Shared Models in Different Modules

47 messages Options
Embed this post
Permalink
1 2 3
Behzad-3

Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
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?)
jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
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:[hidden email]]
Sent: Sun 12/2/2007 12:18 PM
To: [hidden email]
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.
********************
********************
lcrouch

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
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 <[hidden email]> 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:[hidden email]]
Sent: Sun 12/2/2007 12:18 PM
To: [hidden email]
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.
********************
********************

jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
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
[hidden email]

________________________________

From: Luke Crouch [mailto:[hidden email]]
Sent: Sun 12/2/2007 2:25 PM
To: Whitcraft, Jon
Cc: AmirBehzad Eslami; [hidden email]
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 <[hidden email]> 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: [hidden email] <mailto:[hidden email]> ]
        Sent: Sun 12/2/2007 12:18 PM
        To: [hidden email]
        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.
        ********************
        ********************
       


lcrouch

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
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 <[hidden email]> 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
[hidden email]

________________________________

From: Luke Crouch [mailto:[hidden email]]
Sent: Sun 12/2/2007 2:25 PM
To: Whitcraft, Jon
Cc: AmirBehzad Eslami; [hidden email]
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 <[hidden email]> 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: [hidden email] <mailto:[hidden email]> ]
       Sent: Sun 12/2/2007 12:18 PM
       To: [hidden email]
       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.
       ********************
       ********************




Behzad-3

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
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

lcrouch

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink

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.

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
jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by lcrouch
Correct.
 
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
[hidden email]

________________________________

From: Luke Crouch [mailto:[hidden email]]
Sent: Sun 12/2/2007 4:14 PM
To: Whitcraft, Jon
Cc: AmirBehzad Eslami; [hidden email]
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 <[hidden email]> 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
       
        [hidden email]
       
        ________________________________
       
        From: Luke Crouch [mailto:[hidden email]]
        Sent: Sun 12/2/2007 2:25 PM
        To: Whitcraft, Jon
        Cc: AmirBehzad Eslami; [hidden email]
        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 <[hidden email]> 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: [hidden email] <mailto:[hidden email]> ]
       
               Sent: Sun 12/2/2007 12:18 PM
               To: [hidden email]
               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.
               ********************
               ********************
       
       
       
       


jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by Behzad-3
==== 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
[hidden email]

________________________________

From: AmirBehzad Eslami [mailto:[hidden email]]
Sent: Sun 12/2/2007 4:47 PM
To: Luke Crouch
Cc: Whitcraft, Jon; [hidden email]
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.
********************
********************
Simon Mundy

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Check 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?

==== 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
[hidden email]

________________________________

From: AmirBehzad Eslami [mailto:[hidden email]]
Sent: Sun 12/2/2007 4:47 PM
To: Luke Crouch
Cc: Whitcraft, Jon; [hidden email]
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.
********************
********************

--

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

marko.korhonen

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by jwhitcraft
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
jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
That 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
[hidden email]
Phone: (317) 492-8623 :: Fax: (317) 492-6419

-----Original Message-----
From: Marko Korhonen [mailto:[hidden email]]
Sent: Monday, December 03, 2007 12:35 AM
To: [hidden email]
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.
********************
********************
Xavier Vidal

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by marko.korhonen
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.

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 <[hidden email]> wrote:

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.




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78
jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

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?

 

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto:[hidden email]]
Sent: Monday, December 03, 2007 7:54 AM
To: Marko Korhonen
Cc: [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

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.

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 <[hidden email]> wrote:


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.




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78

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

lcrouch

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
yeah, 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 <[hidden email]> wrote:

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?

 

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto:[hidden email]]
Sent: Monday, December 03, 2007 7:54 AM
To: Marko Korhonen
Cc: [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

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.

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 <[hidden email]> wrote:


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.




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78

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


jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Ya it works for me one I adjusted the case on my folder names and include my ./modules/ folder in my include path.

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Luke Crouch [mailto:[hidden email]]
Sent: Monday, December 03, 2007 8:49 AM
To: Whitcraft, Jon
Cc: Xavier Vidal Piera; Marko Korhonen; [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

yeah, 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 <[hidden email]> wrote:

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?

 

 

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto:[hidden email]]
Sent: Monday, December 03, 2007 7:54 AM
To: Marko Korhonen
Cc: [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

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.

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 <[hidden email]> wrote:


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.




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78

********************

********************

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.

********************

********************

 


Xavier Vidal

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by jwhitcraft
Yes

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 <[hidden email]> wrote:

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?

 

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto:[hidden email]]
Sent: Monday, December 03, 2007 7:54 AM
To: Marko Korhonen
Cc: [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

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.

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 <[hidden email]> wrote:


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.




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78

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



--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78
jwhitcraft

RE: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Xavier,

 

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

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto:[hidden email]]
Sent: Monday, December 03, 2007 10:17 AM
To: Whitcraft, Jon
Cc: Marko Korhonen; [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

Yes

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 <[hidden email]> wrote:

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?

 

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto:[hidden email]]
Sent: Monday, December 03, 2007 7:54 AM
To: Marko Korhonen
Cc: [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

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.

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 <[hidden email]> wrote:


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.




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78

********************

********************

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.

********************

********************




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78


Behzad-3

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by Xavier Vidal
Storing 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?

Behzad-3

Re: Shared Models in Different Modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by jwhitcraft
In 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 <[hidden email]> wrote:

Xavier,

 

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

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto:[hidden email]]
Sent: Monday, December 03, 2007 10:17 AM
To: Whitcraft, Jon
Cc: Marko Korhonen; [hidden email]


Subject: Re: [fw-mvc] Shared Models in Different Modules

 

Yes

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 <[hidden email]> wrote:

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?

 

 

Jon Whitcraft
Indianapolis Motor Speedway
[hidden email]

Phone: (317) 492-8623 :: Fax: (317) 492-6419



From: Xavier Vidal Piera [mailto: [hidden email]]
Sent: Monday, December 03, 2007 7:54 AM
To: Marko Korhonen
Cc: [hidden email]
Subject: Re: [fw-mvc] Shared Models in Different Modules

 

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.

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 <[hidden email]> wrote:


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.




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78

********************

********************

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.

********************

********************




--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[hidden email]
[hidden email]
http://web.xaviervidal.net
610.68.41.78



1 2 3