0

For example, we have index controller:

class IndexController{ ...

How to make e.g.

class Index_Controller{ ...

work?

2 Answers 2

3

I've never tried it myself (and wouldn't really recommend doing this : knowing how classes are nammed is nice, because they follow the standard, when you start working on an existsing ZF-based project !), but there might be a solution ; see the following section from the manual : 12.6.2. Subclassing the Dispatcher

At the bottom of the page, it says (quoting, emphasis mine) :

Possible reasons to subclass the dispatcher include a desire to use a different class or method naming schema in your action controllers, or a desire to use a different dispatching paradigm such as dispatching to action files under controller directories (instead of dispatching to class methods).

So, this might help you do what you're asking -- once again, I've never this seen done, so I can't say for sure, but I hope this will give a hint to the final solution...

Sign up to request clarification or add additional context in comments.

Comments

1

As Pascal MARTIN suggested, subclassing the dispatcher is the right way to go - even I'd share his opinion that deviating from the given ZF-naming convention should be well-founded.

Zend_Controller_Dispatcher_Abstract provides two methods that determine the name of the controller class and the action method respectively:

public function formatControllerName($unformatted)
{
    return ucfirst($this->_formatName($unformatted)) . 'Controller';
}

public function formatActionName($unformatted)
{
    $formatted = $this->_formatName($unformatted, true);
    return strtolower(substr($formatted, 0, 1)) . substr($formatted, 1) . 'Action';
}

You can just subclass Zend_Controller_Dispatcher_Abstract and override one or both methods to match your required naming convention.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.