Seperate Public Directories Using Same Model & Config

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Seperate Public Directories Using Same Model & Config

Steve Uplift
Hi,

I am developing a website, which also has an admin site. Both of these are effectively different sites, or at least in terms of Zend MVC, seperate public directories. I need both sites to use the same model (as the databases are the same, I would be duplicating a lot of the code if I coded them seperately), and the same config file.

What's the easiest way to do this? I know it's easy to create modules to use seperate controllers, views and models but they use a common public directory. I thought of just putting the model and config folders outside of both but this just feels a bit messy.

Any ideas anyone?

Thanks

Steve
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

dmitrybelyakov

Steve Uplift wrote
Hi,

I am developing a website, which also has an admin site. Both of these are effectively different sites, or at least in terms of Zend MVC, seperate public directories. I need both sites to use the same model (as the databases are the same, I would be duplicating a lot of the code if I coded them seperately), and the same config file.

What's the easiest way to do this? I know it's easy to create modules to use seperate controllers, views and models but they use a common public directory. I thought of just putting the model and config folders outside of both but this just feels a bit messy.

Any ideas anyone?

Thanks

Steve
Hi,

I think its absolutely fine in that case to place your models in a separate folder, like your 'library' for example. If you then put it on your include path you can easily autoload these models from anywhere in your application.

And by the way - what do you mean by 'two public directories' since you can have only one public webroot?

Good luck,
Dmitry.
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

David Mintz
In reply to this post by Steve Uplift


On Mon, Oct 26, 2009 at 2:48 PM, Steve Uplift <[hidden email]> wrote:

Hi,

I am developing a website, which also has an admin site. Both of these are
effectively different sites, or at least in terms of Zend MVC, seperate
public directories. I need both sites to use the same model (as the
databases are the same, I would be duplicating a lot of the code if I coded
them seperately), and the same config file.

What's the easiest way to do this? I know it's easy to create modules to use
seperate controllers, views and models but they use a common public
directory. I thought of just putting the model and config folders outside of
both but this just feels a bit messy.

Any ideas anyone?


Not sure I completely understand the problem. What's wrong having a default module, an admin module, and a standard directory structure? And why would you want your application files (as opposed to your public resources) stored in a public (web-accessible) directory?


--
Demand health care for everyone:
http://mobilizeforhealthcare.org/

--
David Mintz
http://davidmintz.org/


Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

Steve Uplift
In reply to this post by dmitrybelyakov

dmitrybelyakov wrote
Hi,

I think its absolutely fine in that case to place your models in a separate folder, like your 'library' for example. If you then put it on your include path you can easily autoload these models from anywhere in your application.

And by the way - what do you mean by 'two public directories' since you can have only one public webroot?

Good luck,
Dmitry.
Thanks for the reply. I probably didn't make myself clear enough in the post. I would actually have two seperate webroots, so effectively two seperate applications which both need to access the same models.

Thanks

Steve
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

Steve Uplift
In reply to this post by David Mintz

David Mintz-2 wrote
Not sure I completely understand the problem. What's wrong having a default
module, an admin module, and a standard directory structure? And why would
you want your application files (as opposed to your public resources) stored
in a public (web-accessible) directory?
Thanks for your reply.

I won't have my application files stored in the public directory (that would be very bad obviously), so sorry if i didnt make myself clear. I could have two modules, but I actually need two independent public directories. If that's what you mean, then I'm not sure how to do that, as the examples I have seen so far depict multiple modules but 1 public directory (unless I'm not looking hard enough!).

Steve
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

dmitrybelyakov
In reply to this post by Steve Uplift

Steve Uplift wrote
Thanks for the reply. I probably didn't make myself clear enough in the post. I would actually have two seperate webroots, so effectively two seperate applications which both need to access the same models.

Thanks

Steve
Ok i see, so in other words your question might sound like - 'How to make several virtual hosts share same codebase'. So the answer is still valid - move your code to library and put in on include path - just like you do with ZF.

Dmitry.
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

Shaun Farrell
Could symbolic link the models directory too I guess. Not sure what
the impact is on or if there are any security risks. worth a try I
guess

On 10/26/09, dmitrybelyakov <[hidden email]> wrote:

>
>
>
> Steve Uplift wrote:
>>
>>
>> Thanks for the reply. I probably didn't make myself clear enough in the
>> post. I would actually have two seperate webroots, so effectively two
>> seperate applications which both need to access the same models.
>>
>> Thanks
>>
>> Steve
>>
>
> Ok i see, so in other words your question might sound like - 'How to make
> several virtual hosts share same codebase'. So the answer is still valid -
> move your code to library and put in on include path - just like you do with
> ZF.
>
> Dmitry.
>
> --
> View this message in context:
> http://www.nabble.com/Seperate-Public-Directories-Using-Same-Model---Config-tp26065263p26067185.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>
>

--
Sent from my mobile device

Shaun J. Farrell
Washington, DC
(202) 713-5241
www.farrelley.com
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

Brenton Alker-3
In reply to this post by Steve Uplift
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve Uplift wrote:

> Hi,
>
> I am developing a website, which also has an admin site. Both of these are
> effectively different sites, or at least in terms of Zend MVC, seperate
> public directories. I need both sites to use the same model (as the
> databases are the same, I would be duplicating a lot of the code if I coded
> them seperately), and the same config file.
>
> What's the easiest way to do this? I know it's easy to create modules to use
> seperate controllers, views and models but they use a common public
> directory. I thought of just putting the model and config folders outside of
> both but this just feels a bit messy.
>
> Any ideas anyone?

Is there any reason you can't make the public folder (if that's the only
thing that needs to be different) a subdirectory of the "/public"
directory eg.

/public
  /admin
  /main

Then just point your webroot at the public/admin and public/main
directory respectively?

I think the only change it would require would be the adjusting of the
calculation of the APPLICATION_PATH in the index.php(s).

- --

Brenton Alker
PHP Developer - Brisbane, Australia

http://blog.tekerson.com/
http://twitter.com/tekerson

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrmKUYACgkQ7bkAtAithuuX1wCfR02Nm6EW4ZZQsf02aIWf7oN8
s/MAmgNvwsMuS5sGcpEzBfwxNPDS6RtN
=Tdqz
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

SiCo
In reply to this post by Steve Uplift

Steve Uplift wrote
Thanks for the reply. I probably didn't make myself clear enough in the post. I would actually have two seperate webroots, so effectively two seperate applications which both need to access the same models.

Thanks

Steve
I do this using sub domains, I have admin. which basically loads the bootstrap configuration but with some additional options set on top of those loaded by the standard app. So both the root and the sub domain have an individual index.php (I found this to be the easiest way to allow precise control). Because the settings are the same and everything points to the same location below the web root it all works.
Reply | Threaded
Open this post in threaded view
|

Re: Seperate Public Directories Using Same Model & Config

weierophinney
Administrator
In reply to this post by Steve Uplift
-- Steve Uplift <[hidden email]> wrote
(on Monday, 26 October 2009, 11:48 AM -0700):

> I am developing a website, which also has an admin site. Both of these are
> effectively different sites, or at least in terms of Zend MVC, seperate
> public directories. I need both sites to use the same model (as the
> databases are the same, I would be duplicating a lot of the code if I coded
> them seperately), and the same config file.
>
> What's the easiest way to do this? I know it's easy to create modules to use
> seperate controllers, views and models but they use a common public
> directory. I thought of just putting the model and config folders outside of
> both but this just feels a bit messy.

With Zend_Application and resource autoloaders, this is trivially easy.

Each module should have a Bootstrap.php file containing a class
<ModuleName>_Bootstrap that extends Zend_Application_Module_Bootstrap.
This will automatically create a Zend_Application_Module_Autoloader
instance bound to that module, which gives you the following mappings:

    admin/
        forms/           Admin_Form_*
        models/          Admin_Model_*
        services/        Admin_Service_*
        views/filters/   Admin_View_Filter_*
        views/helpers/   Admin_View_Helper_*

Since all module bootstraps are executed on each request, this means
autoloading for each module is defined up front -- and that means
accessing your models is as simple as simply instantiating them:

    class Admin_BlogController extends Zend_Controller_Action
    {
        public function createEntryAction()
        {
            $model = new Blog_Model_Entry();
            // ...
        }
    }

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/