|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 - 3 | Next > |
|
|
Shared Models in Different ModulesHi List,
I asked a question about Shared View Scripts some days ago and you recommend me to use Zend_Layout. I have a similiar question about Models in a modular-dir-structure. A website always has a homepage, which usually consists of links to other sections (modules). Thus, the default modules should have access to other modules' models. Isn't this an architectural disease? It sounds that these shared models are destroying the Modular-based building. How can I have access to different models in different modules. It is critical for default module (homepage) to have access to whole website's content. What is the best place to put centralized code (including bootstraper, shared views, shared models?) |
|||||||||
|
|
RE: Shared Models in Different ModulesI agree with you. I have having the same problem with my site that you are having.
Jon Whitcraft Indianapolis Motor Speedway ________________________________ From: AmirBehzad Eslami [mailto:behzad.eslami@...] Sent: Sun 12/2/2007 12:18 PM To: fw-mvc@... Subject: [fw-mvc] Shared Models in Different Modules Hi List, I asked a question about Shared View Scripts some days ago and you recommend me to use Zend_Layout. I have a similiar question about Models in a modular-dir-structure. A website always has a homepage, which usually consists of links to other sections (modules). Thus, the default modules should have access to other modules' models. Isn't this an architectural disease? It sounds that these shared models are destroying the Modular-based building. How can I have access to different models in different modules. It is critical for default module (homepage) to have access to whole website's content. What is the best place to put centralized code (including bootstraper, shared views, shared models?) ******************** ******************** This E-mail (and attachments) may contain confidential/privileged information intended only for the named addressee(s). If you are not an intended recipient, do not read, copy, disseminate or take any action based on the content of this E-mail. Please notify the sender by reply E-mail and erase this E-mail from your system. Your assistance is appreciated. E-mail transmission may not be secure or error-free. The company is not responsible for any loss/damage arising from any virus transmitted. ******************** ******************** |
|||||||||
|
|
Re: Shared Models in Different Modulesour situation might be a bit different, but since there's no real stipulation in Zend_Controller as to where the model classes reside (they're not involved in routing and/or view rendering), I tend to put model classes outside of the ZF app itself - in another dir on my include path.
e.g., assuming a project layout like: application/ default/ module1/ library/ document_root/ I would put models under library/ along with Zend/ itself... library/Zend # contains ZF library/MyProject # namespacing dir for my classes library/MyProject/Db # dir for Zend_Db model classes library/MyProject/Db/users.php: class MyProject_Db_users extends Zend_Db_Table {} then I can put library/ in my include path, use Zend_Loader autoloading, and use the MyProject_Db_users class from any of the modules under application. -L On Dec 2, 2007 11:29 AM, Whitcraft, Jon <jwhitcraft@...> wrote: I agree with you. I have having the same problem with my site that you are having. |
|||||||||
|
|
RE: Shared Models in Different ModulesHere's how I have my project setup.
application/ controllers/ <-- default layouts/ <-- holds all my main layout pages library/ <-- custom library conponents models/ <-- where i store all my models currently modules/ <-- my different modules news/ photos/ views/ <-- default views Under each module I have a controllers, views and models directory. What I would like to happen is to be able to put each modules models inside of the news/models/ directory instead of the root modelds directroy that way everything is self contained in the directory. does all that make sense? Jon Whitcraft Indianapolis Motor Speedway jwhitcraft@... ________________________________ From: Luke Crouch [mailto:luke.crouch@...] Sent: Sun 12/2/2007 2:25 PM To: Whitcraft, Jon Cc: AmirBehzad Eslami; fw-mvc@... Subject: Re: [fw-mvc] Shared Models in Different Modules our situation might be a bit different, but since there's no real stipulation in Zend_Controller as to where the model classes reside (they're not involved in routing and/or view rendering), I tend to put model classes outside of the ZF app itself - in another dir on my include path. e.g., assuming a project layout like: application/ default/ module1/ library/ document_root/ I would put models under library/ along with Zend/ itself... library/Zend # contains ZF library/MyProject # namespacing dir for my classes library/MyProject/Db # dir for Zend_Db model classes library/MyProject/Db/users.php: class MyProject_Db_users extends Zend_Db_Table {} then I can put library/ in my include path, use Zend_Loader autoloading, and use the MyProject_Db_users class from any of the modules under application. -L On Dec 2, 2007 11:29 AM, Whitcraft, Jon <jwhitcraft@...> wrote: I agree with you. I have having the same problem with my site that you are having. Jon Whitcraft Indianapolis Motor Speedway ________________________________ From: AmirBehzad Eslami [mailto: behzad.eslami@... <mailto:behzad.eslami@...> ] Sent: Sun 12/2/2007 12:18 PM To: fw-mvc@... Subject: [fw-mvc] Shared Models in Different Modules Hi List, I asked a question about Shared View Scripts some days ago and you recommend me to use Zend_Layout. I have a similiar question about Models in a modular-dir-structure. A website always has a homepage, which usually consists of links to other sections (modules). Thus, the default modules should have access to other modules' models. Isn't this an architectural disease? It sounds that these shared models are destroying the Modular-based building. How can I have access to different models in different modules. It is critical for default module (homepage) to have access to whole website's content. What is the best place to put centralized code (including bootstraper, shared views, shared models?) ******************** ******************** This E-mail (and attachments) may contain confidential/privileged information intended only for the named addressee(s). If you are not an intended recipient, do not read, copy, disseminate or take any action based on the content of this E-mail. Please notify the sender by reply E-mail and erase this E-mail from your system. Your assistance is appreciated. E-mail transmission may not be secure or error-free. The company is not responsible for any loss/damage arising from any virus transmitted. ******************** ******************** |
|||||||||
|
|
Re: Shared Models in Different Moduleshmm...
you don't mean you want to have *copies* of all the models in each module, right? you're trying to move ALL models into the news/models directory so the news module is self-contained? to me it only makes sense to put the news-only models into the news module directory. if you have application-wide models, they should stay in the universal models directory, IMO. -L On Dec 2, 2007 2:17 PM, Whitcraft, Jon <jwhitcraft@...> wrote: Here's how I have my project setup. |
|||||||||
|
|
Re: Shared Models in Different ModulesIn my opinion, each Module should be self-contained. Let's look at
each module as a package. This allows you create new projects via the well-known copy-paste technique! However, the default module needs access to other models to collect the magnet content. We can put "./application/modules" into the include_path. But we cannot use the Zend_Loader to load models using the following syntax: Zend_Loader('{modulename}_models_{ModelName}'). Because Zend_Loader checks for the class name to match via the given parameter. Perhaps we need a Zend_Loader::loadModel to load the required models in each Action Controller, and of course, there could be a method, say, setModuleModelDirectoryName(). -B |
|||||||||
|
|
Re: Shared Models in Different ModulesWe can put "./application/modules" into the include_path. right, so if I: * put "./application/modules" in my include_path * make ./application/modules/users/models/user.php: class users_models_user extends Zend_Db_Table {} Zend_Loader will know how to load it, right? so isn't the answer as simple as naming your classes to match their directories? -L |
|||||||||
|
|
RE: Shared Models in Different ModulesCorrect.
I said that wrong. the news modules only has two modules in it. One model for the story and one model that contains the actually data of all the stories for the index listing page. Now with that said in my global module folder I have my user model which handles the user info which can be accessed from any controller. Jon Whitcraft Indianapolis Motor Speedway jwhitcraft@... ________________________________ From: Luke Crouch [mailto:luke.crouch@...] Sent: Sun 12/2/2007 4:14 PM To: Whitcraft, Jon Cc: AmirBehzad Eslami; fw-mvc@... Subject: Re: [fw-mvc] Shared Models in Different Modules hmm... you don't mean you want to have *copies* of all the models in each module, right? you're trying to move ALL models into the news/models directory so the news module is self-contained? to me it only makes sense to put the news-only models into the news module directory. if you have application-wide models, they should stay in the universal models directory, IMO. -L On Dec 2, 2007 2:17 PM, Whitcraft, Jon <jwhitcraft@...> wrote: Here's how I have my project setup. application/ controllers/ <-- default layouts/ <-- holds all my main layout pages library/ <-- custom library conponents models/ <-- where i store all my models currently modules/ <-- my different modules news/ photos/ views/ <-- default views Under each module I have a controllers, views and models directory. What I would like to happen is to be able to put each modules models inside of the news/models/ directory instead of the root modelds directroy that way everything is self contained in the directory. does all that make sense? Jon Whitcraft Indianapolis Motor Speedway jwhitcraft@... ________________________________ From: Luke Crouch [mailto:luke.crouch@...] Sent: Sun 12/2/2007 2:25 PM To: Whitcraft, Jon Cc: AmirBehzad Eslami; fw-mvc@... Subject: Re: [fw-mvc] Shared Models in Different Modules our situation might be a bit different, but since there's no real stipulation in Zend_Controller as to where the model classes reside (they're not involved in routing and/or view rendering), I tend to put model classes outside of the ZF app itself - in another dir on my include path. e.g., assuming a project layout like: application/ default/ module1/ library/ document_root/ I would put models under library/ along with Zend/ itself... library/Zend # contains ZF library/MyProject # namespacing dir for my classes library/MyProject/Db # dir for Zend_Db model classes library/MyProject/Db/users.php: class MyProject_Db_users extends Zend_Db_Table {} then I can put library/ in my include path, use Zend_Loader autoloading, and use the MyProject_Db_users class from any of the modules under application. -L On Dec 2, 2007 11:29 AM, Whitcraft, Jon <jwhitcraft@...> wrote: I agree with you. I have having the same problem with my site that you are having. Jon Whitcraft Indianapolis Motor Speedway ________________________________ From: AmirBehzad Eslami [mailto: behzad.eslami@... <mailto:behzad.eslami@...> ] Sent: Sun 12/2/2007 12:18 PM To: fw-mvc@... Subject: [fw-mvc] Shared Models in Different Modules Hi List, I asked a question about Shared View Scripts some days ago and you recommend me to use Zend_Layout. I have a similiar question about Models in a modular-dir-structure. A website always has a homepage, which usually consists of links to other sections (modules). Thus, the default modules should have access to other modules' models. Isn't this an architectural disease? It sounds that these shared models are destroying the Modular-based building. How can I have access to different models in different modules. It is critical for default module (homepage) to have access to whole website's content. What is the best place to put centralized code (including bootstraper, shared views, shared models?) ******************** ******************** This E-mail (and attachments) may contain confidential/privileged information intended only for the named addressee(s). If you are not an intended recipient, do not read, copy, disseminate or take any action based on the content of this E-mail. Please notify the sender by reply E-mail and erase this E-mail from your system. Your assistance is appreciated. E-mail transmission may not be secure or error-free. The company is not responsible for any loss/damage arising from any virus transmitted. ******************** ******************** |
|||||||||
|
|
RE: Shared Models in Different Modules==== QUOTE ====
Perhaps we need a Zend_Loader::loadModel to load the required models in each Action Controller, and of course, there could be a method, say, setModuleModelDirectoryName(). The problem or issue i see with this is if you have a bunch of modules it would be pain to always keep modifying your bootstrap file to keep track of these. what would be ideal is if when this command is given: ->addModuleDirectory($this->dirApplication . DIRECTORY_SEPARATOR . 'modules') it would register all the model directories or something like that to handle it. Not sure how it would be done but it's an idea. Jon Whitcraft Indianapolis Motor Speedway jwhitcraft@... ________________________________ From: AmirBehzad Eslami [mailto:behzad.eslami@...] Sent: Sun 12/2/2007 4:47 PM To: Luke Crouch Cc: Whitcraft, Jon; fw-mvc@... Subject: Re: [fw-mvc] Shared Models in Different Modules In my opinion, each Module should be self-contained. Let's look at each module as a package. This allows you create new projects via the well-known copy-paste technique! However, the default module needs access to other models to collect the magnet content. We can put "./application/modules" into the include_path. But we cannot use the Zend_Loader to load models using the following syntax: Zend_Loader('{modulename}_models_{ModelName}'). Because Zend_Loader checks for the class name to match via the given parameter. Perhaps we need a Zend_Loader::loadModel to load the required models in each Action Controller, and of course, there could be a method, say, setModuleModelDirectoryName(). -B ******************** ******************** This E-mail (and attachments) may contain confidential/privileged information intended only for the named addressee(s). If you are not an intended recipient, do not read, copy, disseminate or take any action based on the content of this E-mail. Please notify the sender by reply E-mail and erase this E-mail from your system. Your assistance is appreciated. E-mail transmission may not be secure or error-free. The company is not responsible for any loss/damage arising from any virus transmitted. ******************** ******************** |
|||||||||
|
|
Re: Shared Models in Different ModulesCheck out Ralph's proposal at http://framework.zend.com/wiki/display/ZFPROP/Zend_Controller_Action_Helper_ModelLoader
It may be close to what you're after?
-- Simon Mundy | Director | PEPTOLAB """ " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" " PeptoLab will be closed: Saturday 15th December through until Monday 17th December Saturday 22nd December through until Wednesday 2nd January For urgent requests, please call 0438 046 061 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000 Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124 http://www.peptolab.com |
|||||||||
|
|
RE: Shared Models in Different ModulesHi to all!
I made one folder to all my models, and I appended the include_path with the path to this folder. $models_path = APPLICATION_PATH ."My_Application/Model/"; // include $models_path to include_path somewhere Then where ever in actions I might need some model I just make: $model = new Page(); or something like that... So these models are shared by all controllers & actions but not by all my different applications. br, Marko |
|||||||||
|
|
RE: Shared Models in Different ModulesThat is what I currently do but I want to be able to keep all my modules
in one folder which makes for easy check for me to track in SVN. It also allows me to update the module and then copy it to different sites faster as it's just one folder. That I just deal with instead of having to move parts of it to different folders. Jon Whitcraft Indianapolis Motor Speedway jwhitcraft@... Phone: (317) 492-8623 :: Fax: (317) 492-6419 -----Original Message----- From: Marko Korhonen [mailto:marko.korhonen@...] Sent: Monday, December 03, 2007 12:35 AM To: fw-mvc@... Subject: RE: [fw-mvc] Shared Models in Different Modules Hi to all! I made one folder to all my models, and I appended the include_path with the path to this folder. $models_path = APPLICATION_PATH ."My_Application/Model/"; // include $models_path to include_path somewhere Then where ever in actions I might need some model I just make: $model = new Page(); or something like that... So these models are shared by all controllers & actions but not by all my different applications. br, Marko -- View this message in context: http://www.nabble.com/Shared-Models-in-Different-Modules-tf4932443s16154 .html#a14124197 Sent from the Zend MVC mailing list archive at Nabble.com. ******************** ******************** This E-mail (and attachments) may contain confidential/privileged information intended only for the named addressee(s). If you are not an intended recipient, do not read, copy, disseminate or take any action based on the content of this E-mail. Please notify the sender by reply E-mail and erase this E-mail from your system. Your assistance is appreciated. E-mail transmission may not be secure or error-free. The company is not responsible for any loss/damage arising from any virus transmitted. ******************** ******************** |
|||||||||
|
|
Re: Shared Models in Different ModulesI'm treating model classes as framework classes using the conventional naming to avoid namespace collisions, so all the model classes common to all the application are stored in default/models/ and are named Default_Models_* so they can be easily be localized. Of course, inside the model class the "real name" is set with protected $_name.
You can have model classes in another modules and be namespaced accordingly. The autoload function will find this classes the same way it finds the Zend Libs and other classes.
On Dec 3, 2007 6:35 AM, Marko Korhonen <marko.korhonen@...> wrote:
-- Xavier Vidal Piera Enginyer Tècnic Informàtic de Gestió Tècnic Especialista Informàtic d'equips xavividal@... xvidal@... http://web.xaviervidal.net 610.68.41.78 |
|||||||||
|
|
RE: Shared Models in Different ModulesSo if I understand
you correctly, I should be able to do this $story = new
News_Models_Story(); Where this is my
directory structure: ./modules/ ./news/
./models/
Story.php Correct?
From: Xavier Vidal
Piera [mailto:xavividal@...] I'm treating model
classes as framework classes using the conventional naming to avoid namespace
collisions, so all the model classes common to all the application are stored
in default/models/ and are named Default_Models_* so they can be easily be
localized. Of course, inside the model class the "real name" is set
with protected $_name. On Dec 3, 2007 6:35 AM, Marko Korhonen <marko.korhonen@...>
wrote:
********************
********************
This E-mail (and attachments) may contain confidential/privileged information intended only for the named addressee(s). If you are not an intended recipient, do not read, copy, disseminate or take any action based on the content of this E-mail. Please notify the sender by reply E-mail and erase this E-mail from your system. Your assistance is appreciated. E-mail transmission may not be secure or error-free. The company is not responsible for any loss/damage arising from any virus transmitted.
********************
********************
|
|||||||||
|
|
Re: Shared Models in Different Modulesyeah, that's my understanding. and I think that's also the most-sensible way to lay them out, yeah?
-L On Dec 3, 2007 7:09 AM, Whitcraft, Jon <jwhitcraft@...> wrote:
|
|||||||||
|
|
RE: Shared Models in Different ModulesYa it works for
me one I adjusted the case on my folder names and include my ./modules/ folder
in my include path.
From: Luke Crouch
[mailto:luke.crouch@...] yeah, that's my
understanding. and I think that's also the most-sensible way to lay them out,
yeah? On Dec 3, 2007 7:09 AM, So if I understand you correctly, I
should be able to do this $story = new News_Models_Story(); Where this is my directory structure: ./modules/
./news/
./models/
Story.php Correct?
From: Xavier Vidal Piera [mailto:xavividal@...] I'm treating model classes as framework classes using
the conventional naming to avoid namespace collisions, so all the model classes
common to all the application are stored in default/models/ and are named
Default_Models_* so they can be easily be localized. Of course, inside the
model class the "real name" is set with protected $_name. On Dec 3,
2007 6:35 AM, Marko Korhonen <marko.korhonen@...> wrote:
******************** ******************** This E-mail (and attachments) may contain
confidential/privileged information intended only for the named addressee(s).
If you are not an intended recipient, do not read, copy, disseminate or take
any action based on the content of this E-mail. Please notify the sender by
reply E-mail and erase this E-mail from your system. Your assistance is
appreciated. E-mail transmission may not be secure or error-free. The company
is not responsible for any loss/damage arising from any virus transmitted. ******************** ******************** |
|||||||||
|
|
Re: Shared Models in Different ModulesYes
But i remember to do that in lowercase (module names are in lowercase), so i have all the folder structure in lower case. At this moment, any way to organize better the model classes will be apreciated. On Dec 3, 2007 2:09 PM, Whitcraft, Jon <jwhitcraft@...> wrote:
-- Xavier Vidal Piera Enginyer Tècnic Informàtic de Gestió Tècnic Especialista Informàtic d'equips xavividal@... xvidal@... http://web.xaviervidal.net 610.68.41.78 |
|||||||||
|
|
RE: Shared Models in Different ModulesXavier, I ran into that
problem too. I just refactored the class name to be new_Models_Story which
makes no sense but it works for right now and going back later to refactor once
it gets all figured out wont be too hard as the Zend Neon Beta does a good job
of finding all the occurrences of that class. Cheers
From: Xavier Vidal
Piera [mailto:xavividal@...] Yes On Dec 3, 2007 2:09 PM, So if I understand you correctly, I
should be able to do this $story = new News_Models_Story(); Where this is my directory structure: ./modules/
./news/
./models/
Story.php Correct?
From: Xavier Vidal Piera [mailto:xavividal@...] I'm treating model classes as framework classes using
the conventional naming to avoid namespace collisions, so all the model classes
common to all the application are stored in default/models/ and are named
Default_Models_* so they can be easily be localized. Of course, inside the
model class the "real name" is set with protected $_name. On Dec 3,
2007 6:35 AM, Marko Korhonen <marko.korhonen@...> wrote:
******************** ******************** This E-mail (and attachments) may contain
confidential/privileged information intended only for the named addressee(s).
If you are not an intended recipient, do not read, copy, disseminate or take
any action based on the content of this E-mail. Please notify the sender by
reply E-mail and erase this E-mail from your system. Your assistance is
appreciated. E-mail transmission may not be secure or error-free. The company
is not responsible for any loss/damage arising from any virus transmitted. ******************** ********************
|
|||||||||
|
|
Re: Shared Models in Different ModulesStoring all models in a global directory is not a good practice, as described earlier in previous
posts. We should be able to install new modules into an existing application only via copy-and-paste. I'm just thinking of a new approach: We name the Controller classes in a modular structure using the following scheme: class {ModuleName}_{ControllerName}Controller { //... } I have confused several times when naming Controller and Model classes, since they don't follow a consistent scheme. But can we apply the previous naming scheme to the models to establish a consistent naming scheme among different parts of the app? class {ModuleName}_{ModelName}Model { $protected $_name = '{modelname} //... } Since the './application/modules' is already in include_path, we can use Zend_Loader::loadModel('{ModuleName}_{ModelName}Model') which loads './application/modules/{modulename}/models/{ModelName}Model.php'. With this approach, we need a loadModel() method to load models, and a setModuleModelDirectoryName('models') method to tell the Zend_Loader where are each module's models located. What do you think? |
|||||||||
|
|
Re: Shared Models in Different ModulesIn my opinion, ZF's current naming scheme is not consistent among different MVC components.
For Controllers: {MyModule}_{MyController}Controller @ modules/mymodule/controllers/mycontrollercontroller.php For Models: {MyModel} @ modules/mymodule/models/mymodel.php There could be a better Zend_Loader::loadClass() and a better naming scheme for controllers and models in this MVC. We already know that X_Y_Z loads X/Y/Z.php , ok? So, why should I store a contoller in "module/controller/IndexController.php" and name it "Module_IndexController" ?!! Isn't it better to name the class as Module_Controller_Index which is located at module/controllers/index.php ? And it makes sense to apply the same principle to models. Module_Model_MyModel. On Dec 3, 2007 7:21 PM, Whitcraft, Jon <jwhitcraft@...> wrote:
|
|||||||||
| < Prev | 1 - 2 - 3 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |