joostvanveen / build-a-cms-with-codeigniter

Source code for the Tutsplus course 'Build a CMS with Codeigniter'
53 stars 55 forks source link

Adding A page #5

Closed rsa408 closed 10 years ago

rsa408 commented 10 years ago

Hi Friend; thanks for your great teaching. I got this error when i finished course 12

A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$parent_id Filename: page/edit.php Line Number: 7

page\edit line 7:

input->post('parent_id') ? $this->input->post('parent_id') : $page->parent_id); ?>

i had to say i got a copy of your git and checked with what i have write from your courses. could you possibly help me to solve this?

joostvanveen commented 10 years ago

Hi buddy,

The error you are getting implies that you did not set $page correctly. You can check its value by doing <?php dump($page); ?> from the view file.

The problem is likely in controller admin/page.php of in models/page_m.php Please check your code against the source copde for those files.

If the error is in the controller, $this->data['page'] is probably not set correctly at line 44-51

// Fetch a page or set a new one
if ($id) {
    $this->data['page'] = $this->page_m->get($id);
    count($this->data['page']) || $this->data['errors'][] = 'page could not be found';
}
else {
    $this->data['page'] = $this->page_m->get_new();
}

If the error is in the model then you porbbaly got an error on line 34-43, in setting and returning a new page object

public function get_new ()
{
    $page = new stdClass();
    $page->title = '';
    $page->slug = '';
    $page->body = '';
    $page->parent_id = 0;
    $page->template = 'page';
    return $page;
}   
rsa408 commented 10 years ago

Dear friend you are a hero for me in codeigniter i ve learn it by your teaching.

The problem was in model " $page->parent_id = 0; " my model has not contain this row at all.

Best regards.

joostvanveen commented 10 years ago

Glad I could help :)