Thanks Matt for this very useful explanation.
Yes i understand the problem with setting '/' as the seperator in the url as it will not know if it's directory.
I did add modules and i did use the structure suggested, And accessing module/controller/action did work the thing i had was that i had another directory inside the controllers directory so i had to do module/controller_subdirectorycontroller/action and that's not what i was looking for but i was looking to get this module/controller/subdirectorycontroller/action but i see the point and problem in doing that. That's why i thought if using a router to know that module/controller/sub/action exists in the router segements it will direct it to the place it should. But you said that it was too late to use the router as it should be done in the bootstartup file.
I also had a problem with the view render since i used sub directory he searched the index.phtml view inside views/scripts/index/index/index.phtml when ever i accessed module/index_index/ and yea that's what it should do but i was planning on having the entire views scripts under the views/scripts directory.
Anyway regarding to this moduler way of building the application i assume with 1.8 this will not be an issue since it will use a bootstartup file for each module, and then i could add custom routers for each module/controller to use prior initialization.
Maybe what i am trying to get already available and i just can't figure it out...yet. But i am still learning the ZF and still trying to find the best way of creating a moduler application. ZF is progressing very well and as a person who used several Frameworks i can say this one is probably the best one of them all. But it misses a couple of things, A) there is a very small amount of examples on building a moduler application (and examples in general) B) there is no place for developers to help each other and show code examples, demo applications, examples , tips and so forth. I think that having a Peer2Peer tech support forums will probably be one of the best ways of making ZF get even better.
Hopefully by the time that 1.8 comes out there will be more examples and people willing to help.
Thanks again, Vince.
--
Vincent Gabriel.
Lead Developer, Senior Support.
Zend Certified Engineer.
Yes i understand the problem with setting '/' as the seperator in the url as it will not know if it's directory.
I did add modules and i did use the structure suggested, And accessing module/controller/action did work the thing i had was that i had another directory inside the controllers directory so i had to do module/controller_subdirectorycontroller/action and that's not what i was looking for but i was looking to get this module/controller/subdirectorycontroller/action but i see the point and problem in doing that. That's why i thought if using a router to know that module/controller/sub/action exists in the router segements it will direct it to the place it should. But you said that it was too late to use the router as it should be done in the bootstartup file.
I also had a problem with the view render since i used sub directory he searched the index.phtml view inside views/scripts/index/index/index.phtml when ever i accessed module/index_index/ and yea that's what it should do but i was planning on having the entire views scripts under the views/scripts directory.
Anyway regarding to this moduler way of building the application i assume with 1.8 this will not be an issue since it will use a bootstartup file for each module, and then i could add custom routers for each module/controller to use prior initialization.
Maybe what i am trying to get already available and i just can't figure it out...yet. But i am still learning the ZF and still trying to find the best way of creating a moduler application. ZF is progressing very well and as a person who used several Frameworks i can say this one is probably the best one of them all. But it misses a couple of things, A) there is a very small amount of examples on building a moduler application (and examples in general) B) there is no place for developers to help each other and show code examples, demo applications, examples , tips and so forth. I think that having a Peer2Peer tech support forums will probably be one of the best ways of making ZF get even better.
Hopefully by the time that 1.8 comes out there will be more examples and people willing to help.
Thanks again, Vince.
On Tue, Feb 24, 2009 at 3:01 PM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- vadim gavrilov <vadimg88@gmail.com> wrote
(on Tuesday, 24 February 2009, 08:17 AM +0200):
> Thanks,Actually, no. The reason _ was chosen over / is because / is used to
>
> I assume the '_' is what sets it to know it's a sub directory. Is there a way
> to replace the '_' with a '/' so the link will be admin/tools/other/
> [actionname] i know i can do this with the dispatcher but not sure how.
separate discrete segments of the URL; it's difficult to reliably
determine that a segment of the url indicates a directory without doing
stat calls on each pass.
As an example, let's look at this structure:
application/
controllers/
Admin/
FooController.php
Public/
FooController.php
News/
FooController.php
Now, let's consider you want to match /admin/foo/bar. How would the
router try to match this?
The default route is, basically, ':controller/:action/*' -- so, knowing
this, it would try to execute AdminController::fooAction() with an empty
"bar" parameter.
Now, the default route also allows for an optional "module" segment. In
that case, if any modules have been added to the front controller, it
will try to match the first segment against the list of modules; if any
match, it will then grab that controller in that module.
You could potentially leverage this information, and do the following:
$front->addControllerDirectory(APPLICATION_PATH . '/controllers/Admin', 'admin')
->addControllerDirectory(APPLICATION_PATH . '/controllers/Public', 'public')
->addControllerDirectory(APPLICATION_PATH . '/controllers/News', 'news');
The problem with this approach is that modules are supposed to be
self-contained "applications" -- a module's directory structure should
mimic the recommended directory structure:
application/
modules/
admin/
controllers/
FooController.php
views/
scripts/
public/
controllers/
FooController.php
views/
scripts/
news/
controllers/
FooController.php
views/
scripts/
If you don't follow that structure, you then need to do a bunch of other
customizations; the ViewRenderer's mappings will need to be altered so
that they match your own directory structure, for instance.
Another solution is to write your own route that makes the assumption
that the first segment of the path always indicates a directory under
controllers/. This would not be hard to do -- take a look at the module
route (Zend_Controller_Router_Route_Module) to get some ideas.
Adding routes to Zend_Controller_Action (which is what I assume you mean
> The thing i want to do with the router is have a file called router.php inside
> every controllers sub directory that will add routes to certain places. I
> didn't quite grasp the way i need to use the router class and from reading the
> documentation (what i read so far) it doesn't clearly say where you need to
> define the new instance of the router class. If it's in the bootstartup.php
> file then how can i access it later from each and every controller? I can't
> create a new instance in every controller beacuse that will be a bad design
> practice. How about creating a master controller that will extend the zend
> abstract and that one will create the instance of the router? Then i could just
> extend the master controller in every controller i have in my controllers
> directory? Is this something usable?
by "the zend abstract") is too late -- routing occurs in the front
controller, before any action controllers are instantiated.
What you need to do is inject routes into the router prior to to
routing. This can either be done during bootstrapping, or in a front
controller plugin with a defined routeStartup() hook.
Honestly, though, it sounds to me like what you're looking for is this:
http://framework.zend.com/manual/en/zend.controller.modular.html
Based on what you described -- custom routes per subdirectory of
controllers -- a modular directory structure is the recommended way to
achieve it.
This is going to get a ton more powerful and meaningful in 1.8, due to
the introduction of Zend_Application, and based on what you're trying to
do, I think you'll be able to leverage the idea of a "bootstrap per
module." In this paradigm, you can have a bootstrap class per
module, and within it add initialization routines that create new
routes to add to the router.
--
> On Tue, Feb 24, 2009 at 1:36 AM, Tomoaki Kosugi <kipspro@gmail.com> wrote:
>
> Hi
>
> This is my guess,you need to set up two as below.
>
> 1. Controller Setup
> 2. Router Setup
>
> 1. Using action controllers in sub directories
> /admin/tools/otherController.php
> is mapped to below↓
> className:
> Admin_Tools_OtherController
> you can access this controller in this uri.
> /admin/tools_other/[actionname]/*
>
> 2.Router Setup
> you can add routes from the uri "/admin/tools/other"
> to the controller named "tools_other" .
>
> Excuse me ,I am not good at English.
>
> regards
>
> --
> noopable:
> Tomoaki Kosugi
>
>
> 2009/2/24 vince. <vadimg88@gmail.com>:
> >
> > How can i set a rewrite rule class/instance across the entire application
> > that i could use sub directories inside the main controllers directory
> for
> > each module? Meaning so i could have this structure:
> >
> > /application
> > /modules
> > /admin
> > /controllers
> > /index
> > /indexcontroller.php
> > /othercontroller.php
> > /tools
> > /indexcontroller.php
> > /othercontroller.php
> > /settings
> > /indexcontroller.php
> > /othercontroller.php
> > /layouts
> > /site
> > /controllers
> > /index
> > /indexcontroller.php
> > /othercontroller.php
> > /tools
> > /indexcontroller.php
> > /othercontroller.php
> > /settings
> > /indexcontroller.php
> > /othercontroller.php
> > /layouts
> > /library
> >
> >
> > and i could enter the file admin/controller/tools/other as follows:
> > admin/tools/other trough the url. and basically use sub directories
> inside
> > the controllers directory. what do i need to setup?
> >
> > Thanks.
> >
>
>
>
>
>
> --
> Vincent Gabriel.
> Lead Developer, Senior Support.
> Zend Certified Engineer.
>
>
>
>
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
--
Vincent Gabriel.
Lead Developer, Senior Support.
Zend Certified Engineer.
没有评论:
发表评论