On few following lines I will try to explain my problem as clearly as I can. What I am trying to do is match URLs like this:
www.mydomain.com/someusername
To this:
www.mydomain.com/view/profile/username/someusername
To achieve this I have added this code to my bootstrap file:
protected function _initRoutes() { $this->router = $this->frontController->getRouter(); $route = new Zend_Controller_Router_Route( ':username', array( 'module' => 'default', 'controller' => 'view', 'action' => 'profile' ) ); $this->router->addRoute('profile', $route); }
Now my problems:
1) When I go to www.mydomain.com/someusername I get this error message:
Message: username is not specified Stack trace #0 C:\wamp\www\hunnyhive\library\Zend\Controller\Router\Rewrite.php(441): Zend_Controller_Router_Route->assemble(Array, true, true) #1 C:\wamp\www\hunnyhive\library\Zend\View\Helper\Url.php(49): Zend_Controller_Router_Rewrite->assemble(Array, NULL, true, true) #2 [internal function]: Zend_View_Helper_Url->url(Array, NULL, true) #3 C:\wamp\www\hunnyhive\library\Zend\View\Abstract.php(342): call_user_func_array(Array, Array) #4 [internal function]: Zend_View_Abstract->__call('url', Array) #5 C:\wamp\www\hunnyhive\application\modules\default\views\scripts\view\profile.phtml(17): Zend_View->url(Array, NULL, true) #6 C:\wamp\www\hunnyhive\library\Zend\View.php(108): include('C:\wamp\www\hun...') #7 C:\wamp\www\hunnyhive\library\Zend\View\Abstract.php(833): Zend_View->_run('C:\wamp\www\hun...') #8 C:\wamp\www\hunnyhive\library\Zend\Controller\Action\Helper\ViewRenderer.php(903): Zend_View_Abstract->render('view/profile.ph...') #9 C:\wamp\www\hunnyhive\library\Zend\Controller\Action\Helper\ViewRenderer.php(924): Zend_Controller_Action_Helper_ViewRenderer->renderScript('view/profile.ph...', NULL) #10 C:\wamp\www\hunnyhive\library\Zend\Controller\Action\Helper\ViewRenderer.php(963): Zend_Controller_Action_Helper_ViewRenderer->render() #11 C:\wamp\www\hunnyhive\library\Zend\Controller\Action\HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #12 C:\wamp\www\hunnyhive\library\Zend\Controller\Action.php(523): Zend_Controller_Action_HelperBroker->notifyPostDispatch() #13 C:\wamp\www\hunnyhive\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('profileAction') #14 C:\wamp\www\hunnyhive\library\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #15 C:\wamp\www\hunnyhive\application\Bootstrap.php(100): Zend_Controller_Front->dispatch() #16 C:\wamp\www\hunnyhive\library\Zend\Application.php(335): Bootstrap->run() #17 C:\wamp\www\hunnyhive\public\index.php(33): Zend_Application->run() #18 {main} Request parameters: array(4) { ["username"]=> string(5) "admin" ["module"]=> string(7) "default" ["controller"]=> string(4) "view" ["action"]=> string(7) "profile" }
When I go to www.mydomain.com/view/profile/username/someusername everything works fine though.
2) Second problem is that when I go to URLs such as www.mydomain.com/somecontroller (and somecontroller is and existing controller) I also get a huge error because the URL is matched to the www.mydomain.com/view/profile/username/somecontroller.
How can I solve this problem?
View this message in context: Problem with a simple route
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论