Hey

I dont know whether this is the best way to solve this problem about loading
MODELS for a specific MODULE. I had this same question and burned a hell of
a time trying to understand what to do. This is the solution i found:

i got three modules like this:

default
-> controllers
-> models
-> views

pro
-> controllers
-> models
-> views

public
-> controllers
-> models
-> views

Now i needed to load the index model class for the PRO module. And this
should happen within the PRO's index action. This is what I came up with:

file: /pro/controllers/IndexController.php

public function init() {
    Zend_Loader::loadClass('Pro_Models_Index');
}

public function indexAction() {
    $objIndex = new Pro_Models_Index();
    $objIndex->theGreatFunction();
}

file: /pro/models/Index.php

class Pro_Models_Index {
    theGreatFunction() {
        // some code here
    }
}

like wise we can use "Default_Models_Index", "Public_Models_Index" or even
"Pro_Models_List" which searches for a "/pro/models/List.php" file. You can
see I just simply send in the path to models. I found this is a pretty neat
way.

Let me know if this worked for you :)

-- M


Maurice Fonk wrote:
> 
> On question 2: You can create a "global" model directory, or maybe put 
> global models into your "default" module's model directory. The only 
> important thing is that it is in your include path. But, even better, I 
> can point you toward a solution that popped up on this list yesterday:
> 
> http://www.nabble.com/Model-Loading-helper-tf3942096s16154.html#a11181598
> 
> hope that helps,
> MF
> 
> Julian Davchev wrote:
>> damn, I dig in deeper in mail archive.
>> Turns out controller class should be named <module_name>_ControllerName
>> I my case Admin_IndexController. Filename remains IndexController.php
>> So question 1 is cleared.
>>
>> Someone could elaborate on question 2 would be great.
>>
>>
>>
>> Regards,
>>
>>
>>
>> Julian Davchev wrote:
>>   
>>> Hi,
>>>
>>>
>>>
>>> I must say I read the whole manual regarding controllers and most stuff
>>> seems pretty straight forward but for some reason I couldn't do the
>>> following.
>>>
>>> From what I see for my needs will be good to have one module for client
>>> view and one admin  module for admin stuff.
>>>
>>> 1)
>>> I tried using this
>>> http://framework.zend.com/manual/en/zend.controller.modular.html
>>> point 7.11.2
>>>
>>> My structure is as follows - having default + admin module.
>>>
>>> application
>>>       default/controllers/IndexController.php
>>>
>>>       admin/controllers/IndexController.php
>>>
>>>
>>> $dir = array(
>>>       'default' => PROJECT_ROOT . '/application/default/controllers',
>>>       'admin'    => PROJECT_ROOT . '/application/admin/controllers'
>>> );
>>>
>>>
>>> $controller = Zend_Controller_Front::getInstance();
>>> $controller->setControllerDirectory($dir);
>>> $controller->setParam('noViewRenderer', true);
>>> $controller->throwExceptions(true);
>>>
>>>
>>> When I try to launch
>>> domain.com/        default module cicks in as is supposed to
>>>
>>> but when I do
>>> domain.com/admin/index/index/
>>>
>>> for example....it says
>>> File "IndexController.php" was not foundexception 'Zend_Exception'
>>>
>>> and after some debugging I see it is looking for class
>>> Admin_IndexController.php
>>>
>>> witch probably translates to admin/IndexController.php and not
>>> admin/controllers/IndexController.php
>>>
>>> Can someone lead me to what I do wrong?
>>>
>>>
>>> 2. One more question:
>>> This models directory....I kind of miss how it comes together with the
>>> whole part. I mean...is there any way to include
>>> stuff automatically from there.... can I share automatically same models
>>> dir for two modules?
>>> Because right now to include something from there I am pretty much
>>> include manually stuff - which doesnt make much sense if it is suggested
>>> dir stays there.
>>>
>>> Thanks for time spent
>>>
>>> Regards
>>>
>>>
>>>   
>>>     
>>
>>
>>
>>   
> 
> 
> -- 
> Maurice Fonk
> 
> [EMAIL PROTECTED]
> http://naneau.nl/
> 
> Scio me nihil scire
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/having-trouble-with-setting-simple-module-structure.-tf3945560s16154.html#a12393568
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to