Welcome Guest, Not a member yet? Register   Sign In
Passing values

[eluser]Suhas nazir[/eluser]
Is it possible to pass values to the index function in codeigniter?????

The index function in a controller is only called when no method is provided. For example:
www.example.com/mycontroller -> this calls the index method in the mycontroller controller
www.example.com/mycontroller/mymethod -> this calls the mymethod method in the mycontroller controller
This means, that you will not get to the index function when there is an argument in the url after the controller name.
If you DO want to call the index method with an argument, you need to use the _remap method. Example:
function _remap()
  // if www.example.com/mycontroller/argument is called, segment(2) equals 'argument'
  // so this way, it will result in index() being executed with the argument 'argument'

You might want to do some more checking, for instance if www.example.com/mycontroller is called, segment(1) is 'mycontroller' and segment(2) is 'index'. So you should check if the argument is 'index' before handling it. but I hope the idea is clear now.

For more info, check the 'routing' page in the CI manual.

What are wanting to do because the question has many answers? The one mddd gave you is correct, and can also been done like:
//In Controller
function index(){
   $this->argument(); //Run index or empty 2nd uri segment to argument method

function argument(){
   //Do something here

Or perhaps you want to define a default 3rd segment to automatically be set by default
function index($id = 0){
  //$id = 0 by default

function index(){
   $id = $this->uri->segment(3,0); //$id = 0 by default

Theme © iAndrew 2016 - Forum software by © MyBB