Welcome Guest, Not a member yet? Register   Sign In
Can I pass URL variables to the index function of a controller ?
#4

[eluser]suba[/eluser]
can pass variable to the index function.
example:
your url is www.example.com/test/45

you can get url value via two ways.
1
Code:
$this->url->segment(n);// n means 1,2,3,4,etc.,
//or
$this->url->uri_to_assoc(n)
2.
Code:
class Test extends Controller
{
function index($id)//here add argument variable
{
// through the index function you can access first value from url.
//first value means next of controller name.
$this->data['id']=$id;//45
$this->load->view('test_view',$data);
}
}

in your view page
Code:
<html>
<body>
<h1>Id is&lt;?=$id?&gt;</h1>&lt;!-- 45 --&gt;
&lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
Can I pass URL variables to the index function of a controller ? - by El Forum - 06-19-2010, 01:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB