I have a site that I want to pass directly to the controller method without going through the class in codeigniter.
https://website.com/product_number instead of https://website.com/index/product_number
I want that to go directly to my main controller method.
config/routes.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
controllers/Welcome.php
function index($product_number)
{
//process $product_number output
}
Would this be possible in codiegniter?
Open config/routes.php then add this line to it
$route['(.+)'] = 'welcome/index/$1'; I hope this helps your situation.
Open
/application/config/config.php
then find this line
$config['base_url'] = 'https://website.com/index/';
and Replace with
$config['base_url'] = 'https://website.com/';
I hope this Aswer very helpful for you.
Related
The CodeIgniter Routing dont work,
Im trying to route:
$route['Kayit'] = "Kayit/index";
localhost:8090/Kayit/ result = 404 Page Not Found
And it doesnt work. Can someone help me?
My route.php file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['default_controller'] = 'Sayfa/view';
$route['(:any)'] = 'Sayfa/view/$1';
$route['Sayfa/'] = 'Sayfa/view/';
$route['Kayit/'] = "Kayit/index";
?>
Put
$route['(:any)'] = 'Sayfa/view/$1';
At the end line since wildcard placeholder intercepts other routes.
Like:
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['default_controller'] = 'Sayfa/view';
$route['Sayfa'] = 'Sayfa/view';
$route['Kayit'] = "Kayit/index";
$route['(:any)'] = 'Sayfa/view/$1';// (:any) wildcard catcher must go at the end
Also, you are good to remove trailing slashes from routes.
From docs:
Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
I got error "Unable to determine what should be displayed. A default route has not been specified in the routing file"
I have two controllers 1.signup and 2.login_control !
How to set routes in routes.php file ? my baseurl is http://localhost:1337/PhpProject1/
my code is below in routes.php file
$route['signup/(:any)'] = 'signup';
$route['login_control/(:any)'] = 'login_control';
$route['404_override'] = '';
First, specified your default route by your first controller.
Like this-
$route['default_controller'] = "signup";
and then add your another controller.
$route['login-control'] = 'login_control';
Do like this
Syntax
$route['how_its_look_like'] = 'controller_name/method';
Example
$route['signup'] = 'login/signup';
$route['login'] = 'login/login';
$route['logout'] = 'login/logout';
$route['404_override'] = '';
Links
Ccodeigniter Routing Examples
Hi everyone im new with codeigniter. my routes.php is
$route['default_controller'] = "Maincontroller";
$route['(:any)'] = "Maincontroller/user_index/$1";
i want to search people if they type in the URL = www.site.com/username
but my problem is when going to other controller. should i route all my controllers?
$route['default_controller'] = "Maincontroller";
$route['somecontrollers'] = 'somecontrollers';
$route['(:any)'] = "Maincontroller/user_index/$1";
then how about my methods.
i tried this remap
public function _remap($method, $params = array())
{
if (method_exists(__CLASS__, $method)) {
$this->$method($params);
} else {
$this->user_index($method);
}
}
but this only works properly in controller which is not default, and i get the result i want. but as i apply this in my default controller it doesnt work well.
Hope this one help you!
$route['Maincontroller/(:any)'] = 'Maincontroller/user_index/$1';
$route['somecontrollers/(:any)'] = 'somecontrollers/user_index/$1';
$route['(:any)'] = "user_index/$1";
I want to route:
site.com/add-your-business to site.com/addyourbusiness
Can you do that with the -
this does not work:
$route['add-your-business'] = "addyourbusiness";
$route['default_controller'] = "home";
$route['404_override'] = '';
I have the controller addyourbusiness set up but getting this page error:
Not Found
The requested URL /add-your-business was not found on this server.
Thanks for any help.
so the thing is I'm using .htaccess to hide the index.php but I still get the controller name in the url like that: http://example.com/name_controller/about
My question is: is it possible to hide the name of the controller, so that only method is shown? hxxp://example.com/name_controller/about
You can define a custom route in config/routes.php - for example:
$route['about'] = 'name_controller/about';
Then, http://example.com/about
goes to http://example.com/name_controller/about
See Hiding the controller’s method name in the URL? in the CI forums for more information.
You can add an entry in the /system/application/config/routes.php file:
$route['about'] = "controller_name/about";
$route['default_controller'] = "xxx";
home
$route['home'] = "xxx/home";
function_name/parameter0/parameter1/parameter2
$route['Collection/(:any)'] = "xxx/Collection/$1";
I did it like this: (config/routes.php)
Code:
$route['((photos|blogs).+)'] = "$1";
$route['([a-zA-Z0-9_-]+)'] = "user/profile/$1";
it is ok correct solutions for common.
You can add below code in the /application/config/routes.php file:
$route['default_controller'] = "Home";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['(?i)about'] = "Home/about";
$route['(?i)login'] = "Home/Login";
$route['(?i)products'] = "ProductController/ProductList";
$route['(?i)addproduct'] = "ProductController/AddProduct";
$route['(?i)editproduct'] = "ProductController/EditProduct";
$route['(?i)products/(:any)'] = "ProductController/ProductList/$1";//search product list perameters.
100% It work..