user3864045
user3864045

Reputation: 17

CakePHP "Trying to get property of non-object" error

When I post the form it shows error:

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

Here the ctp file form code:

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>

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?

Upvotes: 2

Views: 4101

Answers (1)

floriank
floriank

Reputation: 25698

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

$this->requert vs $this->request

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.

Upvotes: 2

Related Questions