Welcome Guest, Not a member yet? Register   Sign In
MY_Model Base CRUD Model
#21

[eluser]megabyte[/eluser]
I think there is another issue now.

But of course it could be related to my code, lol.

So no MY_Model error anymore, but in my view when I'm using the table class which I have autoloaded and works in other views. I get this error

Code:
Fatal error: Call to a member function set_template() on a non-object

Could the changes you made to MY_Model have affected this?
#22

[eluser]Jamie Rumbelow[/eluser]
Nope, definitely your code!
#23

[eluser]megabyte[/eluser]
I was so hoping you weren't going to say that. lol.


Don't get me wrong, I think you're a genius, and wish I knew at 15 what you do, although PHP wasn't around to my knowledge in 1988.
#24

[eluser]Jamie Rumbelow[/eluser]
Hehe, thanks Smile and sorry I can't help - it must be an issue with using the wrong variable - check that you're accessing the right var in your view.
#25

[eluser]megabyte[/eluser]
I'm trying to debug. I use the same in every view.

Code:
$tmpl = array ( 'table_open' => '<table cellspacing="0" class="tablesorter">',
                'row_alt_start' => '<tr class="odd">'
              );

$this->table->set_template($tmpl);
#26

[eluser]megabyte[/eluser]
Here's another question for you though.


In the user manual they say best practice is this:

Code:
if ($query->num_rows() > 0)
{
    foreach($query->result() as $row)
    {    
        
    }
}


But if I use your model, then what I get back from this function is a result:


Code:
public function get_all() {
        return $this->db->get($this->table)
            ->result();
    }

And I can't use $query->num->rows
#27

[eluser]megabyte[/eluser]
OK, I found the issue, and yes its to do with you. Tongue

Hopefully you have a sense of humor (which I believe you do), as I am in no way being negative.

It's actually something I ran into along time ago.


In your MY_Model, you are using

Code:
$this->table

Which is allowed to be changed in the model I extend from MY_Model. So when I do so, it kills $this->table that is created from the table class.

I'd probably suggest changing $this->table to $this->tbl or $this->_table
#28

[eluser]megabyte[/eluser]
Maybe an obvious question, but when extending MY_Model you can't keep the same naming structure can you?

For example if I extend MY_Model and I create a function called insert() it will overwrite the MY_Model insert.

Correct?

If this is the case, is there a way to fix this?
#29

[eluser]Phil Sturgeon[/eluser]
[quote author="megabyte" date="1263785475"]Maybe an obvious question, but when extending MY_Model you can't keep the same naming structure can you?

For example if I extend MY_Model and I create a function called insert() it will overwrite the MY_Model insert.

Correct?

If this is the case, is there a way to fix this?[/quote]

There is no need to "fix" this as it is not broken. That is normal PHP behaviour. Simply be careful when working on your models to not override them unless you want to...

I like the ability to overload the function names as I can do stuff like this:

Code:
function insert($ticket)
    {
        $this->load->helper('date');
        
        $ticket['created_on'] = now();
        
        return parent::insert($ticket);
    }

Very handy indeed. :-)
#30

[eluser]megabyte[/eluser]
See this is the magical line I was looking for:

Code:
return parent::insert($ticket);


thanks.




Theme © iAndrew 2016 - Forum software by © MyBB