Hi Richard,
www.mydomain.com/someusername for your user profiles is not a good idea. Because you cannot use your other Controllers. (You cannot be sure that there wont be a same username with your controller names)
You should do somethink like
www.mydomain.com/profile/someusername
protected function _initRoutes()
{
$this->router = $this->frontController->getRouter();
$route = new Zend_Controller_Router_Route(
'profile/:username/*',
array(
'controller' => 'view',
'action' => 'profile'
)
);
$this->router->addRoute('profile', $route);
}
From: Richard Knop [mailto:risoknop@gmail.com]
Sent: Saturday, October 03, 2009 4:31 PM
To: fw-mvc@lists.zend.com
Subject: [fw-mvc] Problem with a simple route
Sent: Saturday, October 03, 2009 4:31 PM
To: fw-mvc@lists.zend.com
Subject: [fw-mvc] Problem with a simple route
Hello everyone,
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:
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);
}
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.
Sent from the Zend MVC mailing list archive at Nabble.com.
________________________________
Bu mesaj ve ekleri, mesajda gönderildiği belirtilen kişi/kişilere özeldir ve gizlidir. Size yanlışlıkla ulaşmışsa lütfen gönderen kisiyi bilgilendiriniz ve mesajı sisteminizden siliniz. Mesaj ve eklerinin içeriği ile ilgili olarak şirketimizin herhangi bir hukuki sorumluluğu bulunmamaktadır. Şirketimiz mesajın ve bilgilerinin size değişikliğe uğrayarak veya geç ulaşmasından, bütünlüğünün ve gizliliğinin korunamamasından, virüs içermesinden ve bilgisayar sisteminize verebileceği herhangi bir zarardan sorumlu tutulamaz.
This message and attachments are confidential and intended for the individual(s) stated in this message. If you received this message in error, please immediately notify the sender and delete it from your system. Our company has no legal responsibility for the contents of the message and its attachments. Our company shall have no liability for any changes or late receiving, loss of integrity and confidentiality, viruses and any damages caused in anyway to your computer system.
This message and attachments are confidential and intended for the individual(s) stated in this message. If you received this message in error, please immediately notify the sender and delete it from your system. Our company has no legal responsibility for the contents of the message and its attachments. Our company shall have no liability for any changes or late receiving, loss of integrity and confidentiality, viruses and any damages caused in anyway to your computer system.
没有评论:
发表评论