Cakephp component $ this-> controller-> modelClass

In the component I'm trying to access Myprofile Model

class SignMeupComponent extends Object public function register() { $this->__isLoggedIn(); if (!empty($this->controller->data)) { extract($this->settings); $model = $this->controller->modelClass; $this->controller->loadModel($model); $this->controller->{$model}->Myprofile->save($this->controller->data); $this->controller->data['Myprofile']['user_id'] = $this->controller->{$model}->id; $this->controller->{$model}->set($this->controller->data); if ($this->controller->{$model}->validates()) { 
  • how to use $ this-> controller-> classclass
  • how to use any model in a component

thank for any suggestion

+4
source share
1 answer

$this->controller not defined by default. You must save the reference to the controller manually, for example, in the initialize() method of your component:

 public function initialize(&$controller, $settings = array()) { $this->controller = $controller; } 

Then you must have access to the properties and methods of the controller.

+14
source

All Articles