I have a application/controller/login.php file containing the following
class Login extends Controller {
function Login()
{
parent::Controller();
}
function index()
{
$this->mysmarty->assign('title', 'Login');
$this->mysmarty->assign('site_media', $this->config->item('site_media'));
$this->mysmarty->display('smarty.tpl');
}
}
My routes definition looks like the following:
$route['default_controller'] = "welcome";
$route['login'] = 'login';
$route['scaffolding_trigger'] = "";
The problem is that I keep getting a 404 when I try to access http://localhost/myapp/login. What did I do wrong? I've checked CI routes docs and cannot spot anything.
There shouldn't be anything wrong with this - does it work without the route?
Also, have you set the .htaccess properly (i.e. does http://localhost/myapp/index.php/login work instead)
Another point to keep in mind, if you have have "enable_query_strings" set to true and aren't using the .htaccess mod_rewrite rules:
In config/config.php:
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
The URL to route your request properly would look like this:
http://localhost/myapp/index.php?c=login
If you have not removed your index.php from your app using the .htaccess file, well thats another ball game on its own. But what you can do is this:
Set a default controller that's not the welcome file and if you want the welcome file to be your default use the link this way
http://localhost/myapp/index.php/login
Remember this way only works when the index.php file has not been removed using the .htaccess file.
Also open the apllication/config/config.php and use this code for the baseurl
$config['base_url'] = 'http://localhost/myapp';
That should always do the trick.
Related
I am currently under CodeIgniter 3.1.13, trying to root every single request to my Core controller. I'm starting CodeIgniter, I'm missing something as it didn't work.
I'm searching to get the bold part below as $1, and always aim the same controller.
site.com/ <- Working
site.com/test <- Working
site.com/test/test2 <- This one isn't working.
Here is my routes configuration :
$route['default_controller'] = 'Core';
$route['(:any)'] = 'Core/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = true;
I though (:any) would also handle that case.
Is there any way to do this properly ?
The Core controller is in \codeigniter\application\controllers directory.
I wonder if using REGEX couldn't work here. To be honest, I want to send the full part as $1 :
site.com/home/test/example
class Core extends CI_Controller {
// Below $page would be equal to "test/test2"
public function view($page = "index") {
}
Any idea ?
$route['default_controller'] = 'Student';
$route['admin'] = 'index.php/Admin_depart/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I am fairly new to CodeIgniter and finishing up my first project. However, before I put it up on my hosting site I would like to clean up the URL's using the routes.php file that CodeIgniter provides in the config folder. but it is not working it work correctly when i write same url i the default_controller
The index.php is causing the issue.
Route destinations must be defined only as a controller/method pair. So in your case the correct route would be:
$route['admin'] = 'Admin_depart/index';
anyone browsing to yoursite.com/admin would be served whatever is in your Admin_depart controller, index method (just as if he/she browsed directly to yoursite.com/admin_depart/index;
Hey I am having an issue routing to my other controllers in codeigniter.
Basically this is my base url http://localhost:8012/CodeIgniterProject/
This works fine but every time I type something after it I get an object not found error. I am trying to route to my Dashboard.php controller but having no luck. I want to type http://localhost:8012/CodeIgniterProject/dashboard and hit the Dashboard controller.
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['home/(:any)'] = "dashboard";
$route['(:any)'] = "";
$route['404_override'] = 'dashboard';
$route['Dashboard'] = "dashboard";
$route['about'] = "site/about";
I know this might be simple to other people but I don't usually work in php and this has me a little stumped. I was under the impression codeigniter would pick up dashboard from my controllers folder and got to my controller class to load it? And then if I wanted to pass params to the class etc I'd just need to add e.g /123??? Thanks for your time.
define method too, like:
$route['Dashboard'] = "dashboard/index";
I know the question has been asked many times but I really can't solve the issue.
My default controller is working, but if I want to access another controller I will have the 404 issue.
My controller file name has the upper case as Utilisateur.php,
So I'm trying to access the Controller function inscription by inscription
Here is my config:
$config['base_url'] = 'http://localhost:63342/WeBusy/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Here is my rooting:
$route['default_controller'] = 'accueil';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
And finally the controler:
class Utilisateur extends CI_Controller {
public function inscription(){
$data = array('header' => 'HeaderAccueil.php', 'body' => 'utilisateur/AjoutUtilForm.php');
$this->load->view('StructureHtml.php', $data);
}
Thanks
Give complete path to your anchor
inscription
But the best practice is to give dynamic url like using url helper or constants.
For Example if use url helper function your anchor path is like.
inscription
Don't forget to load url helper in your autoload file or your class constructor.
I found the issues,
So I needed to create a .htaccess file in the root of the applicaiton in order to remove the index.php AND this still doesn't work with phpstorm, maybe there is something to configure but it is working smoothly on EasyPhp :)
Check your controller filename, should be Utilisateur.php (ucfirst).
Check if your mod_rewrite works:
http://localhost:63342/WeBusy/index.php?q=utilisateur/inscription
add new method index() {die('test');} to your Utilisateur controller and change $route['default_controller'] = 'accueil'; to: $route['default_controller'] = 'utilisateur';
Structure of my controller directory:
--Controller
--frontend
--user_controller
When i call default controller it says 404 page not found
Route i have set :
$route['default_controller'] = "frontend/user_controller";
$route['admin_panel/site'] = "site";
$route['admin_panel'] = "backend/admin_controller/dashboard";
$route['admin_panel/login'] = "backend/admin_controller/index";
$route['admin_panel/(:any)'] = "backend/admin_controller/$1";
$route['admin_panel/(:any)/(.*)'] = "backend/admin_controller/$1/$2";
And when i run http://localhost/example/frontend/user_controller then it works.
So but didn't work this url : http://localhost/example
Please try with: move default controller at bottom
$route['admin_panel/site'] = "site";
$route['admin_panel'] = "backend/admin_controller/dashboard";
$route['admin_panel/login'] = "backend/admin_controller/index";
$route['admin_panel/(:any)'] = "backend/admin_controller/$1";
$route['admin_panel/(:any)/(.*)'] = "backend/admin_controller/$1/$2";
$route['default_controller'] = "frontend/user_controller";
Codeigniter will not allow default controller to be in a sub directory.
You have to rewrite it as
$route['default_controller'] = "user_controller";
And place that directly in the controller folder
You can refer this thread to avoid this. But I didn't tested it.
It is better to avoid the core functionalities as it may affect the updates.
I have not tested this but potentially you could use this to get around the sub-folder?
$route['frontend'] = 'frontend/user_controller';
$route['default_controller'] = 'frontend';
need to make sure there is a 'public function index()' in there though as you aren't specifying the method to load...