Welcome Guest, Not a member yet? Register   Sign In
Model linking issue
#1

[eluser]epseix[/eluser]
Hi everyone,

I'm beginning my journey with Codeigniter and following user guide. The model section has confused me greatly.

I have following controller about.php:
Code:
<?php
class About extends CI_Controller{

    function About(){
        parent::Controller;
    }

    function index(){
$this->load->model('About_model');
$data['query'] = $this->About_model->about_get();
$this->load->view('about_view', $data);
    }
}
?>

View about_view.php:
Code:
<html>
<head>
<title></title>
</head>
<body>
<?php
foreach($query as $row){
print $row->intId;
print $row->strId;
}
?>
</body>
</html>

And Model about_model.php:
Code:
<?php
class About_model extends CI_Model{

    function About_model(){
        parent::Model;
    }

    function about_get(){
        $this->load->database();
        $query = $this->db->get('myDb');
        return $query->result();
    }
}
?>

Just trying to get a basic linkup established, and experiment from there... But it's not working!

Can anybody steer me in the right direction?

Thanks!
#2

[eluser]TheFuzzy0ne[/eluser]
You first problem is that you are calling parent::Controller, but in the context of a property, not a method. i.e. parent::Controller and not parent::Controller(). Your second problem will be that parent::Controller() does not exist. That should be parent::CI_Controller().

What version of PHP are you using? Since PHP5, the __construct() method is supported.

So first, change:
Code:
function About(){
    parent::Controller;
}

to:
Code:
function __construct() {
    parent::__construct();
}

That should fix your problem. Alternatively, since you don't have anything else in your constructor, you can simply omit it completely, and the parent constructor will automatically be invoked.

Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB