Load a controller into an other controller in cakephp?

I think there're some misunderstandings in your mind about MVC architectural pattern If you need some bullet for your gun,just get the bullet itself,and it's not neccessary to get another gun with it. So I hope you understand loading controller is really a bad idea Also if you want some variables accessable by all controllers,as Gaurav Sharma mentioned ,you can use Configure::write() to store data in the application’s configuration app/config/core. Php e.

G Configure::write('somekey',$someval) Then you can get $someval by Configure::read('somekey') in any controller.

I think there're some misunderstandings in your mind about MVC architectural pattern. If you need some bullet for your gun,just get the bullet itself,and it's not neccessary to get another gun with it. So I hope you understand loading controller is really a bad idea.

Also if you want some variables accessable by all controllers,as Gaurav Sharma mentioned ,you can use Configure::write() to store data in the application’s configuration app/config/core.php.e. G Configure::write('somekey',$someval); Then you can get $someval by Configure::read('somekey') in any controller.

I've been working on this this morning. I actually get the controller name from a database, but I've changed it to use variables instead. $controller_name = "Posts"; // the name of the controller.

$action = "index"; // The action we want to call. App::import('Controller', $controller_name); // Now we need the actual class name of the controller. $controller_classname = $controller_name .'Controller'; $Controller = new $controller_name; $Controller->variable_name = "something"; // we can set class variables here too.

// Now invoke the dispatcher so that it will load and initialize everything (like components) $d = new Dispatcher(); $d->_invoke($Controller, array('pass'=> '', 'action' => $action)); // And exit so it doesn't keep going. Exit(0); I honestly didn't bother figuring out what 'pass' is for (I assume variables), but it throws a warning without it. You will also need to explicitly call $this->render in your $action.

1 pass is half of the passedArgs variable in the Controller. If you use Dispatcher::dispatch() rather than _invoke, it will set these for you, in addition to doing other potentially useful things (but also potentially unnecessary for your purposes). – rintaun Sep 22 at 14:33.

You can use any one of the methods below to access a variable anywhere in the cakePHP application. 1. ) use the configuration class OR 2.) use session for those variables.

Sorry, but I that doesn't seem to work aswell.. – john May 19 '10 at 9:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions