How to access model in a module


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 ( 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 -

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

Any help would be really appreciated.


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.



            '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:




        $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.


OK, sorry I misunderstood your question. You can also add the module’s models to your config’s “import” array.