logo

Passing data using Set() from Component to View

logo

I googled this for an hour trying to find the solution, in the end the very helpful people at irc.freenode.net (#cakePHP) helped me out.

I thought that when creating a custom component and extending the Object Class that certain methods were inherited – this isnt the case at all.

In order to use Set to pass stuff to the controller (and then onto the view) you must add the following method to your controller:

function initialize(&$controller, $settings = array()) {
  // saving the controller reference for later use
  $this->controller =& $controller;
}

Then when you want to use set() you simply call it as:

$this->controller->set('name', $name);

Hope this helps :)

You can also return data using the function return to the controller and then set it from there – but the above method is useful if you are returning multiple data to the view.

Share with your friends and help out this site:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogosphere News
  • E-mail this story to a friend!
  • Identi.ca
  • LinkedIn
  • Live
  • MisterWong
  • MySpace
  • Ping.fm
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Tumblr
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
logo
logo
Powered by Nu Order Webs