CakePHP“试图获取非对象的属性”错误 [英] CakePHP "Trying to get property of non-object" error

查看:72
本文介绍了CakePHP“试图获取非对象的属性”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发布表单时它显示错误:

When I post the form it shows error:

Trying to get property of non-object [APP\Controller\UsersController.php, line 647].

此处是ctp文件的形式代码:

Here the ctp file form code:

admin_highlightedstylist.ctp是

admin_highlightedstylist.ctp is

    <?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>

此处为控制器代码脚本UserController.php

Here the controller code script, 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'));


        }

如何删除此错误以及如何删除我可以解决它吗?

How can I remove this error and how can I solve it?

推荐答案

您是否尝试过实际阅读错误消息,您知道这意味着什么吗?

Have you tried to actually read the error message and do you know what it means?

$ this->请求 $ this->请求

这是一个简单的错字。恕我直言,错误消息非常清楚,它告诉您您尝试使用不存在的对象。如果知道的话,很容易调试。

It is a simple typo. The error message is IMHO very clear, it tells you that you try to use an object that doesn't exist. Pretty easy to debug if you know that.

这篇关于CakePHP“试图获取非对象的属性”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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