Can't get segment() info |
[eluser]drakenlx[/eluser]
Hello Everybody I'm new to CI and wrote a very simple code in which I can't get segment info; the plan is to list a table with 3 columns id_user / name / and a Picture Anchor pointing to the edit method in the main controller passing the id_user as a parameter, I get redirected to: http://localhost/cigniter/index.php/user/edit/3 But when I want to get segment info in the "edit" function always get: echo $this->uri->total_segments() // displays: 0 echo $this->uri->segment(0,"No Data") // displays: No Data echo $this->uri->segment(1,"No Data") // displays: No Data echo $this->uri->segment(2,"No Data") // displays: No Data echo $this->uri->segment(3,"No Data") // displays: No Data Do you know if need to edit something in CI config or php.ini, etc. ? Thank You The Code is: Controller: User.php Code: <?php View: user_v.php Code: <html>
[eluser]Twisted1919[/eluser]
1. Don't load the uri class, it is auto loaded by CI . 2. $this->uri->segment(0) doesn't exists, the count starts from 1. 3. print_r($this->uri->segment_array()) gives you ? 4. don't do database calls from your controller, move them in your models, and call the models . 5. don't foreach($rs_users->result() as user) in your view. Instead, in your controller do $data['users'] = $this->model_name->get_users(); and in your view foreach($users AS $user); 6. don't $this->load->helper(1),$this->load->helper(2) blah . $this->load->helper(array(1,2,3,n)); is the way . 7.You will use your database in all your controllers instances maybe, so autoload it , don't load it in the constructor .
[eluser]drakenlx[/eluser]
Thank You very much "Lab Assistant" My problem is gone just removing the $this->load->library('uri'); line Now I'm taking note about the rest too. Thank you on going further the mere solution, I do appreciate it!
[eluser]Twisted1919[/eluser]
No problem, just please read the user guide ten times again. Believe me, it'll make your life much easier ![]()
|
Welcome Guest, Not a member yet? Register Sign In |