开发者

cakephp component $this->controller->modelClass

开发者 https://www.devze.com 2023-03-06 00:47 出处:网络
In Component I try to access Myprofile Model class SignMeupComponent extends Object public function register() {

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->{开发者_Python百科$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


$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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号