Welcome Guest, Not a member yet? Register   Sign In
Creating data in constructor
#4

[eluser]Twisted1919[/eluser]
Usually, when using $this->data, you do it when you have a MY_Controller and extend your controllers from it, assuming that in your MY_Controller, you set information in $this->data that will be globally available in other controller that extends it.

If you don't have a MY_Controller, then you can go like
Code:
class Site extends Controller{

   public $last_models;

   public function __construct()
   {
     parent::Controller();
     $this->last_models = $this->ANY_GLOBAL_MODEL->ANY_METHOD_WITHIN_MODEL();
     // now, accessing $this->last_models in each of your class methods will give you the expected result.
   }

   public function home()
   {
        $data = array(
            'title'=>'This is the title',
            'pagina'=>'home'
        );
      // you can do like this :
      $data['last_models'] = $this->last_models;
  
      //or, if you have many properties and you are lazy like i am
      $data = array_merge($data,get_object_vars($this));
      

      // in both cases, if accessing $last_models in the view, will give you the correct result.
   }
}


Messages In This Thread
Creating data in constructor - by El Forum - 12-31-2010, 06:33 AM
Creating data in constructor - by El Forum - 12-31-2010, 07:12 AM
Creating data in constructor - by El Forum - 12-31-2010, 07:22 AM
Creating data in constructor - by El Forum - 12-31-2010, 07:50 AM
Creating data in constructor - by El Forum - 01-01-2011, 03:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB