how can i set one controller to render actions from another controller in cakephp 1.2
hello, i'm new to cakephp. in my app there's controller named sections which renders pages and there're multiple controllers for special actions (e.g. photos, shop, etc). what i'm trying to do is to create whole pages structure with sections controller and set some pages to be rendered by other controllers in backend. i found out that renderAction will do this task e.g. $this-set('pish', $this-requestAction(array('controller' = 'photo', 'action' = 'index'), array('return'))); is it ok to use renderAction or there's better way to do it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how can i set one controller to render actions from another controller in cakephp 1.2
and then again, how can i pass some parameters via url. e.g. i have url like http://127.0.0.2/sections/view/14/autocard-3 this means that i call some controller with method autocard to get record with id = 3. if ($ctrlr != 'sections') { (isset($action)) ? $action : $action = 'index'; $cAct = explode('-', $action); $this-set('pish', $this-requestAction(array('controller' = $ctrlr, 'action' = $cAct[0]), array('return'))); } this will work but wil not do what i need. but if i change $this-set('pish', $this-requestAction(array('controller' = $ctrlr, 'action' = $cAct[0]), array('return'))); to $this-set('pish', $this-requestAction(array('controller' = $ctrlr, 'action' = $cAct[0]($cAct[1])), array('return'))); cakephp ends up with error Fatal error: Call to undefined function autocard() in /var/www/hotcake/app/controllers/sections_controller.php on line 55 On 28 окт, 12:37, johnbl4ck [EMAIL PROTECTED] wrote: hello, i'm new to cakephp. in my app there's controller named sections which renders pages and there're multiple controllers for special actions (e.g. photos, shop, etc). what i'm trying to do is to create whole pages structure with sections controller and set some pages to be rendered by other controllers in backend. i found out that renderAction will do this task e.g. $this-set('pish', $this-requestAction(array('controller' = 'photo', 'action' = 'index'), array('return'))); is it ok to use renderAction or there's better way to do it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how can i set one controller to render actions from another controller in cakephp 1.2
I am not absolutely sure, but I think you will get a little better performance (and structure) from calling requestAction in your view in this case. That is, you create elements to do the rendering and use requestAction to get the data to the element. Not to render anything. If your application warrants it, you may also be better off loading up the needed Models directly in the current controller. This would cut out requestAction. This would be a good option if your controller or action is for a portal-style page that shows bits from different parts of the application. /Martin On Oct 28, 9:12 am, johnbl4ck [EMAIL PROTECTED] wrote: and then again, how can i pass some parameters via url. e.g. i have url likehttp://127.0.0.2/sections/view/14/autocard-3 this means that i call some controller with method autocard to get record with id = 3. if ($ctrlr != 'sections') { (isset($action)) ? $action : $action = 'index'; $cAct = explode('-', $action); $this-set('pish', $this-requestAction(array('controller' = $ctrlr, 'action' = $cAct[0]), array('return'))); } this will work but wil not do what i need. but if i change $this-set('pish', $this-requestAction(array('controller' = $ctrlr, 'action' = $cAct[0]), array('return'))); to $this-set('pish', $this-requestAction(array('controller' = $ctrlr, 'action' = $cAct[0]($cAct[1])), array('return'))); cakephp ends up with error Fatal error: Call to undefined function autocard() in /var/www/hotcake/app/controllers/sections_controller.php on line 55 On 28 окт, 12:37, johnbl4ck [EMAIL PROTECTED] wrote: hello, i'm new to cakephp. in my app there's controller named sections which renders pages and there're multiple controllers for special actions (e.g. photos, shop, etc). what i'm trying to do is to create whole pages structure with sections controller and set some pages to be rendered by other controllers in backend. i found out that renderAction will do this task e.g. $this-set('pish', $this-requestAction(array('controller' = 'photo', 'action' = 'index'), array('return'))); is it ok to use renderAction or there's better way to do it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how can i set one controller to render actions from another controller in cakephp 1.2
Passing parameters via URL: /controller_name/action_name/parameter_1/parameter_2/ parameter_n Parameters are added with slashes into the URL after the action name, so if you have an action autocard in your controller: (let's assume it is called PostsController) function autocard ($param1, $param2) { echo $param1; echo $param2; } Now you can call this function with the URL /posts/autocard/hello/ world and it would print you in the view: hello world --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how can i set one controller to render actions from another controller in cakephp 1.2
yes i got that. but http://127.0.0.2/sections/view/14/autocard/4 actually calls sections controller with method view and param 14, autocard is method of cars controller and it's param should be 4 but i can't get how to handle this via requestAction On 28 окт, 14:09, zwobot [EMAIL PROTECTED] wrote: Passing parameters via URL: /controller_name/action_name/parameter_1/parameter_2/ parameter_n Parameters are added with slashes into the URL after the action name, so if you have an action autocard in your controller: (let's assume it is called PostsController) function autocard ($param1, $param2) { echo $param1; echo $param2; } Now you can call this function with the URL /posts/autocard/hello/ world and it would print you in the view: hello world --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: how can i set one controller to render actions from another controller in cakephp 1.2
Are you sure this functionality shouldn't be in the model? requestAction() is expensive and slow. I'm not really sure what your action is doing, but consider this approach instead: $this-set('pish', $this-CurrentModel-RelatedModel- getSomeData($withSomeParams)); or if the models are really not related, you can load the other model: $OtherModel = ClassRegistry::init('OtherModelName'); $this-set('pish', $OtherModel-getSomeData($withSomeParams)); Either way, really it comes down to fat models and skinny controllers and proper place to keep the logic. On Oct 28, 4:23 am, johnbl4ck [EMAIL PROTECTED] wrote: yes i got that. buthttp://127.0.0.2/sections/view/14/autocard/4 actually calls sections controller with method view and param 14, autocard is method of cars controller and it's param should be 4 but i can't get how to handle this via requestAction On 28 окт, 14:09, zwobot [EMAIL PROTECTED] wrote: Passing parameters via URL: /controller_name/action_name/parameter_1/parameter_2/ parameter_n Parameters are added with slashes into the URL after the action name, so if you have an action autocard in your controller: (let's assume it is called PostsController) function autocard ($param1, $param2) { echo $param1; echo $param2; } Now you can call this function with the URL /posts/autocard/hello/ world and it would print you in the view: hello world --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---