Page 1 of 1

Zend Framework Zend_Controller_Router_Route

Posted: Wed Dec 12, 2007 11:07 am
by shiznatix
I am having some massive problems with Zend_Controller_Router_Route and I am not sure where else to ask this so maybe someone else knows whats going on.

I am trying to make a route for this URL:
http://192.168.2.100/zf/rbadmin/room-signups/update/1/

so I do this:

Code: Select all

$route11 = new Zend_Controller_Router_Route(
	'room-signups/update/:id',
	array(
		'controller' => 'roomsignups',
		'action'     => 'update'
	)
);
But this throws me this error:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (RoomSignups)' in /var/www/lib/library/Zend/Controller/Dispatcher/Standard.php:198 Stack trace: #0 /var/www/lib/library/Zend/Controller/Front.php(929): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /var/www/zf/rbadmin/index.php(158): Zend_Controller_Front->dispatch() #2 /var/www/zf/rbadmin/room-signups.php(1): require_once('/var/www/zf/rba...') #3 {main} thrown in /var/www/lib/library/Zend/Controller/Dispatcher/Standard.php on line 198
Now I understand this is because if I let it do the route by default then it is looking for the controller file: RoomSignupsController.php which is what I want. But if I use the custom route that I want, it starts looking for the controller file RoomsignupsController.php (notice the lowercase "s"). So then it can't find the file and craps out on me.

So, how can I make it so I specify the controller file or just make it so that when it takes out the '-' it does a ucfirst() or something on it so everything is good? I would rather have it so that it turns to RoomSignupsController even when using the custom route.

Posted: Thu Dec 13, 2007 9:19 am
by shiznatix
Ok I don't mean to bumb too early but I won't have access to a computer for about a day after this so I will do this anyway but with some extra information...

I have tried basically digging through all of the places that the router goes but I can't find where it changes the way the controller is named. I have set it explicitally as "RoomSignups" but it still changes it back to "Roomsignups". I dumped out the $router variable and all was showing correct so somewhere between that and the dispatch the controller gets changed, I just can't find where this happens. If someone knows, please help me out.

Posted: Thu Dec 13, 2007 9:36 am
by John Cartwright
Why don't you just rename your controller to the standard naming convention? Either way.. heres the function that formats the controller name.
/Zend/Controller/Dispatcher/Abstract.php

Code: Select all

abstract class Zend_Controller_Dispatcher_Abstract implements Zend_Controller_Dispatcher_Interface
{
    /**
     * Formats a string into a controller name.  This is used to take a raw
     * controller name, such as one stored inside a Zend_Controller_Request_Abstract
     * object, and reformat it to a proper class name that a class extending
     * Zend_Controller_Action would use.
     *
     * @param string $unformatted
     * @return string
     */
    public function formatControllerName($unformatted)
    {
        return ucfirst($this->_formatName($unformatted)) . 'Controller';
    }

Posted: Fri Dec 14, 2007 2:17 am
by shiznatix
What is the standard? It is hard because if I name it like this: "RoomsignupsController.php" it only works if I use the custom routes. If I name it "RoomSignupsController.php" the the custom routes don't work. It does not seam to be standardized at all, kinda seams like a bug to me.

anyway, after looking at the code there, if I do this:

Code: Select all

'controller' => 'room-signups',
for my custom routes then everything works just peachy.