![]() |
actively control uri (segments) when opening views via different functions - 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: actively control uri (segments) when opening views via different functions (/showthread.php?tid=13167) |
actively control uri (segments) when opening views via different functions - El Forum - 11-13-2008 [eluser]sparbier[/eluser] I have a controller ('setcard') that includes a function ('show_setcard') that loads a view ('mr_setcardopinions') which utilizes $this->uri->segment(3) to decide what to display. This works fine as long as that function is called directly via a url, e.g. http://beta.muckenretter.de/index.php/setcard/show_setcard/40 (this displays setcard number 40, including the 'mr_setcardopinions' view) The view includes a form to input and save something. If that is done I need to re-load the page to display the new data, so in the function that saves the data (also in the same controller 'setcard') I put as last statement $this->show_setcard(40) As result, the function is called correctly, the page reloads, but the URL still reads http://beta.muckenretter.de/index.php/setcard/save_opinion and subsequently the view that looks for the uri-segment doesn't find anymore which setcard to display. Any ideas? is there a way to actively influence the url when calling from within a function? actively control uri (segments) when opening views via different functions - El Forum - 11-13-2008 [eluser]rogierb[/eluser] Simply replace $this->show_setcard(40) with redirect("setcard/show_setcard/40") in the save function. Or replace $this->uri->segment(3) with a variable that gets passed along via function show_setcard($uri_id) to the view. Hope I got your question right;-) actively control uri (segments) when opening views via different functions - El Forum - 11-13-2008 [eluser]Colin Williams[/eluser] After processing a form successfully, it's usually best to redirect to the appropriate page. You can pass along info like messages in the session. Also, don't require that the view sniffs out the id from the URI. The controller should pass it to the view. actively control uri (segments) when opening views via different functions - El Forum - 11-13-2008 [eluser]sparbier[/eluser] well, to be bluntly honest, the reason why I opted for the view to sniff the URI is that I don't know how to pass a variable to a view. I know I could do it by saving it in the session data/cookie, but that sounded kind of overkill to me. So what is the decent way, to pass a variable from a function to a view? actively control uri (segments) when opening views via different functions - El Forum - 11-13-2008 [eluser]Colin Williams[/eluser] This is a fundamental aspect of the CodeIgniter framework. Read the user guide and be enlightened to the tool you are using. At least get through the General Topics section. Code: $data['id'] = $this->uri->rsegment(3); actively control uri (segments) when opening views via different functions - El Forum - 11-13-2008 [eluser]sparbier[/eluser] :red: humble, humble me. but thx anyway, got it working now - the decent way. |