Welcome Guest, Not a member yet? Register   Sign In
actively control uri (segments) when opening views via different functions
#1

[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/se...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/se...ve_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?
#2

[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;-)
#3

[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.
#4

[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?
#5

[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);
$this->load->view('my_view', $data);
#6

[eluser]sparbier[/eluser]
:red: humble, humble me. but thx anyway, got it working now - the decent way.




Theme © iAndrew 2016 - Forum software by © MyBB