Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the parameter from url in codeigniter?

Tags:

codeigniter

I couldn't get the parameter value from url in codeigniter. For instance: localhost/log/job/php here log/ is my folder, job/ is my controller and php is my parameter.

I want to get this parameter in controller 'job'. How can I do that?

like image 441
M.Athish krishna Avatar asked Apr 18 '15 14:04

M.Athish krishna


Video Answer


1 Answers

You can use $this->uri->segment(n);

You need to do some changes in route in order to allow the code igniter to receive the parameter in your controller

$route['uri-(:any)/(:num)'] = "controller/function/$1/$2";

OR

$route['uri-(:any)'] = "controller/function/$1";

in your controller do some changes

<?php
 if (!defined('BASEPATH'))
   exit('No direct script access allowed');

 class controller extends CI_Controller 
 {
    function function($parameter1 = null, $parameter2 = null) 
    {
       ........
    }
 }

refer this http://www.codeigniter.com/userguide2/libraries/uri.html

like image 181
user5506189 Avatar answered Oct 14 '22 18:10

user5506189