cakephp组件$this->controller->modelClass
在组件中,我尝试访问 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
- 如何在组件中使用任何模型
感谢任何建议
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()) {
- how to use $this->controller->modelclass
- how to use any model in component
thank for any suggest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下未定义
$this->controller
。您必须手动保存对控制器的引用,例如在组件的initialize()
方法中:然后您应该能够访问控制器的属性和方法。
$this->controller
is not defined by default. You have to save a reference to the controller manually, for example in theinitialize()
method of your component:Then you should be able to access the controller's properties and methods.