How to add an auxiliary or on-the-fly component using the controller action method

I do not want to add it as below, because I needed them only once in a certain method of action

(so it's not useless to load memory)


class UsersController extends AppController {
    var $name = 'Users';
    var $helpers = array('Html', 'Session');
    var $components = array('Session', 'Email');
+3
source share
3 answers
class UsersController extends AppController {
  public function method_name() {
    $this->helpers[] = 'MyHelper'
  }
}

Read more about this in the documentation .

Hope this helps.

+7
source

You can download helpers using

$this->helpers[] = 'MyHelper';

as mentioned above in Rob, but this will not work for controllers, because they have their own initialization and startup methods that must be called for their operation.

: ComponentLoaderComponent

, , , .

, , , , , .

0

:

$this->Common->addHelper('Tools.Datetime');
$this->Common->addHelper(array('Text', 'Number', ...));
$this->Common->addComponent('RequestHandler');
$this->Common->addLib(array('MarkupLib'=>array('type'=>'php'), ...));

..

, : http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/1277

php: http://www.dereuromark.de/2010/11/10/loading-classes-on-the-fly/

, mtnorthrop. , . .

0

Source: https://habr.com/ru/post/1773654/


All Articles