![]() |
Problems with my CRUD function - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Problems with my CRUD function (/showthread.php?tid=22564) Pages:
1
2
|
Problems with my CRUD function - El Forum - 09-14-2009 [eluser]minoh[/eluser] hello guys, for my first CI app i want to use a CRUD function to administrate different tables. i success using an example to create the CR function, but i have problem retrieving 'id' in the view/update/delete functions. the CI errors : Code: A PHP Error was encountered and this is my view() function : Code: function view($id) thanks. Problems with my CRUD function - El Forum - 09-14-2009 [eluser]xzela[/eluser] dude, the above error is simply stating that it can not find the first parameter ($id). This means you are not properly supplying the correct parameters when calling this function. Recheck the line of code which calls the 'view' function. You should find the error at that location. Problems with my CRUD function - El Forum - 09-15-2009 [eluser]BrianDHall[/eluser] In your code: Code: function view($id) This says "this function MUST be called with a parameter, or error". While this is logically ok, the problem is you are assuming in your function that $id was set somewhere - but it might not have been. You can set a default value for $id, here: Code: function view($id = 1) To pass a variable to the function the url should be something like website.com/person/view/1 - but if someone rips off the 1 they'll get that ugly error about $id being undefined, so you'll want to make sure its set before you refer to it. Problems with my CRUD function - El Forum - 09-15-2009 [eluser]minoh[/eluser] yes i can get the $id in the url but i still have de same errors. the problem can be from CI url helper ? because i create a new site where i only use the CRUD function and it's works. Problems with my CRUD function - El Forum - 09-15-2009 [eluser]kurucu[/eluser] What URL are you entering? I assume you know it should be /yoursite/view/1 and not /yoursite/view?id=1. Come to think of it, if you are not using index.php, is your .htaccess file configured correctly? Quick test: do other controller functions that take parameters work OK? Problems with my CRUD function - El Forum - 09-15-2009 [eluser]minoh[/eluser] - the URL is good 'MySite/admin/person/view/1". - i'm using this .htacess to take off the index.php : Code: RewriteEngine On - it doesnt work with a simple controler to take the parameter, also by trying to delete a record with a simple Code: $this->db->where('id', $this->uri->segment(3)); Problems with my CRUD function - El Forum - 09-15-2009 [eluser]JoostV[/eluser] Counting the params in your URI, your ID appears to be in segment 4, not 3. So Code: $this->db->where('id', $this->uri->segment(4)); If you are not sure which segment your param is in, test you params using Code: var_dump($this->uri->segment_array()); Problems with my CRUD function - El Forum - 09-16-2009 [eluser]minoh[/eluser] [quote author="JoostV" date="1253052067"]Counting the params in your URI, your ID appears to be in segment 4, not 3. So Code: $this->db->where('id', $this->uri->segment(4)); If you are not sure which segment your param is in, test you params using Code: var_dump($this->uri->segment_array()); the var_dump returns : array(0){} as result. normally it should returns array(4){...}. Problems with my CRUD function - El Forum - 09-16-2009 [eluser]JoostV[/eluser] There's your problem, then. Now all you have to do is figure out why... Problems with my CRUD function - El Forum - 09-16-2009 [eluser]minoh[/eluser] i dont have any idea, i'm starting with ci. as i post before by testing the function in a new ci site, the function works, but when i copy it in my project doesnt work. the problem could come from url helper ? |