dependency injection - Laravel 4: how to inject another class in a eloquent model -


i'm trying use built-in laravel's ioc container inject pagemanager class inside page model , i'm little lost.

what i'm trying achieve that:

class pages extends eloquent {      public function __construct(pagesmanagerinterface $manager, array $attributes = array())      {         parent::__construct($attributes);         $this->manager = new $manager;     }      public function savetodisk()     {          $this->manager->writetofile();     } 

but obtain error:

errorexception: argument 1 passed pages::__construct() must instance of pagesmanagerinterface, none given.

i tried add in app/start/global.php:

app::bind('pages',function(){      return new pages(new pagesmanager); }); 

but seems ignored framework, , don't know how insert $attribute array declaration.

i'm little lost appreciated!

i think need is:

app::bind('pagesmanagerinterface',function(){      return new pages(new pagesmanager);  }); 

this tells laravel inject new page object everytime needs instance of pagesmanagerinterface wich wasn't passed while creating model.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -