Welcome Guest, Not a member yet? Register   Sign In
how do I know which link has been clicked on web page? - CI newbie Q
#2

[eluser]WanWizard[/eluser]
The basic structure of a CI URL is:

http://www.yourwebsite/controllername/me...r2/value2/ ...

So the first two segments determine the controller to load, and the method within that controller to call.

You don't have to make a new combination for every function, if it's possisble (from a functional or design point of view) to group things in a single method, why not? You can easy convert your example to:
Code:
<ul>
<li>http://www.example.com/controllername/methodname/link/1</li>
<li>http://www.example.com/controllername/methodname/link/2</li>
<li>http://www.example.com/controllername/methodname/link/3</li>
<li>http://www.example.com/controllername/methodname/link/4</li>
<li>http://www.example.com/controllername/methodname/link/4</li>
</ul>
In which case the all call the same method. In the method, use $this->uri->uri_to_assoc() to convert the URI parameters to an array, which in this case will be
Code:
array( 'link' => '1')
You can use this info to process the request.

In a more complex case, you can use URI routing (see the manual) to consolidate URI requests (view this as a sort of rewriting of the URI), so you can use p.e. one single controller that handles all static HTML pages.

For example, if you have a controller called 'static_html', with a method 'render' that loads the view(s) and displays it, you can create a route that converts
Code:
http://www.example.com/about/company
to
Code:
http://www.example.com/static_html/render/about/company
and use the parameters 'about' and 'company' in the render() method to determine which views to load.


Messages In This Thread
how do I know which link has been clicked on web page? - CI newbie Q - by El Forum - 06-25-2010, 03:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB