Hassan
Hassan

Reputation: 313

getting an error Undefined property: stdClass::$id

I've issue with my CMS whenever I tried to Add new page with the following line of code

<?php echo form_open_multipart('admin/page/edit/'. $page->id); ?>

it gives me error A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$id

Filename: page/edit.php

Line Number: 5

my edit function is this which perform add & update functionality

public function edit($id = NULL) {
        //Fetch a page or set 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();
        }
        $id == NULL || $this->data['page'] = $this->page_m->get($id);
        //Pages for dropdown
        $this->data['pages_no_parents'] = $this->page_m->get_no_parents();
        //dump($this->data['pages_no_parents']);
        //Setup form
        $rules = $this->page_m->rules;

        $this->form_validation->set_rules($rules);
        //Process the form
        if ($this->form_validation->run() == TRUE) {

            $data = $this->page_m->array_from_post(array(
                'title',
                'slug',
                'order',
                'body',
                'template',
                'parent_id',
                'filename'
            ));

            /*             * ***********WORKING FOR IMAGE UPLOAD AND SAVE PATH TO DATABASE*************** */
            if (!empty($_FILES['filename'])) {
                $fdata = $this->do_upload('filename');           /// you are passing the parameter here
                $data['filename'] = base_url() . 'uploads/' . $fdata;
            }
            $this->page_m->save($data, $id);
           // echo '<pre>' . $this->db->last_query() . '</pre>';
            redirect('admin/page');
        }
        //Load the view    
        $this->data['subview'] = 'admin/page/edit';
        $this->load->view('admin/_layout_main', $this->data);
    }
    public function do_upload($field_name) {                        // but not retriveing here do this
        $field_name = 'filename';
        $config = array(
            'allowed_types' => '*',
            'max_size' => '1024',
            'max_width' => '1024',
            'max_height' => '768',
            'upload_path' => './uploads/'
        );
        $this->load->library('upload');
        $this->upload->initialize($config);

        if (!$this->upload->do_upload($field_name)) {
            echo $this->upload->display_errors();
            die();
            $this->data['error'] = array('error' => $this->upload->display_errors());
            //$this->data['subview'] = 'admin/page/edit';
            //$this->load->view('admin/_layout_main', $this->data);
        } else {
            $fInfo = $this->upload->data();
            //return $fInfo['file_path'].$fInfo['file_name'];
            //     $this->filename = $fInfo;
            return $fInfo['file_name'];
        }
    }

Upvotes: 0

Views: 1819

Answers (1)

Rwd
Rwd

Reputation: 35180

<?php echo form_open_multipart('admin/page/edit/'. ((isset($page->id)) ? $page->id : '')); ?>

As I mentioned in my comment, if you are creating a new record (I assume:) your page object will not have an id yet, so you just have to do a quick check to make sure it exists and if not output an empty string.

Upvotes: 1

Related Questions