model queries preference |
[eluser]brian88[/eluser]
I wanted to do the below code because thats what codeigniter prefers. But when I try to access it in the controller I get an error in my sql because of the quotes. So im forced to do it the 2nd way(down below) Code: // get all posts i get an error with this code because of the quotes. is there a way around the quotes? Code: $data['posts'] = $this->main_mod->getPosts('posts', 'id', '50'); 2nd way Code: // get all posts Does it really matter between what one I use here? I figure the 1st code example is more secure since its code igniters way.
[eluser]Brad K Morse[/eluser]
Try this in the model Code: function getPosts($table, $id = 'id', $limit = 100) { calling in controller: Code: $data['posts'] = $this->main_mod->getPosts('posts', 'id', 50);
[eluser]CodeIgniteMe[/eluser]
Code: // get all posts this method is only for query values, which is why it is automatically escaped as stated on the user guide Queries Brad's method is the recommended one for table and field names |
Welcome Guest, Not a member yet? Register Sign In |