cakephp component $this->controller->modelClass

强颜欢笑 提交于 2020-01-14 10:37:08

问题


In Component I try 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()) {
  1. how to use $this->controller->modelclass
  2. how to use any model in component

thank for any suggest


回答1:


$this->controller is not defined by default. You have to save a 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 should be able to access the controller's properties and methods.



来源:https://stackoverflow.com/questions/5983633/cakephp-component-this-controller-modelclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!