Using a Component inside a Shell Console in Cakephp

Asked

Viewed 65 times

2

Can anyone tell me how to use a Component I created in cakephp within a cake console script?

I tried using App::import but could not.

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

public $components = array('MeuComponent');

But in Shell it doesn’t work =/

Can anyone tell me how to use Meucomponent inside a Cakephp Shell?

1 answer

2

I found the solution 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);
    }
}  

Ready, you can already use your Component inside the Shell scripts.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.