Routes - module-controller

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

Routes - module-controller

Simon Walter
Why are module and controller combined with a minus sign?

(Sorry if this was discussed before.)

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

Adam Lundrigan
Simon,

Could you provide an example?  I haven't come across a scenario where the
module and controller route parts are concatenated with a hyphen.

Unless you are asking why the module and controller URI segments can
contain hypens?  If that is your question: camel-cased controller class
names and action names are converted to hyphen-separated terms when used in
URIs :

Controller class name:  Module_MyFooController
Controller action name:  doSomethingAction
URL to invoke action:   /module/my-foo/do-something

Does that answer your question?

Adam Lundrigan, B.Sc, ZCE
[hidden email]


On Mon, Nov 14, 2011 at 10:49 AM, Simon Walter <[hidden email]> wrote:

> Why are module and controller combined with a minus sign?
>
> (Sorry if this was discussed before.)
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

weierophinney
Administrator
In reply to this post by Simon Walter
-- Simon Walter <[hidden email]> wrote
(on Monday, 14 November 2011, 05:19 AM -0900):
> Why are module and controller combined with a minus sign?
>
> (Sorry if this was discussed before.)

Are you talking about controller aliases? If so, it's to ensure unique
aliases between modules. Otherwise, we end up with potential conflicts
as one module tries to define an alias that another has already defined.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

Simon Walter
On Monday, November 14, 2011 05:51:54 Matthew Weier O'Phinney wrote:

> -- Simon Walter <[hidden email]> wrote
>
> (on Monday, 14 November 2011, 05:19 AM -0900):
> > Why are module and controller combined with a minus sign?
> >
> > (Sorry if this was discussed before.)
>
> Are you talking about controller aliases? If so, it's to ensure unique
> aliases between modules. Otherwise, we end up with potential conflicts
> as one module tries to define an alias that another has already defined.

No, but perhaps I read into it too much. I was going over the new components
and reading the nice new ZF2 manual
(http://packages.zendframework.com/docs/latest/manual/en/), very nice BTW, and
then came upon quick start bit that covers application and module layout:

"ZendSkeletonApplication ships with a "default route" that will likely get you
to this action. That route basically expects "/{controller}/{action}", which
allows you to specify this: "/zend-user-hello/world"."

I thought that might be a typo, at first. I followed the instructions, and
yes, it's with a minus. I thought this was *just* an example. So I looked
around the ZendSkeletonApplication which does create a default route in
modules/Application/configs/module.config.php, but that does not seem to
specify a module segment: '/[:controller[/:action]]'

I imagine many people would want to use a / to separate module and controller
rather than a -. Perhaps this could be the default in the example or make the
documentation clear about how this is happening, as it is nice to see various
use cases and examples.

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

EvanDotPro
On Mon, Nov 14, 2011 at 5:40 PM, Simon Walter <[hidden email]> wrote:

> On Monday, November 14, 2011 05:51:54 Matthew Weier O'Phinney wrote:
>> -- Simon Walter <[hidden email]> wrote
>>
>> (on Monday, 14 November 2011, 05:19 AM -0900):
>> > Why are module and controller combined with a minus sign?
>> >
>> > (Sorry if this was discussed before.)
>>
>> Are you talking about controller aliases? If so, it's to ensure unique
>> aliases between modules. Otherwise, we end up with potential conflicts
>> as one module tries to define an alias that another has already defined.
>
> No, but perhaps I read into it too much. I was going over the new components
> and reading the nice new ZF2 manual
> (http://packages.zendframework.com/docs/latest/manual/en/), very nice BTW, and
> then came upon quick start bit that covers application and module layout:
>
> "ZendSkeletonApplication ships with a "default route" that will likely get you
> to this action. That route basically expects "/{controller}/{action}", which
> allows you to specify this: "/zend-user-hello/world"."
>
> I thought that might be a typo, at first. I followed the instructions, and
> yes, it's with a minus. I thought this was *just* an example. So I looked
> around the ZendSkeletonApplication which does create a default route in
> modules/Application/configs/module.config.php, but that does not seem to
> specify a module segment: '/[:controller[/:action]]'
>
> I imagine many people would want to use a / to separate module and controller
> rather than a -. Perhaps this could be the default in the example or make the
> documentation clear about how this is happening, as it is nice to see various
> use cases and examples.

I have implemented a quick and dirty proof of concept for ZF1-style
"module" routing, which I believe addresses some of the concerns in
this thread. I put "module" in quotes because it is really just a
segment that maps to a namespace, and theoretically has nothing to do
with modules at all.

ZF2 changes are in my feature/namespace-route branch:

- https://github.com/EvanDotPro/zf2/tree/feature/namespace-route
- Specific commit:
https://github.com/EvanDotPro/zf2/commit/d9e3965eacdc635a85fd86b005934697f472a50e

ZendSkeletonApplciation changes in the respective
feature/namespace-route branch:
- https://github.com/EvanDotPro/ZendSkeletonApplication/tree/feature/namespace-route
- Specific commit:
https://github.com/EvanDotPro/ZendSkeletonApplication/commit/c645c836a23a251a041a0b50d2ac6f88ef8726ac

I personally wouldn't use this route, but I'm sure the demand from
those coming from ZF1 is high enough to warrant such a feature. The
specific implementation is just a proof of concept, so the code isn't
beautiful. The important part is simply the behavior that the code
performs. The logic is based on that outlined in this Gist:
https://gist.github.com/44438ebab645a7d06a0d

For the lazy:

/foo
  - check for 'foo' DI alias
  - Foo\Controller\IndexController::indexAction()
  - Application\Controller\FooController::indexAction()

/foo-bar
  - check for 'foo-bar' DI alias
  - FooBar\Controller\IndexController::indexAction()
  - Application\Controller\FooBarController::indexAction()

/foo/bar
  - check for 'foo' DI alias
  - Foo\Controller\BarController::indexAction()
  - Application\Controller\FooController::barAction()

/foo/bar/baz
  - check for 'foo' DI alias
  - Foo\Controller\BarController::bazAction()

If the demand is there for this, I'll work with Ben Scholzen and
Matthew to clean up the implementation and get it into the core.

--
Evan Coury

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

Benoît Durand

Le 15 nov. 11 à 05:58, Evan Coury a écrit :

> If the demand is there for this, I'll work with Ben Scholzen and
> Matthew to clean up the implementation and get it into the core.
Into the core or ZF1 layer? ;)

Simon, do you understand than module of ZF2 is not the same thing than  
module of ZF1?
Module of ZF1 is a directory, and module of ZF2 is a namespace.

We don't need to define module in URL with zf2: just a segment in  
order to reflect a controller class namespaced.

--
Benoît Durand
--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

EvanDotPro
2011/11/14 Benoît Durand <[hidden email]>:
>
> Le 15 nov. 11 à 05:58, Evan Coury a écrit :
>
>> If the demand is there for this, I'll work with Ben Scholzen and
>> Matthew to clean up the implementation and get it into the core.
>
> Into the core or ZF1 layer? ;)

Probably core (once the implementation is massively cleaned up) since
this is ZF1-style routing for the ZF2 MVC. The ZF1 layer module still
has the old module route which should work.

--
Evan Coury

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

weierophinney
Administrator
In reply to this post by Simon Walter
-- Simon Walter <[hidden email]> wrote
(on Monday, 14 November 2011, 03:40 PM -0900):

> On Monday, November 14, 2011 05:51:54 Matthew Weier O'Phinney wrote:
> > -- Simon Walter <[hidden email]> wrote
> >
> > (on Monday, 14 November 2011, 05:19 AM -0900):
> > > Why are module and controller combined with a minus sign?
> > >
> > > (Sorry if this was discussed before.)
> >
> > Are you talking about controller aliases? If so, it's to ensure unique
> > aliases between modules. Otherwise, we end up with potential conflicts
> > as one module tries to define an alias that another has already defined.
>
> No, but perhaps I read into it too much. I was going over the new components
> and reading the nice new ZF2 manual
> (http://packages.zendframework.com/docs/latest/manual/en/), very nice BTW, and
> then came upon quick start bit that covers application and module layout:
>
> "ZendSkeletonApplication ships with a "default route" that will likely get you
> to this action. That route basically expects "/{controller}/{action}", which
> allows you to specify this: "/zend-user-hello/world"."
>
> I thought that might be a typo, at first. I followed the instructions, and
> yes, it's with a minus. I thought this was *just* an example. So I looked
> around the ZendSkeletonApplication which does create a default route in
> modules/Application/configs/module.config.php, but that does not seem to
> specify a module segment: '/[:controller[/:action]]'
>
> I imagine many people would want to use a / to separate module and controller
> rather than a -. Perhaps this could be the default in the example or make the
> documentation clear about how this is happening, as it is nice to see various
> use cases and examples.

The way that dispatching occurs is completely module agnostic.

The idea is that you simply map routes to controllers, and then
controllers determine what to do with the request.

The only reasons I've had examples that include the module name are:

 * To prevent naming collisions in the DiC/SL when pulling a controller
   by name.
 * To ensure that view scripts are identified in the correct
   directories.

These issues can both be solved in other ways.

I'd argue you should focus on semantic routing to explictly named
controllers (as in, by class name), and not rely on "magic" routing such
as the above. Why?

 * It will help you focus on the idea that a module should provide one
   discrete set of functionality only. Instead of grouping together many
   controllers that do many separate things, have one or two controllers
   that do related things.
 * It will force you to start thinking of routes in modules as trees
   deriving from a single route. This makes it easier to group related
   controllers under a single master route, while still retaining the
   specificity of granular routes.
 * It will prevent naming collisions.
 * It will allow for substitutions (simply override the configuration).

While I think a "default" module can be useful for RAD, I also think
it's very limiting, and I'd rather promote the above ideas.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

Simon Walter
On Tuesday, November 15, 2011 06:50:00 Matthew Weier O'Phinney wrote:

> -- Simon Walter <[hidden email]> wrote
>
> (on Monday, 14 November 2011, 03:40 PM -0900):
> > On Monday, November 14, 2011 05:51:54 Matthew Weier O'Phinney wrote:
> > > -- Simon Walter <[hidden email]> wrote
> > >
> > > (on Monday, 14 November 2011, 05:19 AM -0900):
> > > > Why are module and controller combined with a minus sign?
> > > >
> > > > (Sorry if this was discussed before.)
> > >
> > > Are you talking about controller aliases? If so, it's to ensure
> > > unique
> > > aliases between modules. Otherwise, we end up with potential
> > > conflicts
> > > as one module tries to define an alias that another has already
> > > defined.>
> > No, but perhaps I read into it too much. I was going over the new
> > components and reading the nice new ZF2 manual
> > (http://packages.zendframework.com/docs/latest/manual/en/), very nice
> > BTW, and then came upon quick start bit that covers application and
> > module layout:
> >
> > "ZendSkeletonApplication ships with a "default route" that will likely
> > get you to this action. That route basically expects
> > "/{controller}/{action}", which allows you to specify this:
> > "/zend-user-hello/world"."
> >
> > I thought that might be a typo, at first. I followed the instructions,
> > and yes, it's with a minus. I thought this was *just* an example. So I
> > looked around the ZendSkeletonApplication which does create a default
> > route in modules/Application/configs/module.config.php, but that does
> > not seem to specify a module segment: '/[:controller[/:action]]'
> >
> > I imagine many people would want to use a / to separate module and
> > controller rather than a -. Perhaps this could be the default in the
> > example or make the documentation clear about how this is happening, as
> > it is nice to see various use cases and examples.
>
> The way that dispatching occurs is completely module agnostic.
>
> The idea is that you simply map routes to controllers, and then
> controllers determine what to do with the request.
>
> The only reasons I've had examples that include the module name are:
>
>  * To prevent naming collisions in the DiC/SL when pulling a controller
>    by name.
>  * To ensure that view scripts are identified in the correct
>    directories.

It's all over the manual. This indicates it is a ZF best practice. I would
argue that it is not consistent.

http://example.com/user/read/123
vs
http://example.com/user-read/123

I don't like the concatenated "module-controller" directory for view scripts,
and I don't like it in the URL or route either. Hierarchies are for a reason.
Having the module name included in the view script directory name seems
redundant.

While it would be nice to do this:
'route'    => '/modulename/[:controller[/:action]]'

As is currently, I would end up with:
http://example.com/modulename/modulename-controller/action

With all the arguments against "magic" stuff, why is it being done here? If I
call my controller "Product", why must I reference as module-product? Seems
like some "magic" stuff to me.

>
> These issues can both be solved in other ways.
>
> I'd argue you should focus on semantic routing to explictly named
> controllers (as in, by class name), and not rely on "magic" routing such
> as the above. Why?
>
>  * It will help you focus on the idea that a module should provide one
>    discrete set of functionality only. Instead of grouping together many
>    controllers that do many separate things, have one or two controllers
>    that do related things.
>  * It will force you to start thinking of routes in modules as trees
>    deriving from a single route. This makes it easier to group related
>    controllers under a single master route, while still retaining the
>    specificity of granular routes.
>  * It will prevent naming collisions.
>  * It will allow for substitutions (simply override the configuration).
>
> While I think a "default" module can be useful for RAD, I also think
> it's very limiting, and I'd rather promote the above ideas.

I don't see how having a "namespace" segment, as Evan has called it in his
implementation, would detract from any of the points you present.

I should be more clear. I don't see a need for a default module that handles
routing etc. I do like the per-module config and setting up routes in there.
That's very nice. Everything is contained and no assumptions are made about
how the module works etc.

For many applications, I'd want the various parts to be accessible in a
standard fasion. Predictability is nice. I use one off routes sometimes, but
generally I follow a pattern just for sanity's sake. Being able to create such
a pattern, and it doesn't need to be the default BTW, is what I'm after.

But that is all beside the point. Having controller and module concatenated as
a segment in a route seems to be a drawback to any type of route. IMHO, It
does not solve the naming collision issue in a elegant way.

This begs the question: Is the Router the only class that does this module-
controller concatenation? What about views? Anywhere else?

Sorry if I seem annoyed about this seemingly little thing. It doesn't have
much to do with ZF1. It's got more to do with consistency.

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

booradleys
This post has NOT been accepted by the mailing list yet.
I begin to understand.
Tell me if I'm wrong but
1 - The old urls like / module / controller / action must be rewritten / namespace-controller/action.
2 - All records of view scripts should be appointed <Controller> renamed <namespace-controller>
3 - prefix all the namespace-alias to ensure their uniqueness.

I still have it just slows down the rendering to get the view script to the right place:

When I call / candidat-catalogue/recherche:
1 - catalog controller action research (in my module / namespace Candidate) is called with my candidate catalog alias => OK
2 - The view script is searched in my module / namespace Application => KO

Message: Script "candidat-catalogue/recherche.phtml" not found in path (F: \ Zend \ ZF2 \ application \ modules \ Application \ configs / .. / views / scripts \).

This is the class that raises bp Listener looks like ...

Have you any idea?
Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

Mischosch
In reply to this post by weierophinney

Am 15.11.2011 um 16:50 schrieb Matthew Weier O'Phinney:

> -- Simon Walter <[hidden email]> wrote
> (on Monday, 14 November 2011, 03:40 PM -0900):
>> On Monday, November 14, 2011 05:51:54 Matthew Weier O'Phinney wrote:
>>> -- Simon Walter <[hidden email]> wrote
>>>
>>> (on Monday, 14 November 2011, 05:19 AM -0900):
>>>> Why are module and controller combined with a minus sign?
>>>>
>>>> (Sorry if this was discussed before.)
>>>
>>> Are you talking about controller aliases? If so, it's to ensure unique
>>> aliases between modules. Otherwise, we end up with potential conflicts
>>> as one module tries to define an alias that another has already defined.
>>
>> No, but perhaps I read into it too much. I was going over the new components
>> and reading the nice new ZF2 manual
>> (http://packages.zendframework.com/docs/latest/manual/en/), very nice BTW, and
>> then came upon quick start bit that covers application and module layout:
>>
>> "ZendSkeletonApplication ships with a "default route" that will likely get you
>> to this action. That route basically expects "/{controller}/{action}", which
>> allows you to specify this: "/zend-user-hello/world"."
>>
>> I thought that might be a typo, at first. I followed the instructions, and
>> yes, it's with a minus. I thought this was *just* an example. So I looked
>> around the ZendSkeletonApplication which does create a default route in
>> modules/Application/configs/module.config.php, but that does not seem to
>> specify a module segment: '/[:controller[/:action]]'
>>
>> I imagine many people would want to use a / to separate module and controller
>> rather than a -. Perhaps this could be the default in the example or make the
>> documentation clear about how this is happening, as it is nice to see various
>> use cases and examples.
>
> The way that dispatching occurs is completely module agnostic.
>
> The idea is that you simply map routes to controllers, and then
> controllers determine what to do with the request.
>
> The only reasons I've had examples that include the module name are:
>
> * To prevent naming collisions in the DiC/SL when pulling a controller
>   by name.
> * To ensure that view scripts are identified in the correct
>   directories.
>
> These issues can both be solved in other ways.
>
> I'd argue you should focus on semantic routing to explictly named
> controllers (as in, by class name), and not rely on "magic" routing such
> as the above. Why?
>
> * It will help you focus on the idea that a module should provide one
>   discrete set of functionality only. Instead of grouping together many
>   controllers that do many separate things, have one or two controllers
>   that do related things.
> * It will force you to start thinking of routes in modules as trees
>   deriving from a single route. This makes it easier to group related
>   controllers under a single master route, while still retaining the
>   specificity of granular routes.
> * It will prevent naming collisions.
> * It will allow for substitutions (simply override the configuration).
>
> While I think a "default" module can be useful for RAD, I also think
> it's very limiting, and I'd rather promote the above ideas.
Hi there,

while playing around with zf2 I was running fast into this collisions thing.
I created two modules, threw an IndexController (with different namespaces) into it and wanted to see, how things are working.
It worked somehow, but really not the way I thought it would work. So I renamed it to Index2, gave it another alias and got it working.
So, while looking into it, I understood this overriding and collision thing.

So, my point is: Its great having the possibility to override things, but in general I don't want to think too much about the naming of my Aliases or Controllers.
Perhaps Index is a bad example. But what happens, if you use the edpuser module (with an "user" alias in it), and in two of your own modules you have an "user" alias, too?
Rethink your explicity naming conventions?

Modules have namespaces, great! So why dont use them?
There are mainly two points, where it matters: routing and view rendering.

I was talking with Evan about this topic and decided to give it a try to implement namespaces into routing and view rendering.

It is some time ago, that I pushed it to my zf2 repo, never got more feedback and missed it, to send it it here:

https://github.com/Mischosch/zf2/commit/0d39c965a4fede88f3911bae161aeca63daf0f7e - "namespace" router
https://github.com/Mischosch/zf2/commit/cc00b8256a779ce056a46543c2ad56572644915c - add namespace support for Zend\Mvc\Application request - alias matching
(https://github.com/Mischosch/zf2/commit/ddd48718b2ea5b727474230bedcb5b6b80668a82 - port Zend/Controller/Router/Route to Mvc)

The view part (ViewListener) is a little bit more complex. You have the templateStack full of paths.
No Namespace is used there, so I decided to fetch only my given module path and remove other view paths from stack.
Its a "working" solution for rendering the views of the given namespace/module (not a nice one perhaps).

Its getting more complicated, if a module contains more than one namespace.


So, I get the idea of "explictly named controllers".
But while using more and more modules - collisions seem to be there really fast.
UserController is a common thing - why should I have to rethink the naming?
Using "namespaces" in routes would really help avoiding collisions.


Or how would you deal with 3 different UserControllers in different modules?
Perhaps Im missing something with routing, aliasing and view rendering.

Can you explain more in detail, what you mean with "thinking of routes in modules as trees" ?


Cheers

Mischosch



smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

weierophinney
Administrator
In reply to this post by Simon Walter
-- Simon Walter <[hidden email]> wrote
(on Wednesday, 16 November 2011, 12:35 AM -0900):

> On Tuesday, November 15, 2011 06:50:00 Matthew Weier O'Phinney wrote:
> > -- Simon Walter <[hidden email]> wrote
> > (on Monday, 14 November 2011, 03:40 PM -0900):
> > > On Monday, November 14, 2011 05:51:54 Matthew Weier O'Phinney wrote:
> > > > -- Simon Walter <[hidden email]> wrote
> > > > (on Monday, 14 November 2011, 05:19 AM -0900):
> >
> > The way that dispatching occurs is completely module agnostic.
> >
> > The idea is that you simply map routes to controllers, and then
> > controllers determine what to do with the request.
> >
> > The only reasons I've had examples that include the module name are:
> >
> >  * To prevent naming collisions in the DiC/SL when pulling a controller
> >    by name.
> >  * To ensure that view scripts are identified in the correct
> >    directories.
>
> It's all over the manual. This indicates it is a ZF best practice.

Slow down, please. We've only released our first beta, and, as noted in
the release announcement, these are gmail-style betas. There are no best
practices yet in ZF2. Lots of things are subject to change.

> I would argue that it is not consistent.
>
> http://example.com/user/read/123
> vs
> http://example.com/user-read/123
>
> I don't like the concatenated "module-controller" directory for view
> scripts, and I don't like it in the URL or route either. Hierarchies
> are for a reason.  Having the module name included in the view script
> directory name seems redundant.

It does, until you have two modules that each have controllers with the
same name, and actions of the same name. Which view script is used then?

That's the real issue here. Right now, the "module-controller"
convention is simply because it makes using aliases easy, and because it
makes view script resolution easy. The former problem is a matter of
taste, and easily overridable and changed, but the latter is a bigger
problem. More below.

> While it would be nice to do this:
> 'route'    => '/modulename/[:controller[/:action]]'
>
> As is currently, I would end up with:
> http://example.com/modulename/modulename-controller/action
>
> With all the arguments against "magic" stuff, why is it being done here? If I
> call my controller "Product", why must I reference as module-product? Seems
> like some "magic" stuff to me.

Did you read my notes below, about routing to specific controllers?

> > These issues can both be solved in other ways.
> >
> > I'd argue you should focus on semantic routing to explictly named
> > controllers (as in, by class name), and not rely on "magic" routing such
> > as the above. Why?
> >
> >  * It will help you focus on the idea that a module should provide one
> >    discrete set of functionality only. Instead of grouping together many
> >    controllers that do many separate things, have one or two controllers
> >    that do related things.
> >  * It will force you to start thinking of routes in modules as trees
> >    deriving from a single route. This makes it easier to group related
> >    controllers under a single master route, while still retaining the
> >    specificity of granular routes.
> >  * It will prevent naming collisions.
> >  * It will allow for substitutions (simply override the configuration).
> >
> > While I think a "default" module can be useful for RAD, I also think
> > it's very limiting, and I'd rather promote the above ideas.
>
> I don't see how having a "namespace" segment, as Evan has called it in
> his implementation, would detract from any of the points you present.

It adds more information to track, and information that is highly
dynamic and potentially incorrect.

What if you override configuration to have a route defined in one module
actually go to a controller in another module? But you want to use the
view script from the original module? Using aliases makes this work
easily, as the "module-controller" alias simply points to a different
controller class now -- but the alias stays the same. (Just playing
devil's advocate here.)

Also, I'm going to note that the autodiscovery of module view script
directories in ZF1 has led to a lot of WTF?!?! moments by users,
resulting in quite some issue reports. Why? because folks forget that
they have other modules that define the same controllers, and that
_forward() and action() and whatnot end up playing with the view script
hierarchy.

By having the routing convention only worry about controllers we
simplify this -- but in turn need to make other things more specific,
such as which view script directory we want to select.

> I should be more clear. I don't see a need for a default module that handles
> routing etc. I do like the per-module config and setting up routes in there.
> That's very nice. Everything is contained and no assumptions are made about
> how the module works etc.
>
> For many applications, I'd want the various parts to be accessible in a
> standard fasion. Predictability is nice. I use one off routes sometimes, but
> generally I follow a pattern just for sanity's sake. Being able to create such
> a pattern, and it doesn't need to be the default BTW, is what I'm after.

I'd argue that each module should define this. It's relatively easy to
do this with the Segment and Part routes at this time -- you define your
module's routes as a single "part" route, with a "Literal" route
defining the root, and with one or more child "Segment" routes. One of
these might be "/:controller[/:action]". This allows you to be highly
specific with your controller arguments -- specifying the exact class.
Since this is in configuration, you can then override it with separate
classes.

What we really need to answer, however, is how to do the mapping to the
view scripts. One suggestion is to use "module/controller/<scripts>" -
but that also means knowing what "module" we're in. Another possibility
is to have the controllers inform the view somehow of where to look for
the view script -- perhaps via annotations, perhaps explicitly by
providing an argument in the return value.

> But that is all beside the point. Having controller and module
> concatenated as a segment in a route seems to be a drawback to any
> type of route. IMHO, It does not solve the naming collision issue in a
> elegant way.

I'll note that I have explicit routes for everything on my site. These
point the controller to _names_ -- the routes themselves are not using
the "module-controller" annotation, but the controller they resolve to
_is_ -- and that *alias* is then used to identify a controller class,
and then resolve to a view script. That's all.

That addresses the concatenated names in the URL -- there aren't any.
But it does not address cleanly the view script resolution.

> This begs the question: Is the Router the only class that does this
> module- controller concatenation? What about views? Anywhere else?
>
> Sorry if I seem annoyed about this seemingly little thing. It doesn't
> have much to do with ZF1. It's got more to do with consistency.

So, let's get a proposal out there for _VIEW_ _SCRIPT_ _RESOLUTION_.
That's the real issue here. Everything else is solvable, and not even
something the routes define.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

EvanDotPro
On Wed, Nov 16, 2011 at 9:11 AM, Matthew Weier O'Phinney
<[hidden email]> wrote:

> -- Simon Walter <[hidden email]> wrote
> (on Wednesday, 16 November 2011, 12:35 AM -0900):
>> On Tuesday, November 15, 2011 06:50:00 Matthew Weier O'Phinney wrote:
>> > -- Simon Walter <[hidden email]> wrote
>> > (on Monday, 14 November 2011, 03:40 PM -0900):
>> > > On Monday, November 14, 2011 05:51:54 Matthew Weier O'Phinney wrote:
>> > > > -- Simon Walter <[hidden email]> wrote
>> > > > (on Monday, 14 November 2011, 05:19 AM -0900):
>> >
>> > The way that dispatching occurs is completely module agnostic.
>> >
>> > The idea is that you simply map routes to controllers, and then
>> > controllers determine what to do with the request.
>> >
>> > The only reasons I've had examples that include the module name are:
>> >
>> >  * To prevent naming collisions in the DiC/SL when pulling a controller
>> >    by name.
>> >  * To ensure that view scripts are identified in the correct
>> >    directories.
>>
>> It's all over the manual. This indicates it is a ZF best practice.
>
> Slow down, please. We've only released our first beta, and, as noted in
> the release announcement, these are gmail-style betas. There are no best
> practices yet in ZF2. Lots of things are subject to change.
>
>> I would argue that it is not consistent.
>>
>> http://example.com/user/read/123
>> vs
>> http://example.com/user-read/123
>>
>> I don't like the concatenated "module-controller" directory for view
>> scripts, and I don't like it in the URL or route either. Hierarchies
>> are for a reason.  Having the module name included in the view script
>> directory name seems redundant.
>
> It does, until you have two modules that each have controllers with the
> same name, and actions of the same name. Which view script is used then?
>
> That's the real issue here. Right now, the "module-controller"
> convention is simply because it makes using aliases easy, and because it
> makes view script resolution easy. The former problem is a matter of
> taste, and easily overridable and changed, but the latter is a bigger
> problem. More below.
>
>> While it would be nice to do this:
>> 'route'    => '/modulename/[:controller[/:action]]'
>>
>> As is currently, I would end up with:
>> http://example.com/modulename/modulename-controller/action
>>
>> With all the arguments against "magic" stuff, why is it being done here? If I
>> call my controller "Product", why must I reference as module-product? Seems
>> like some "magic" stuff to me.
>
> Did you read my notes below, about routing to specific controllers?
>
>> > These issues can both be solved in other ways.
>> >
>> > I'd argue you should focus on semantic routing to explictly named
>> > controllers (as in, by class name), and not rely on "magic" routing such
>> > as the above. Why?
>> >
>> >  * It will help you focus on the idea that a module should provide one
>> >    discrete set of functionality only. Instead of grouping together many
>> >    controllers that do many separate things, have one or two controllers
>> >    that do related things.
>> >  * It will force you to start thinking of routes in modules as trees
>> >    deriving from a single route. This makes it easier to group related
>> >    controllers under a single master route, while still retaining the
>> >    specificity of granular routes.
>> >  * It will prevent naming collisions.
>> >  * It will allow for substitutions (simply override the configuration).
>> >
>> > While I think a "default" module can be useful for RAD, I also think
>> > it's very limiting, and I'd rather promote the above ideas.
>>
>> I don't see how having a "namespace" segment, as Evan has called it in
>> his implementation, would detract from any of the points you present.
>
> It adds more information to track, and information that is highly
> dynamic and potentially incorrect.
>
> What if you override configuration to have a route defined in one module
> actually go to a controller in another module? But you want to use the
> view script from the original module? Using aliases makes this work
> easily, as the "module-controller" alias simply points to a different
> controller class now -- but the alias stays the same. (Just playing
> devil's advocate here.)
>
> Also, I'm going to note that the autodiscovery of module view script
> directories in ZF1 has led to a lot of WTF?!?! moments by users,
> resulting in quite some issue reports. Why? because folks forget that
> they have other modules that define the same controllers, and that
> _forward() and action() and whatnot end up playing with the view script
> hierarchy.
>
> By having the routing convention only worry about controllers we
> simplify this -- but in turn need to make other things more specific,
> such as which view script directory we want to select.
>
>> I should be more clear. I don't see a need for a default module that handles
>> routing etc. I do like the per-module config and setting up routes in there.
>> That's very nice. Everything is contained and no assumptions are made about
>> how the module works etc.
>>
>> For many applications, I'd want the various parts to be accessible in a
>> standard fasion. Predictability is nice. I use one off routes sometimes, but
>> generally I follow a pattern just for sanity's sake. Being able to create such
>> a pattern, and it doesn't need to be the default BTW, is what I'm after.
>
> I'd argue that each module should define this. It's relatively easy to
> do this with the Segment and Part routes at this time -- you define your
> module's routes as a single "part" route, with a "Literal" route
> defining the root, and with one or more child "Segment" routes. One of
> these might be "/:controller[/:action]". This allows you to be highly
> specific with your controller arguments -- specifying the exact class.
> Since this is in configuration, you can then override it with separate
> classes.
>
> What we really need to answer, however, is how to do the mapping to the
> view scripts. One suggestion is to use "module/controller/<scripts>" -
> but that also means knowing what "module" we're in. Another possibility
> is to have the controllers inform the view somehow of where to look for
> the view script -- perhaps via annotations, perhaps explicitly by
> providing an argument in the return value.
>
>> But that is all beside the point. Having controller and module
>> concatenated as a segment in a route seems to be a drawback to any
>> type of route. IMHO, It does not solve the naming collision issue in a
>> elegant way.
>
> I'll note that I have explicit routes for everything on my site. These
> point the controller to _names_ -- the routes themselves are not using
> the "module-controller" annotation, but the controller they resolve to
> _is_ -- and that *alias* is then used to identify a controller class,
> and then resolve to a view script. That's all.
>
> That addresses the concatenated names in the URL -- there aren't any.
> But it does not address cleanly the view script resolution.
>
>> This begs the question: Is the Router the only class that does this
>> module- controller concatenation? What about views? Anywhere else?
>>
>> Sorry if I seem annoyed about this seemingly little thing. It doesn't
>> have much to do with ZF1. It's got more to do with consistency.
>
> So, let's get a proposal out there for _VIEW_ _SCRIPT_ _RESOLUTION_.
> That's the real issue here. Everything else is solvable, and not even
> something the routes define.

Exactly.

At this point, I have no intentions of submitting my earlier patch for
inclusion into the core, so I've decided to spin off the functionality
into a module for those who prefer a default route like this:

https://github.com/EvanDotPro/EdpMagicRoute

You can use this today, and it works. Simply install that module and
enable it _after_ your Application module in application.config.php,
and voilà, you have the ZF1-style routes you're asking for.

That said, this absolutely does NOT solve the view rendering issue. As
Matthew has said, that's the real issue here.

--
Evan Coury

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Routes - module-controller

knguyen
This post has NOT been accepted by the mailing list yet.
In reply to this post by Adam Lundrigan
Hi Adam,

Controller class name:  Module_MyFooController
Controller action name:  doSomethingAction
URL to invoke action:   /module/my-foo/do-something


How can I do follow this way. Can you help me? Thanks!