![]() |
how to take the url to became a variable - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: how to take the url to became a variable (/showthread.php?tid=17294) |
how to take the url to became a variable - El Forum - 04-01-2009 [eluser]sherpa[/eluser] Code: function choose_testi($id=0){ how to take the url to became a variable - El Forum - 04-01-2009 [eluser]yudahebat[/eluser] no. I need the segment(3) to get the ID of my tabel that I choose to show on $data I've tried your code but I still use Code: $id = $this->uri->segment(3); and I got an error Code: A PHP Error was encountered I also cek your code without editing and got an error also no data pass to the view how to take the url to became a variable - El Forum - 04-01-2009 [eluser]jdfwarrior[/eluser] Not trying to be mean, but it seems like your having trouble with some really basic stuff with CI/PHP. You really should go back and dig a little more into the user guide. CodeIgniter has awesome documentation. You could probably figure out everything your wanting to know very easily there. how to take the url to became a variable - El Forum - 04-01-2009 [eluser]yudahebat[/eluser] I've found how to pass the $data to the view but on the Code: $this->load->view('adm_testimonial',$data); if I can make it in Code: redirect('/admipage/adm_testimonial/'); please help me... how to take the url to became a variable - El Forum - 04-01-2009 [eluser]jdfwarrior[/eluser] Well you cant pass data through the redirect function. If your just trying to access that function and give it the data though, why dont you just call the function rather than doing a redirect. Modify your adm_testimonial function to accept a parameter and do: Code: $this->adm_testimonial($data); how to take the url to became a variable - El Forum - 04-01-2009 [eluser]yudahebat[/eluser] sorry I dont Understand my english not so good where I put that code?? specificlly.. how to take the url to became a variable - El Forum - 04-01-2009 [eluser]jedd[/eluser] [quote author="yudahebat" date="1238605909"]no. I need the segment(3) to get the ID of my tabel that I choose to show on $data[/quote] Okay - the important thing here that I think you are missing is that if you have a function like this: Code: function foo ( $bar ) { Then $bar will be the same as segment(3) The good thing about using the function ($variable) approach is that you can easily have multiple variables (and they take their value from your URL : http://example.com/Controller/foo/2/3/4/5 You could get each of those values by adjusting the code above to be: Code: function foo ($bar , $hugo , $bob , $nuggen) { In that example, using that URL, you'd find that $bar = 2, $hugo=3, $bob=4, $nuggen=5 The bad thing about using segment(x) is that a) it's harder to read and debug, and b) if you ever adjust your controller file layout - start using sub-directories for example - these numbers are suddenly wrong and you have to re-visit your code. Now, the reason that you see people write this kind of code: Code: function foo ( $bar = 0 ) { Is so that IF the URL is just http://example.com/Controller/foo -- so, no trailing number segment -- then $bar will be set to 0, which is more convenient than being 'not set'. If there IS a trailing number on that URL, then it over-rides - and $bar takes on that value. Does this make more sense? how to take the url to became a variable - El Forum - 04-01-2009 [eluser]jdfwarrior[/eluser] modify your adm_testimonials function to accept a parameter (see jedd's post above). Then replace your redirect function call, with the code I gave you. That will make it run that function (same as going to admpage/adm_testimonials) and you can pass the $data variable to that function. From there you can manipulate it or display whatever you want. how to take the url to became a variable - El Forum - 04-01-2009 [eluser]yudahebat[/eluser] I've change my code as your command do you mean like this?? Code: function adm_testimonial($id=0) and choose_testi function Code: function choose_testi($id=0){ it didn't produce anything on $data so Code: echo $tanggal; undefined... anything wrong?? please help.. how to take the url to became a variable - El Forum - 04-01-2009 [eluser]yudahebat[/eluser] I give you the text link on the views adm_testimonial.php Code: echo '<td class="tabel2">'; |