Welcome Guest, Not a member yet? Register   Sign In
Edit Page Issue
#1

[eluser]jzmwebdevelopement[/eluser]
Hello,

I am getting the following error when I try and access:

domain.co.nz/admin/editpage/home

I get the following error:

Code:
PHP Fatal error:  Call to a member function getCMSPage() on a non-object in controllers/home.php on line 22



The issue with this is that I cannot understand why it is being passed back into the main "home" controller - which is the main controller

Ideal Situation

What I am trying to do with this is load the content into a text area on for editing and when submit is clicked I would like it to go back to the same page with a message saying content updated.

Admin Template

Code:
<li>&lt;?php echo anchor('#','Edit Pages');?&gt;
            &lt;?php if(is_array($cms_pages)): ?&gt;
                    <ul>
                        &lt;?php foreach($cms_pages as $page): ?&gt;
                        <li><a >permalink?&gt;">&lt;?=$page->name?&gt;</a></li>
                        &lt;?php endforeach; ?&gt;
                    </ul>
                &lt;?php endif; ?&gt;
                </li>

Page Model

Code:
function updatePage($data){
        $data = array('content' => $content);
        $this ->db->where('id',$id);
        $this->db->update('pages',$data);
    }

View:

Code:
&lt;?php
//Setting form attributes
$formpageEdit = array('id' => 'pageEdit', 'name' => 'pageEdit');
$formInputTitle = array('id' => 'title', 'name' => 'title');
$formTextareaContent = array('id' => 'content', 'name' => 'content');
?&gt;

<section id = "validation">&lt;?php echo validation_errors();?&gt;</section>

<h4>&lt;?= $title ?&gt; </h4>
&lt;?php
echo form_open('admin/editpage/'.$page->permalink, $formpageEdit);
echo form_fieldset();
echo form_label ('Content', 'content');
echo form_textarea("content", $page['content']);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?&gt;

Controller:

Code:
function index(){
        if($this->session->userdata('logged_in')){
        
        }else{
            redirect('admin/home');
        }
       $page = $this->navigation_model->getCMSPage($this->uri->segment(3));
        $data['cms_pages'] = $this->navigation_model->getCMSPages();
        $data['title'] = $page->name;
        $data['content'] = $this->load->view('admin/editpage', array('page' => $page, TRUE));

        $this->load->view('admintemplate', $data);
    
    }
#2

[eluser]toopay[/eluser]
load the model first!
Code:
$this->load->model('navigation_model');
#3

[eluser]jzmwebdevelopement[/eluser]
[quote author="toopay" date="1303194919"]load the model first!
Code:
$this->load->model('navigation_model');
[/quote]

It is already auto loaded http://cl.ly/2U1F3a2B0s2K0i3k3g13
#4

[eluser]toopay[/eluser]
Post your models here!
#5

[eluser]jzmwebdevelopement[/eluser]
Here is my navigation_model:

It works fine on other pages just not this one.

Code:
class Navigation_model extends CI_Model {
    // the __construct() is the same as running Navigation_model();
    function __construct() {
        parent::__construct();
    }
    
    // nget ALL pages
    
    function getCMSPages() {
        
        $query = $this->db->get('pages');
        if($query->num_rows() > 0) return $query->result();
    
    }
    
    function getCMSPage($permalink = NULL) {
        
        if(!$permalink) $permalink = 'home'; //Default Page
        $this->db->where('permalink', $permalink);
        $query = $this->db->get('pages', 1);
        if($query->num_rows() == 1) return $query->row();
        
    }
    
}
#6

[eluser]toopay[/eluser]
and your controller...
#7

[eluser]jzmwebdevelopement[/eluser]
Navigation Controller

Code:
class Navigation extends CI_Controller {

    function __construct() {
        parent::__construct();

    }
    
    function index() {
        if(!$this->session->userdata('logged_in')) {
            redirect('admin/home');
        }
        // set data
        $data['sales_pages'] = $data->navigation_model->getSalesPages();
        $data['cms_pages'] = $data->navigation_model->getCMSPages();
        
        // load partial view - EAMPLE
        // view path,  data to pass in ( NULL, array or object ), TRUE returns as a varialble, else echo's.
        $data['content'] = $this->load->view('admin/content', NULL, TRUE);
        // THEN load view.
        $this->load->view('admintemplate', $data);
      
    }
#8

[eluser]toopay[/eluser]
just to make sure, lets disable autoload, and load the model manually right before you call it's function.
#9

[eluser]jzmwebdevelopement[/eluser]
Still no luck
#10

[eluser]toopay[/eluser]
[quote author="jzmwebdevelopement" date="1303191727"]
I get the following error:

Code:
PHP Fatal error:  Call to a member function getCMSPage() on a non-object in controllers/home.php on line 22
[/quote]

i've just noticed, the error is in your home controller! Post it here.




Theme © iAndrew 2016 - Forum software by © MyBB