Query string creating problems for all methods in codeigniter - php

I am working on one project in that I am passing users data via query string in url , so I have enabled it inside config.php but after this if I try to call other methods in project then it is not working and again when disabled query string in config.php all methods are working fine, I don't know why enable query string affected on all methods in controller.
Note: I am using routing so it is lik this
$config['enable_query_strings'] = TRUE;// afte making true unable to call other methods in controller.
$route['xyz_method/(:any)'] = 'controller/method1/$1';
$link=urlencode(base64_encode("some_data"));
<li>Click here</li>

"...
CodeIgniter optionally supports this capability, which can be enabled in your application/config.php file. If you open your config file you’ll see these items:
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
If you change “enable_query_strings” to TRUE this feature will become active. Your controllers and functions will then be accessible using the “trigger” words you’ve set to invoke your controllers and methods:
index.php?c=controller&m=method
Note
If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with segment based URLs.
..."
See documentation here

To work this, try using this
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;

Related

Change Codeigniter pagination query string

I want to change codeigniter pagination query string. Currently this is working like below example
http://example.com/1
I want to change this with my example like
http://example.com?page=1
Anyone can let me know how I can do this without changes in existing library? or Should I have to create my own pagination for this system?
Thanks
You have to set config for pagination
$config['page_query_string'] to TRUE
you also can configure your querystring
$config['query_string_segment'] = 'your_string';
Actually with CodeIgniter 3.0.0 there is a better solution now;
You should enable the reusage of the query string buy enabling this configuration:
$config['reuse_query_string'] = true;
only after that you should initialize the pagination:
$this->pagination->initialize($config);
You can do it by using 'Enabling Query Strings' in /application/config/config.php
$config['enable_query_strings'] = TRUE;
But, it will also add controller and method names as query stings not as clean urls like:
index.php?c=controller&m=method
Reference

How to pass controller name throught query string Codeigniter

How to pass when controller name is inside folder.
index.php?c=welcome
I tried this index.php?c=A/welcome which is not working.
The config file has this:
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
It says: "// experimental not currently in use"
I looked at the Router class that handles this and it looks like it uses the value passed in ?d= to set the directory...you might want to try that.
It would look like
index.php?d=A&c=welcome
Just pass the folder name before controller and append the variables after it. like
index.php / foldername / controllerName / functionName
NOTE:
Use of "index.php" is mostly depends on you as you have used them with others.

Sending QueryString in codeIgniter

I am new to code Igniter framework, and I want to send querystring data, with $this->index(), function, how can i do this, I have done editing in config.php file, to accept query strings.
Your question is not clear at all. As an indication on how to work, though:
As it seems you already did, you must set to TRUE the "enable_query_string" config index:
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
As you see, you also have an index for the $_GET array where controllers and models will be placed. In order to build a url (which you must do manually, since the helpers work with uri segments) you can do something like:
index.php?c=mycontroller&m=mymethod&var1=var1
which maps to Mycontroller() controller class and Mymethod() class method, and works the same as for uri segments. In your methods, to retrieve the query string variables after the method, you can:
use the $this->input->get('var1') input method to retrieve the query string part;
use the "regular" $_GET array (which you have enabled by passing TRUE to the config index, as above), $_GET['var1']
just pass the argument to the method (as in uri segments):
function mymethod($var1)
{
echo $var1;
{
"c" and "m" are default triggers, which you can obviously change to whatever you like (just set them in the 2 config indexes, of course).
In Code Igniter you may use $this->input->get() inside your controller functions. You can also use PHP's $_GET array. More information in the documentation at http://codeigniter.com/user_guide/libraries/input.html

How to get Zend Route to use a different module depending on the domain name

I'd like to set up multiple domain names to use the same framework, but I can't seem to get zend's router to bend to my will.
There are plenty of examples using subdomains, but trying to make them work for an entire domain doesn't seem to work as I would expect it to.
Here's the closest I've come, but it doesn't seem to work:
resources.router.routes.mysite.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite.route = "www.mysite.com"
resources.router.routes.mysite.defaults.module = "mysite"
resources.router.routes.mysite1.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite1.route = "www.mysite1.com"
resources.router.routes.mysite1.defaults.module = "mysite1"
Any suggestions?
Based upon this Nabble thread, it looks like you need to add a path route and then chain that path route to your hostname routes.
So perhaps something like:
; abstract routes to be used in chaining
resources.router.routes.plain.type = "Zend_Controller_Router_Route"
resources.router.routes.plain.abstract = true
resources.router.routes.plain.route = "/:controller/:action"
resources.router.routes.plain.defaults.controller = "index"
resources.router.routes.plain.defaults.action = "index"
resources.router.routes.mysite.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite.abstract = true
resources.router.routes.mysite.route = "www.mysite.com"
resources.router.routes.mysite.defaults.module = "mysite"
resources.router.routes.mysite1.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.mysite1.abstract = true
resources.router.routes.mysite1.route = "www.mysite1.com"
resources.router.routes.mysite1.defaults.module = "mysite1"
; now the actual (non-abstract) routes are chains of the abstract ones
resources.router.routes.mysite-plain.type = "Zend_Controller_Router_Route_Chain"
resources.router.routes.mysite-plain.chain = "mysite,plain"
resources.router.routes.mysite1-plain.type = "Zend_Controller_Router_Route_Chain"
resources.router.routes.mysite1-plain.chain = "mysite1,plain"
Actually, we could probably collapse the two abstract mysiteX routes into a single abstract route using a placeholder like :site to stand in for the mysiteX value and set some requirements/defaults on those, but I think this conveys the idea.
Not tested - actually I have never played with chained routes before - but it seems that something like this is required to make the hostname routing work.
I've done this before by actually using different configuration files based on the current value of $_SERVER['SERVER_NAME'], which is configured by the web server. (HTTP_HOST is the one sent by the client.)
You could probably do the same thing in a single file by using INI file sections and inheritance.

URI re-routing in codeigniter

I'm using URI re-routing in CI to make better URLS. An example here would be:
$route['users/(:any)'] = "users/index/$1";
The aim here is to get rid of the index from URL. This works well. However it stops me from being able to access any functions in the users controller, for example
mywebsite.com/users/messages
Just redirects to the users/index. Is there a way around this?
Define the list of methods you wish to keep then let the rest wildcard match:
$route['users/(messages|login|something)'] = "users/$1";
$route['users/(:any)'] = "users/index/$1";
Hi I'm not familiar with CI but i have a similar routing system. The (:any) works as a sort of catch all. When my router checks the routing rules it stops checking if it has found an exact match. So then the answer would be to just add another functions route before the catch all. Like
$route['users'] = "users/index/";
$route['users/messages/(:any)'] = "users/checkmessages/$1";
$route['users/(:any)'] = "users/$1";
Not sure how CI handles this but i can think of something like the first URL part is the class and the second the function. The router or the controller module should have the intelligence to start calling the function even without the routing table.
The routing table should only be used in case of "other callable names" like i did above with the messages/checkmessages thingy.
hope that gets you going.

Categories