how to remove added '?' into url in CI before controller name - codeigniter

I have a login function where after successful login, new directory mentioned like :
redirect('admin');
But when new directory loaded at that time url become like this :
"//localhost/xyz/?admin"
Here an character "?" added into URL. How can i solve this problem.

In your config (applications/config/config.php), query strings will be enabled:
$config['enable_query_strings'] = TRUE;
To remove the ?, disable query strings:
$config['enable_query_strings'] = FALSE;

Related

To make URL for User Profile and products id in codeigniter

I created the URL in route.php like
www.domainname/companyname - Its Work properly
And i also created the URL like
www.domainname/events - Its also works good.
But I created the URL like
www.domainname/category/1 - Its shows error
$route["(.*)"] = 'controller/productsname/$1';
$route['Admin'] = 'Admin/login';
$route["category/:num"] = 'controller/category/$1';
$route["(.*)"] = 'controller/productsname/$1';
Thanks
I haven't tried it yet, but you will probably need to simply point all urls to it, naturally after the rules you've already added.
So something like:
$route['Admin'] = 'Admin/login';
$route["category/:num"] = 'controller/category/$1';
$route["(:any)/(:num)"] = 'controller/$1/$2';
//or
$route["(:any)/(:num)"] = 'controller/products/$1/$2';

`translate_uri_dashes` not working codeigniter route

i already tried this code in route file but it not convert _ to - by default
$route['translate_uri_dashes'] = TRUE;
$route['stock/upload_stock'] = 'stock/upload_stockt';
CodeIgniter 3 provides a nice way for it ,There is a route
$route['translate_uri_dashes'] = false;
which is by default set to false, but if you set it to true, you can name your controllers and controller methods using the underscores (_s) and can call them using dashes (-s).
For example you have a controller named Company, and inside your Controller you have a method called about_us, now you can call it both the ways /company/about_us and company/about-us , when your $route['translate_uri_dashes'] is set to true.
So, try making your route as below
$route['stock/upload-stock'] = 'stock/upload_stock';

Difficulty with two segment uri

They are trying to create the url, where the first segment is the User and the second is his file, ex: www.exemplo.com/joao/ball
Controller
public function user() {
$user_url = $this->uri->segment(1);
}
^^ This would return the profile with every file: www.exemplo.com/joao
public function arquivo() {
$arquivo_url = $this->uri->segment(2);
}
^^ This specific file: www.exemplo.com/joao/bola
Routes
$route['(:any)'] = 'home/user/$1';
$route['??'] = 'home/arquivo/$1';
To solve your problem, you should use route like this..
$route['(:any)/(:any)'] = 'home/arquivo';
$route['(:any)'] = 'home/user';
but as far you with your project this type of routing will give your some hard time. i suggest you to use explicit route name because (:any) refer any thing can be pass through this url.
You can use routes to map the URI and its parameters to the relevant function. CodeIgniter routes behave differently depending on the version of CI.
In CodeIgniter 2.2.0 (:any) is equivalent to the regex, .+ - matches one or more of any character (excluding line breaks); in 3.0 and the current development version it is equivalent to [^/]+ - one or more of any character, excluding line breaks.
The latter is more useful in this case, as you want to identify the two parameters (separated by a forward slash).
In 2.2.0:
$route['([^/]+)/([^/]+)'] = 'home/arquivo/$1/$2';
$route['(:any)'] = 'home/user/$1';
In 3.0:
$route['(:any)/(:any)'] = 'home/arquivo/$1/$2';
$route['(:any)'] = 'home/user/$1';
Controller functions will usually pass the URI parameters as function parameters like this:
public function user($user)
{
// Show the user's profile
}
public function arquivo($user, $file)
{
// Show the file for the user
}
Able to resolve with the following code.
$route['([^/]+)'] = 'home/user/$1';
$route['(:any)/(:any)'] = 'home/arquivo/$1';

Encryption URL parameter not working

In my view form,
$encrypted_string = $this->encrypt->encode($list['id']);
where $list['id'] is auto increment. and URL,
Delete
In Controler,
$id1 = $_GET['id'];
$id = $this->encrypt->decode($id1);
In this $id i get decoded value for some value not for all value,please help me..Thank you.
Instead of
$id1 = $_GET['id'];
Try
$id1 = $this->input->get('sid');
Remember that the param you are passing by query string should have the same name in your controller.
Also, in config.php change
$config['uri_protocol'] = 'auto';
Try different values until one of them works for you.

enable the query string in codeigniter

i already make two changes in config file to enable the $_GET array as
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = true;
but whenever i try tow run my code as http://example.com/controller/function/$demo=demo
it redirected towards the default controller
Enabling query strings in CodeIgniter means that you're using the query string to pass in the controller and function instead of them being parsed from the PATH INFO.
If you want to use the default system for determining what controller and function to use, you do not want to set $config['enable_query_strings'] to true.
This previous SO post covers how to enable teh $_GET array in CodeIgniter: Enabling $_GET in codeigniter
I think that's what you're trying to do.
You also have to set controller and function triggers from config:
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
So once query string is enabled, you can access it like this:
http://example.com/index.php?c=controller&m=function&demo=demo

Resources