当我发布表单时,它显示错误:
Trying to get property of non-object [APP\Controller\UsersController.php, line 647].
这里是ctp文件表单代码:
admin_highlightedstylist.ctp 是
<?php echo $this->Form->create('Userhighlighted'); ?>
<tr>
<th>STYLIST LIST</th>
<th><?php echo $this->Form->input('stylist_id', array('empty' => 'Select Stylist')); ?></th>
<th>
<div class="submit">
<?php echo $this->Form->end('ADD HIGHLIGHTED'); ?>
</div>
</th>
</tr>
这里是 Controller 代码脚本,UserController.php
public function admin_highlightedstylist(){
$this->layout = 'admin';
$this->isAdmin();
if($this->request->is('post')){
print_r($this->requert->data['Userhighlighted']['stylist_id']);
exit;
}
$stylists = $this->User->find('list', array('conditions'=>array('is_stylist' => true,)));
$this->set(compact('id', 'stylists'));
}
如何消除此错误以及如何解决它?
最佳答案
您是否尝试过实际阅读错误消息并且知道它的含义吗?
$this->requert
与 $this->request
这是一个简单的错字。恕我直言,错误消息非常清楚,它告诉您尝试使用不存在的对象。如果您知道这一点,那么调试起来就很容易了。
关于php - CakePHP "Trying to get property of non-object"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25133913/