cakephp组件$this->controller->modelClass

发布于 2024-11-06 20:44:34 字数 802 浏览 1 评论 0原文

在组件中,我尝试访问 Myprofile 模型

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. 如何使用 $this->controller->modelclass
  2. 如何在组件中使用任何模型

感谢任何建议

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-11-13 20:44:34

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

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

然后您应该能够访问控制器的属性和方法。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文