• 8th July 2009 - By admin

    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:
    • Digg
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • E-mail this story to a friend!
    • LinkedIn
    • Live
    • Reddit
    • StumbleUpon
    • Twitter
    • Yahoo! Bookmarks

Ad