Use a "Controller_" namespace prefix for anything inside the controllers directory

15 views
Skip to first unread message

Ryan R.

unread,
Apr 19, 2012, 9:21:12 AM4/19/12
to zfdeve...@googlegroups.com
Hi,

Is there any way to achieve something like this :
In the controllers directory, have controllers named as specified in the convention ( i.e. : IndexController)
An yet be able to name the related class "Controller_IndexController" in order to have an homogeneous way of naming classes based on their locations in relation to the APPLICATION_PATH.

Thanks.

Rolando Garro

unread,
Apr 19, 2012, 4:24:38 PM4/19/12
to Zend Framework Developers
You can use somthing like the code below to load classes
from your own library and keep a name convention
like RNAME_Dirname_classname

protected function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
$moduleLoader->addResourceType("RNAME", '../library/
RNAME','RNAME');
return $moduleLoader;
}

but I guess you'd have to tweak the front controller to use your name
convention on controllers.

Randell

unread,
Apr 19, 2012, 12:51:22 PM4/19/12
to zfdeve...@googlegroups.com
What benefit do you get from doing this?



--
You received this message because you are subscribed to the Google Groups "Zend Framework Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/zfdevelopers/-/FVQdeyYt9iYJ.
To post to this group, send email to zfdeve...@googlegroups.com.
To unsubscribe from this group, send email to zfdevelopers...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/zfdevelopers?hl=en.

Ryan R.

unread,
Apr 20, 2012, 9:00:40 AM4/20/12
to zfdeve...@googlegroups.com
Yes That's what I've settled for for the moment using a resource type to get anything related to controllers (but not controllers) like adapters, output wrappers (it's for a webservice architecture).
But it only works for specified resources.
That results in a difference between the controllers naming convention and the others classes...
But as of right now, it works for me even if it's not ideal.
Thanks.

Ryan R.

unread,
Apr 20, 2012, 9:03:18 AM4/20/12
to zfdeve...@googlegroups.com
The benefit is this is purely non-fonctionnal : it allows you to have the same naming conventions evrywhere :
Controller_IndexController >>> in application/controllers
Controller_Adapter_IndexAdapter >>> in application/controllers/adapters
Model_{...} >>> in application/models
Service_{...} >>> in application/services
and so on ...

It has no purpose other that providing an homogeneous way of naming classes which is the base principle of a "Naming Convention".


Le jeudi 19 avril 2012 18:51:22 UTC+2, Randell a écrit :
What benefit do you get from doing this?

On Thu, Apr 19, 2012 at 9:21 PM, Ryan R. <ryan.r...@gmail.com> wrote:
Hi,

Is there any way to achieve something like this :
In the controllers directory, have controllers named as specified in the convention ( i.e. : IndexController)
An yet be able to name the related class "Controller_IndexController" in order to have an homogeneous way of naming classes based on their locations in relation to the APPLICATION_PATH.

Thanks.


--
You received this message because you are subscribed to the Google Groups "Zend Framework Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/zfdevelopers/-/FVQdeyYt9iYJ.
To post to this group, send email to zfdeve...@googlegroups.com.
To unsubscribe from this group, send email to zfdevelopers+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages