gpt4 book ai didi

cakephp 组件 $this->controller->modelClass

转载 作者:行者123 更新时间:2023-12-04 22:07:48 26 4
gpt4 key购买 nike

在组件中,我尝试访问 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()) {
  • 如何使用 $this->controller->modelclass
  • 如何在组件中使用任何模型

  • 感谢您的任何建议

    最佳答案

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

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

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

    关于cakephp 组件 $this->controller->modelClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5983633/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com