Welcome Guest, Not a member yet? Register   Sign In
update dynamically CRUD
#3

[eluser]Syllean[/eluser]
You're trying to define 2 methods in your model called getPost() that differ only in the fact that one requires a parameter $id and the other does not accept any parameters. This is called method overloading, and it's not possible in PHP.

You have a couple of options:

1) Change the name of one of your functions, maybe change the first getPost() to getPosts(). If you change the name in your model make sure to change it in your controller too.
2) Combine your functions into one using a default value for $id, in something like:

Code:
function getPost($id = null)
{
    if(!$id)
    {
        $query = $this->db->get('posts');
        $posts = array();

        foreach ($query->result() as $row) {
            $posts[] = array(
                'id' => $row->id,
                'title' => $row->title,
                'content' => $row->content
             );
        }
        return $posts;
    }
    else
    {
        $this->db->select('title', 'content');
        $this->db->from('posts');
        $this->db->where('id', $id);
        $q = $this->db->get();
        $data = array();
  
        if ($q->num_rows() > 0)
        {
            foreach($q->result() as $row)
            {
                $data[] = $row;
            }
        }
        return $data;
    }
}


Messages In This Thread
update dynamically CRUD - by El Forum - 06-25-2012, 04:39 AM
update dynamically CRUD - by El Forum - 06-25-2012, 10:27 AM
update dynamically CRUD - by El Forum - 06-25-2012, 10:30 AM
update dynamically CRUD - by El Forum - 06-25-2012, 11:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB