CodeIgniter Forums
having a hyperlink redirect or submit to a new controller - 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: having a hyperlink redirect or submit to a new controller (/showthread.php?tid=53153)



having a hyperlink redirect or submit to a new controller - El Forum - 07-12-2012

[eluser]chubbypama[/eluser]
hi. just new to mvc.
wondering what's the mvc way / codeigniter way to do the following:
i have a list thats being returned from the database... let's call it a widget list.
So i have a controller called Widgets and the index method just returns a list.
i'm building a table with the details.
i want to build it so that if the user clicks on the widget name in the list, it will take them to a new page that shows the details of the widget.

I have another controller called Widget and a method called details().
the question is should i make the table items individual forms, or do i just do an anchor tag? if i do an anchor, how do i pass the value of the widget name to the new controller?
right now i have something like this:

<a href="&lt;?php echo base_url();?&gt;index.php/Widget/details/$viewbag['id']">

and it does redirect.. but this a good way to accomplish this task?

thanks


having a hyperlink redirect or submit to a new controller - El Forum - 07-12-2012

[eluser]InsiteFX[/eluser]
anchor tag



having a hyperlink redirect or submit to a new controller - El Forum - 07-12-2012

[eluser]chubbypama[/eluser]
[quote author="InsiteFX" date="1342123600"]anchor tag
[/quote]

sorry, i was editing my response when you posted this answer...
is this the best / correct way?
thanks!


having a hyperlink redirect or submit to a new controller - El Forum - 07-12-2012

[eluser]InsiteFX[/eluser]
yes



having a hyperlink redirect or submit to a new controller - El Forum - 07-12-2012

[eluser]kanjimaster[/eluser]
Yes.

Though using site_url(("Widget/details/$viewbag[‘id’]") in the href would be more elegant.

And &lt;?php echo anchor("Widget/details/$viewbag[‘id’]", "whatever")Wink; ?&gt; still more so.


having a hyperlink redirect or submit to a new controller - El Forum - 07-12-2012

[eluser]Aken[/eluser]
They answered your question, but here's the actual code:

Code:
<a href="&lt;?php echo site_url('widget/details/' . $viewbag['id']); ?&gt;">Link Text</a>

// OR

&lt;?php echo anchor('widget/details/' . $viewbag['id'], 'Link Text'); ?&gt;