cakephp component $ this-> controller-> modelClass [英] cakephp component $this->controller->modelClass

查看:89
本文介绍了cakephp component $ this-> controller-> modelClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在组件I中尝试访问Myprofile模型

 类SignMeupComponent extends Object 
public function register b $ b $ 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()){


b $ b


  1. 如何使用$ this-> controller-> modelclass

  2. 如何使用组件中的任何模型

感谢任何建议

解决方案

$ this-> controller 默认情况下没有定义。您必须手动保存对控制器的引用,例如在您的组件的 initialize()方法中:

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

那么你应该能够访问控制器的属性和方法。 >

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

解决方案

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

这篇关于cakephp component $ this-> controller-> modelClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆