The problem is here:
[PHP]
$router = $frontController->getRouter();
$router = new Zend_Controller_Router_Route(...);
[/PHP]
You're overwriting the $router variable in the second line. Simply change it to $route, and you should be fine.
I am trying to set up the router (Zend_Controller_Router_Route) in my application's bootstrap file. Its so strange that, my IDE (PHPeD) doesnt show addRoute as a method of router. When I run, my application, I get following error:
Fatal error: Cannot use object of type Zend_Controller_Router_Route as array in E:\Softwares\Apache2.2.6\htdocs\ZendProj\library\Z end\Controller\Router\Route.php on line 247
This is how I am trying to setup the router for my application.
Code:$router = $frontController->getRouter(); $router = new Zend_Controller_Router_Route('signup/:uid/*',array('module'=>'signup', 'controller'=>'signup', 'id' =>null), array('id'=>'(.*)')); $router->addRoute('signup',$route);
I am using ZendFramework-1.6.1
Is there anything I am missing?
Can anyone pls help me into this?
Thanks a lot
regards
Jameel
The problem is here:
[PHP]
$router = $frontController->getRouter();
$router = new Zend_Controller_Router_Route(...);
[/PHP]
You're overwriting the $router variable in the second line. Simply change it to $route, and you should be fine.
Thanks Matthew, for pointing that out to me :-)
basically I am trying to generate URL like /controllername/actionname/parameter1/value1/parameter2/value2
While I have been able to configure the router in my Bootstrap file as follws :
and from my controller's action method (SignupController.php->indexAction), I am trying to generate URL as follows :Code:——————————————————————– $router = $frontController->getRouter(); $route = new Zend_Controller_Router_Route(’signup/:uid/*’,array(’module’=>’signup’, ‘controller’=>’signup’, ‘id’ =>null), array(’id’=>’(.*)’)); $router->addRoute(’signup’,$route ); ——————————————————————–
When I run my application I am getting following error :Code:$URL = $this->url(array( ‘controller’ => ‘user’, ‘action’ => ‘edit’, ‘id’ => ‘123′ ));
exception ‘Zend_Controller_Action_Exception’ with message ‘Method “url” does not exist and was not trapped in __call()’ in E:SoftwaresApache2.2.6htdocszendProjlibraryZendCon trollerAction.php:481 Stack trace: #0 [internal function]: Zend_Controller_Action->__call(’url’, Array) #1 E:SoftwaresApache2.2.6htdocszendProjapplicationcon trollersSignupController.php(59): SignupController->url(Array) #2 E:SoftwaresApache2.2.6htdocszendProjlibraryZendCon trollerAction.php(502): SignupController->indexAction() #3 E:SoftwaresApache2.2.6htdocszendProjlibraryZendCon trollerDispatcherStandard.php(293): Zend_Controller_Action->dispatch(’indexAction’) #4 E:SoftwaresApache2.2.6htdocszendProjlibraryZendCon trollerFront.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5 E:SoftwaresApache2.2.6htdocszendProjpublicindex.ph p(92): Zend_Controller_Front->dispatch() #6 {main}
I am following Naneau Use the URL view helper, please
Thanks
Jameel
The exception you are getting is due to the fact that your controller cannot access the view helper - thus the error. (__call() is PHP magic function invoked when the class does not have the function you tried to call).
View Helpers are supposed to be called from within the view (that is, view scripts at the default ZF layout). Move your $this->url($options_array, $routename) there and you get rid of the exception.
Another issue with your code is that you do not pass the route name to the url helper:
Code:$router->addRoute(’signup’,$route ); ——————————————————————–Change that to include the route you want to use and it should work out fine.Code:$URL = $this->url(array( ‘controller’ => ‘user’, ‘action’ => ‘edit’, ‘id’ => ‘123′ ));
Code:$this->url($options_array, 'signup');
Well, may be I have not been able to explain my problem properly.
I am trying to save some data (basically registration data) to the database. Once that is successfully saved into the db, I am trying to forward the user to the new action as follows :
Now this works perfectly fine. Apart from this what I also want is, to pass on unique profile Id of the user which was generated above.Code:/** Generate unique profile Id and save it to DB along with user's registration details. * Once data is properly saved in to the db, forward the user's * control to register1 Action (defined in the same controller) */ $this->_forward('register1');
Reason I want to pass this unique profile Id from one action to another is that, I have to use this unique profile Id into the 2nd action (register1)
Also as you have mentioned that, viewhelpers are something which I can use it only from the views (i.e phtmls). What does Zend has to offer for the above requirement (i.e if I have to pass the values to other actions[in the same controller] as a URL as a parameter, how can I do that?)
Any pointers or link to the web-resource will be of great help. I have been struggling into this since 3-4 days
Thanks for your time and support
Regards
Jameel