Get Parameters in The Url with Codeigniter

GET parameters in the URL with CodeIgniter

When I first started working with CodeIgniter, not using GET really threw me off as well. But then I realized that you can simulate GET parameters by manipulating the URI using the built-in URI Class. It's fantastic and it makes your URLs look better.

Or if you really need GETs working you can put this into your controller:

parse_str($_SERVER['QUERY_STRING'], $_GET); 

Which will put the variables back into the GET array.

How to get the parameter from url in codeigniter?

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

Cant get URL parameters in CodeIgniter

Use this (if this is not HMVC)

in route.php

# You may need first route since you're accepting null on method
$route['mymethode] = 'mycontroller/mymethode';
$route['mymethode/(:num)'] = 'mycontroller/mymethode/$1';

In AJAX

url: http://mydomein.com/mymethode/123,

Make sure your sites run without index.php

In controller

public function mymethode($listid=null)

Passing multiple variables in URL using codeigniter

You can use uri to retrieve values in your url

Here is an example

public function getproduct()
{
$productID = $this->uri->segment(3);
$factoryID = $this->uri->segment(4);
// ProductID will be 25
// Factory ID will be 45
}

Then you can just use the values as you please

How to get the URL paramters inside view using codeigniter

You can use $this->input->get('coupon'); to get the value of url parameter.
But, I suggest you to get the parameter value with $this->input->get('coupon',TRUE); to applying XSS Security directly.

For information can be found on this link.

How to get id from URL in codeigniter?

if you have to pass the value you should enter url like this

localhost/yoururl/index.php/products_controller/delete_controller/70

and in controller function you can read like this

function delete_controller( $product_id = NULL ) {
echo $product_id;
}

How to pass multiple parameters from url in Codeigniter?

Considering it for SEO purpose, I think it would be safe to leave just the category and the subcategory in the url, and leave the rest as GET variable :

public function show_category($category = false, $subcategory = false)
{
$state = $_GET['state'];
$city = $_GET['city'];
// Showing ads...
}

then you can skip the category and subcategory url segment, and send the state and city as query string :

localhost/show_category/category/subcategory?state=x&city=y

Send a url parameter to a site in codeigniter

If I am understanding correctly you have a folder called modules inside of your controllers folder. This answer is assuming that you have gotten rid of the index.php? part of your URI.

Of course we know that a basic controller should look like this (so your Manage.php should look something like this:

[IMPORTANT: Controllers filenames should start with an uppercase and match the class name]

Class Manage extends CI_Controller{

public function __construct(){
parent::__construct();
// add libraries/models
}

public function index(){
// index logic
}

public function newMethod($param){
//The method used to capture your parameter.
}
}

If that is set up properly, then you should be able to go into routes.php and add something like this:

$route['admin/modules/(:num)'] = 'modules/Manage/newMethod/$1';

Then you should be able to visit www.yoursitename.com/admin/modules/#INSERT-A-NUMBER and get what you want.

Alternatively you can change the route so that it accepts anything as a parameter and not just a number. That looks like this:

$route['admin/modules/(:any)'] = 'modules/Manage/newMethod/$1';

Hope this helps!



Related Topics



Leave a reply



Submit