converting into URI fashion from old string format |
[eluser]alvaroeesti[/eluser]
Hello How can this Code: <a href="closeup.php?id='.urlencode($row['id']).'"> be written in segment format / / for codeigniter? I need to be able to pick the id of the row clicked in order to go to another page with more details about that row. I had it in the standard php procedural but I dont know how to write it in the other way. In addition to that, that code is in a VIEW page, so I am confused now as to how to go to another page, from a view directly to another view? but then who is getting that ID in order to fetch data? Looks to me upon clicking the link that value would have to go to a controller page, that page forward the value to a model, the model return the value to the controller and this one load the closeup view page ?
[eluser]keevitaja[/eluser]
eestlane? if controller name is closeup and method index, then segments should look like this Code: /closeup/index/<id-number> use html helper anchor Code: echo anchor('/closeup/index/<id-number>', 'click me'); and to get the id value use in controller Code: $id = $this->uri->segment(3) as it is the third segment of the uri. to pass this value to the view Code: $data['id'] = $id;
[eluser]alvaroeesti[/eluser]
Ma elan Jõhvis, ja sina? yes, thank you! that will do, it was great about the anchor! I didn't know about it and was doing it via the old http. I managed to get this below working, but I would still like to improve it by replacing one part of it, the http localhosting/housing/ by base_url() but is not working when I try. Code: <td><?php echo anchor("/closeup/index/$encontrados->id_atributo", "<img >thumb_a>");?> Interesting, the engine here at codeigniter has modified itself part of my code, that is, it displays what I had not written myself. it has made disappear the localhost/housing/ how can i replace the part of http://local-- host/housing by base_url() in this code: php echo anchor("/closeup/index/$encontrados->id_atributo", "img src= local---host/housing/assets/uploads/files/$encontrados->thumb_a>");
[eluser]Bankzilla[/eluser]
In applications/config/config.php one of the opening lines is $config['base_url'] = '';, change that to the appropriate url. Also in the controller instead of doing Code: $id = $this->uri->segment(3) You can also do this, which is the same as the above method Code: public function page($id){ So if you want a different view if the $id is set, just check if $id is set and load a different view.
[eluser]alvaroeesti[/eluser]
Thank you. With regards to the base_url I do have that configured, the issue that I am having is because of the double and single quotes, how to embed that function properly in that long string. Also, if I write it here, the editor engine of this website modifies is so that it does not display what I actually wrote, even if i dont include the code quotes, so i have to remove so many things in order to prevent from reinterpreting what i wrote that i cant other than pasting a pic of it. Anyway, i have it in ordinary php and it works so i ll leave it for the end. thank you again for the tip about the page($id) however i think i will stick with segment(3) the reason is that some people if they see the page($id) they always try to sql inject you, although it won't work in my case |
Welcome Guest, Not a member yet? Register Sign In |