Yii Framework Forum: How to access model in a module - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to access model in a module Rate Topic: -----

#1 User is offline   Jonathanza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 22-February 10

Posted 17 March 2010 - 03:49 AM

Hi,

I'm fairly new to Yii and would really appreciate any help with this problem. I think I'm missing something very obvious.

I'm using Yii-User (http://code.google.com/p/yii-user/) for authentication. I'd like to automatically create a user
based on my own input form in the main application. From the code in Yii-User I can see I need to access two models:
   $model = new RegistrationForm;            
   $profile=new Profile;

I think I need to do something like this:
   $RegistrationForm = Yii::app()->getModule('user')->RegistrationForm;


I've also had a look at this article too but I can't see how it applies to what I'm trying to do -
http://www.yiiframew...oc/cookbook/27/

How do I reference the models in a module from the main application?

Any help would be really appreciated.

Jonathan
0

#2 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 17 March 2010 - 06:17 AM

Load the module in your application config file.

More info.
0

#3 User is offline   Jonathanza 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 22-February 10

Posted 17 March 2010 - 06:46 AM

View Postjsoo, on 17 March 2010 - 06:17 AM, said:

Load the module in your application config file.

More info.


Hi jsoo,

Thanks for the reply. I double checked my config, it is already included.
    'modules'=>array(
        'user'=>array(
            'hash' => 'md5',                                     # encrypting method (php hash function)
            'sendActivationMail' => false,                       # send activation email
            'loginNotActiv' => true,                             # allow access for non-activated users
            'autoLogin' => true,                                 # automatically login from registration
            'registrationUrl' => array('/user/registration'),    # registration path
            'recoveryUrl' => array('/user/recovery'),            # recovery password path
            'loginUrl' => array('/user/login'),                  # login form path
            'returnUrl' => array('/applicant/index'),            # page after login
            'returnLogoutUrl' => array('/user/login'),           # page after logout
        ),
    ),


I have managed to solve it by doing the following:
    	$modelClass='application.modules.user.models.*';
        $modelClass=Yii::import($modelClass);
        
        $registrationform = new RegistrationForm;
        $profile = new Profile;

There are a few other unrelated issues I need to resolve but I am able to create a user record now at least.

Jonathan
0

#4 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 17 March 2010 - 07:53 AM

OK, sorry I misunderstood your question. You can also add the module's models to your config's "import" array.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users