How to load a component in console/shell

后端 未结 5 1665
耶瑟儿~
耶瑟儿~ 2020-12-20 17:22

In CakePHP, how do I load a component in a shell?

To use a component in a controller, you include an array of components in a property called $components. That doesn

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 18:10

    //TestShell.php

    class TestShell extends AppShell{
    
        public function test(){
            //to load a component in dis function
         App::import('Component', 'CsvImporter');
         $CsvImporter = new CsvImporterComponent();
         $data = $CsvImporter->get();
        }
    
    }
    

    //CsvImporterComponent.php

    App::uses('Component', 'Controller');
    
    class CsvImporterComponent extends Component {
    
        function get(){
        //your code
        }
    
    }
    

提交回复
热议问题