Yii Framework Forum: importing model from other module - Yii Framework Forum

Jump to content

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

importing model from other module Is there any limit on importing models from other modules? Rate Topic: -----

#1 User is offline   MJD 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 10-April 12
  • Location:PK

Posted 21 May 2012 - 04:59 AM

I am working on a project in YII. I have planned to develop the site modules based. Everything was working fine but today I created a module and imported it the main module. now, when i go to the site at my localhost the browser displays the The connection was reset page. here is the code

Users Model in /modules/users/models/Users.php

public function relations()
    {
        Yii::import('application.modules.companies.models.Company');
        Yii::import('application.modules.clients.models.Clients');
        Yii::import('application.modules.events.models.Events');
        Yii::import('application.modules.notifications.models.UserNotifications');
        Yii::import('application.modules.tasks.models.UserTasks');

        return array(
...
            'contacts' => array(self::HAS_MANY, 'UserLeeds', 'user_id'),
            'userNotifications' => array(self::HAS_MANY, 'UserNotifications', 'user_id'),
            'userTasks' => array(self::HAS_MANY, 'UserTasks', 'user_id'),
            'userRole' => array(self::BELONGS_TO, 'Roles', 'user_role'),
            'userCompany' => array(self::BELONGS_TO, 'Company', 'user_company_id'),
            'userClient' => array(self::BELONGS_TO, 'Clients', 'user_client_id'),
        );
    }


Notifications Model in /modules/notifications/models/UserNotifications.php

public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'notificationType' => array(self::BELONGS_TO, 'Notifications', 'notification_type'),
            'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
        );
    }


If in the Users Model I comment out the
Yii::import('application.modules.notifications.models.UserNotifications');
line all works fine.

Any idea what I am missing here.

UPDATE

Well, just found that if I comment out any of the imported modules it works fine then..

does this mean YII limits the import of module/models to other module/modle to only 4?

Regards
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,342
  • Joined: 12-October 09
  • Location:Croatia

Posted 22 May 2012 - 05:56 AM

Why are you importing models inside the rules method?
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   MJD 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 10-April 12
  • Location:PK

Posted 22 May 2012 - 06:06 AM

Thanks for the reply mdomba :)

I want to develop site with multiple clients.

I divided all major features in modules like notifications, tasks and etc so that I can enable / disable them depending on the client logged in.

The said module in this question is Users that is a default to all clients. I need to get data from all allowed modules for a client for that I was trying to import the corresponding model from other modules like

for notifications => Notifications.php from notifications module
for tasks => Tasks.php from tasks module
for events => Events.php from events module

and etc

all was working fine but the issue I found is that I am unable to import more than four (4) modules. I have looked if there is some limit on importing of modules but didn't find anything.

Hope its making sense.
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,342
  • Joined: 12-October 09
  • Location:Croatia

Posted 22 May 2012 - 06:34 AM

Sorry that I can't help you more... this would need proper debugging to find what is the real cause...

What is strange to me is the you are importing those models inside the relation() method ? (I did spell it wrongly before - rules)

Try to import them in the init() method for example.
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   MJD 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 10-April 12
  • Location:PK

Posted 22 May 2012 - 07:20 AM

ok will try it like that

thanks :)
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