I have an url rewrited like this : http://localhost/test/boutique/index.php/language/fr
I would know if I can take an element inside because var_dump($_GET['language']) return nothing.
the original url is http://localhost/test/boutique/index.php?language=fr (original). In this case $_GET['language'] works fine.
I need the element : fr when it's rewrited to identified the good language.
thank you.
You should get request URI with $_SERVER["REQUEST_URI"] and parse it.
Here is simple example which might help you get the idea for achieving your goal:
$temp = explode(".php", $_SERVER["REQUEST_URI"]);
// $temp[1] -> /language/fr
$url = explode("/", substr($temp[1], 1));
// $url[0] -> language , $url[1] -> fr
echo $url[1];
Are you trying to get it in CodeIgniter???
If it's in CodeIgniter then try to get the value using code.
$val = $this->segment->uri(3);
I'm working on a CodeIgniter project and trying to get the id of this URI:
http://example.com/myDomain/index.php/public/calendar/gestionEvent?id=c2pnumqnqr0dg9tgmaklho5280#google.com
I want the controller to delete or update the event using this ID.
I tried $this->uri->segment(4)but it doesn't seem to work and doesn't show anything.
try this :
$id = $this->input->get_post('id');
echo $id;
in cotroller
$id = $this->input->get('id');
$data['id'] = $id ;
you can not use uri segment here
ex:-http://example.com/index.php/news/local/metro/crime_is_up
here you can use uri segments
The segment numbers would be this:
1.news
2.local
3.metro
http://codeigniter.com/user_guide/libraries/uri.html
UPDATE
if you want to get only the id with out #google.com you can simply use explode()
$id_string = $this->input->get('id');
$id_string_exp = explode("#", $id_string);
$id = $id_string_exp[0];
Then use
$id = $this->input->get('id');
$this->uri->segment(4) will work only if the url is in the form of segments like
http://example.com/myDomain/index.php/public/calendar/gestionEvent/c2pnumqnqr0dg9tgmaklho5280#google.com
Then you will get id using "URI segments".Thanku.i hope this helps you friend
This is my code in routes.php
$route['default_controller'] = "admin";
$route['(:any)'] = $route['default_controller']."/index/";
This is my url:
http://myserver.net/visio/jklmn
But i cant to get the value in index() in admin controller.
I want to get the value jklmn in admin controller.If there is any mistake in my routing code.
This is my index() code;
function index($key = ""){
if(isset($key)){
$newkey = $key;
$data['key'] = $key;
$this->load->view('index',$data);
}else{
redirect('admin/index_login');
}
}
When i taking above link in browser i get the error message below:
Not Found
The requested URL /visio/jklmn was not found on this server.
Use this routing rule:
$route['(:any)/(:any)'] = $route['default_controller']."/index/$2";
which will match a URL with 2 segments (each containing any character) and pass the second match as $2.
You can also pass the first match, just use $1.
Is it possible to create a wildcard match using the Zend Framework Zend_Controller_Router_Route_Hostname for the actual domain? I tried the simple example below but the system would not recognize the route. When I hardwired the route (login.domain.com), it would work properly.
resources.router.routes.login.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.login.route = "login.*"
resources.router.routes.login.chains.index.type = "Zend_Controller_Router_Route"
resources.router.routes.login.chains.index.route = ":action/*"
resources.router.routes.login.chains.index.defaults.controller = "login"
resources.router.routes.login.chains.index.defaults.action = "index"
$route = new Zend_Controller_Router_Route_Hostname ('login.:domain.:net');
$_SERVER ['HTTP_HOST'] = 'login.example.com';
$request = new Zend_Controller_Request_Http ();
$match = $route->match ($request);
var_dump($match);
Is this possible without the :domain.:net both being explicit, i.e. without stipulating just one period?
i.e. I currently have
new Zend_Controller_Router_Route_Hostname('sub.example.com',array('controller' => 'x'));
..but what I'd really like to do is:
new Zend_Controller_Router_Route_Hostname('sub.:remainder',array('controller' => 'x'));
..whereby this route will match any hostname that begins with 'sub.' including sub.example.com, sub.another.example.com, sub.somethingelse.com, sub.com etc.
Doesn't seem to work though!
Anyone got this working?
I am having trouble setting up pagination on codeigniter when I pass parameters in the URL
if my url is like this : search/?type=groups
what should be my $config['base_url'] for pagination to work?
if i set the base url to search/?type=groups the resulting url is search/?type=groups/10
which means $_GET['type']=groups/10
thank you
In pagination config:
if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");
Your current $_GET vars will be shown in pagination links.
You can replace $_GET by another associative array.
This won't add a query string unless one already exists.
Update:
I just saw, if you go back from another pagination number to click on the first(1), CI does not care anymore of your suffix config.
To fix that use $config['first_url'].
e.g: $config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
The most up-to-date answer of this question is;
You should enable the reusage of the query string by enabling this configuration:
$config['reuse_query_string'] = true;
after that you should initialize the pagination:
$this->pagination->initialize($config);
Added $config['reuse_query_string'] to allow automatic repopulation
of query string arguments, combined with normal URI segments. - CodeIgniter 3.0.0 Change Log
Here is my jquery solution:
Just wrap pagination links in a div like this:
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
than add the following jquery code:
$("#pagination > a").each(function() {
var g = window.location.href.slice(window.location.href.indexOf('?'));
var href = $(this).attr('href');
$(this).attr('href', href+g);
});
Works fine for me.
if you are using codeigniter 2 there's an option in config.php, $config['allow_get_array'] - make sure its on TRUE.
Then set the pagination option $config['page_query_string'] to TRUE.
And finally, in your case set $config['base_url'] to "search/?type=groups", the pagination will append the per_page query string after it.
It should work this way, you'll get the offset in $this->input->get("per_page").
code strong!
I struggled with the same issue today. My solution is this:
Generate the pagination links and store them in a string ( $pagination = $this->pagination->create_links(); )
Use regexp to find all links and add query strings
The regular expression code used is:
<?php
$query = '?myvar=myvalue';
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
$unique = array();
if( preg_match_all("/$regexp/siU", $pagination, $matches) )
{
foreach ( $matches[2] as $link )
{
if ( !isset($unique[$link]) )
{
$data['pagination'] = str_replace($link . '"', $link . $query . '"', $data['pagination']);
$unique[$link] = '';
}
}
}
unset($unique);
Works like a charm for me! What it does is:
Find all links
Replace unique links (since there is a previous/next links same link may appear more than once) with the original link and the query-string.
Then just assign the variable to the template that will be shown and use print $your_pagination_variable_name; to show the links with your query-strings attached!
I think you are trying to do the same thing I was trying to do and I got it to work correctly by not setting a base url and just using this setup it kept me from having to manually editting the library
$this->load->library('pagination');
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['total_rows'] = 200;
$config['per_page'] = 20;
$this->pagination->initialize($config);
Using the $config['suffix'] is the IMO best way to implement this because it doesn't require any extra processing as the regex solution. $config['suffix'] is used in the rendering of the urls in the create_links function that's part of the system/libraries/Pagination.php file so if you set the value it'll be used in the generation of the urls and won't require anymore processing which means it'll be faster.
Thanks for the post, this saved me tons of extra, not needed, coding!
Before line:
$this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'=';
Replace this code below:
if(isset($_GET[$this->query_string_segment]))
{
unset($_GET[$this->query_string_segment]);
}
$uri = http_build_query($_GET);
$uri = empty($uri) ? '?' : $uri . '&';
$this->base_url = rtrim($this->base_url).$uri.$this->query_string_segment.'=';
Just see this link.
Just update the modified pagination class and then add
$config['get'] = "?string=" . $_REQUEST['string']."&searchBy=" . $_REQUEST['searchBy'];
The solution is that CodeIgniter does not function like that.
what I need is a method ( in the controller ) for each one of the options in "type"
so one option would be a method called :groups , another called entries etc etc
each method refers to a different model class or method as needed.
I am trying to better understand OOP and CI ...a bit of adjusting to do ... feel free to comment and correct me if i am wrong.
thank you
I got the same problem. My solution is to modify Pagination and put it in application/libraries.
First i create
var $get='';
and find all "a" elements and add $get in the href="........'.$this->get.'"'>.......</a>
Now in the controller or model input these line
$config['get']=(isset($_GET['search']))?'?search='.$_GET['search']:'';
That's it! i hope it will help you.
IN YOUR CONTROLLER:
$config['anchor_class'] = "class='link-pagination'";
IN YOUR VIEW:
$(".link-pagination").each(function() {
$(this).attr("href", $(this).attr('href') + "?id=<?= $this->input->get('id') ?>");
});
Had the same problem but realized that newer versions of CI have a suffix defined within the pagination class. Though it's still not in the documentation. No need to hack it.
I have encountered with similar kind of problem, and based on the above answer here is what I have to do for customization according to my needs.
My URI was to be something like this:
base_url() . /search/?term=
So, here is what I have done:
$config['base_url'] = base_url ."/search/?term=" . $_GET['term']
Hope you'll find the answer on this page:
LINK. Edit your answer back in if you can.