How to get the parameter from url in codeigniter?
$this->uri->segment(n);
where n = 1 for controller, n = 2 for method and n = 3 for parameter and so on.You need n = 3 to get parameter.
In your path
localhost/log/job/php , your method name is missing. Even if your method name is
index then you route will be localhost/log/job/index/phpIn case if you need to remove index.php from url then you will get parameter using
localhost/log/index.php/job/index/phpTo remove index.php you need to create .htaccess file by following these steps:
- Create a .htaccess file where index.php file is located with content
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] - Make sure that apache can access this .htaccess file. To do this edit apache configuration file. If you use ubuntu, then it is
/etc/apache2/sites-available/defaultand then changeAllowOverride nonetoAllowOverride allfor directory and www directory.
<Directory /> Options FollowSymLinks AllowOverride all </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride all Order allow,deny allow from all </Directory> - Then enable mod rewrite if you don't have it, with the following command:
`sudo a2enmod rewrite` - Finally do not forget to restart apache.
Another Way:
$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)
{
........
}
}
Comments
Post a Comment