Use a component inside a Shell Console in CakePHP

2

Does anyone know how to use a component that I created in cakephp within a cake console script?

I've tried using App :: import but I could not.

For example in a normal controller I can use my component as follows:

public $components = array('MeuComponent');

But in Shell this does not work = /

Does anyone know how to use MyComponent inside a CakePHP Shell?

    
asked by anonymous 25.04.2014 / 21:15

1 answer

2

I just found the solution < strong> here

Before your class Shell add

App::uses('ComponentCollection', 'Controller');
App::uses('MeuComponentComponent', 'Controller/Component');

class WorkerShell extends AppShell {
    public function main(){
       $Collection = new ComponentCollection();
       $obj = new MeuComponentComponent($Collection);
    }
}  

You can now use your component within Shell scripts.

    
25.04.2014 / 21:24