So basically, I would like to load a CodeIgniter controller contents outside CodeIgniter's environment, that is, from a traditional PHP page.
I have tried the following but it doesn't suit my requirements:
<?php
require('/application/controller/error?type=not_found');
?>
It gives the following error:
Message: require(/application/controller/error?type=not_found): failed to open stream: No such file or directory
To clarify, I'm trying to change the default /application/errors/error_404.php page contents to this so it will display the custom HTTP 404 error page I've built in the "error" controller & view.
The problem is, The pages under /application/errors/ are treated as normal PHP pages by CodeIgniter which means I can't use $this->load-view('error'); inside the error_404.php page.
I would also appreciate other suggestions for ways to create custom error pages in CodeIgniter.
You should set the 404 page in the route.php page in the application/config folder:
$route['404_override'] = 'your-error-controller/your-error-view';
This route will tell the Router what URI segments to use if those provided in the URL cannot be matched to a valid route.
I might be confused at your question but the routes.php gives you a place where you can point the 404 page to a custom view.
Related
I created a login website, and my URL became like this
http://localhost/koperasi/index.php/cukl/index
how to make my url like...
http://localhost/koperasi/index.php/cukl
because I want to make a crud program but I think I have a problem in the url
**
my previous program using http://localhost/lee/index.php/buku so my page can entered CRUD on http://localhost/lee/index.php/buku/ubah
but now my newer program url is http://localhost/koperasi/index.php/cukl/index
how and where to change the url? is in the controller? model? or view?
I think, firstly you have to add an htaccess file which will remove index.php in your URL.
and inside the route.php file, you can define a new URL which you want.
Like this.
$route['cukl'] = 'cukl/index';
I've got a Codeigniter 3 site where all my routes work except my home page route, which is like so:
<?php
$route['default_controller'] = "front/homepage";
?>
If I create a new route as below I can access it as "/home" but nothing works for index. I get an error in my log as 404 Page Not Found: /index, in my config i have index set to blank.
<?php
$route['home'] = "front/homepage";
?>
Any ideas?
Thanks
This is no-longer supported in Codeigniter since V2 due to it being a bug in the routing logic.
http://www.codeigniter.com/userguide3/installation/upgrade_300.html#directories-and-default-controller-404-override
I have set routes in routes.php for my default page but it shows a 404 error when opening localhost/mywebsite
$route['default_controller'] = "page";
$route['404_override'] = 'page';
I have set the above code in routes.php which gives a 404 error. The page controller has been created.
You need to make sure following things:
Webserver rewrite module is installed
htaccess file is properly configured
index function is present in page controller
You configured default controller & 404_override URL with the same value.
When ever you access to your web site automatically open page controller index function
ie ur_project_url/page/index
OR
ur_project_url/index.php/page/index
when ever you can get the 404 error also open same page controller index function
ie ur_project_url/page/index
OR
ur_project_url/index.php/page/index
please check your controllers and function and routes ,htacess file
please remove your url index.php using htacess
in config folder $config['log_threshold'] = 0; to $config['log_threshold'] = 1; check log files
On my local server, I have setup a website using Codeigniter which opens up fine using below URL
I have a different kind of query regarding rewriting URL
http://localhost/mywebsite
Actually the real URL is below
http://localhost/mywebsite/page/
Which I want it to work as root url as
http://localhost/mywebsite
So I have done it by adding it as default controller in config.php
But now I have another URL as
http://localhost/mywebsite/page/mypagename
Which should open as
http://localhost/mywebsite/mypagename
How can I do it?
You can define a custom route in /system/application/config/routes.php - for example:
$route['abc'] = 'controller_name/abc';
Then, http://mydemosite.com/abc
goes to http://mydemosite.com/controller_name/abc
see https://ellislab.com/codeigniter/user-guide/general/routing.html for more information of URI Routing.
I hope this can be helping you.
I got it solved using routing method as below under config/routes.php
$route['([^/]+)/?'] = 'page/$1';
I am very new to CodeIgniter Ion Auth, I was wondering if it is possible to add pages, outside the auth folder? the pages can be accessed only if the user is logged in. The main reason why I wanted the pages outside the auth folder is that I want to get rid of the "auth" in the url. Any help would be greatly appreciated. By the way, I only tried adding pages inside the auth folder. Thanks!
The short answer is Yes, you can. But if the reason is simply to remove the "auth" in the URL, the easiest way to achieve this is by using routes settings (located in the \application\config\routes.php file)
For example, if you set;
$route['login'] = 'auth/login';
The URL to the log in page will be;
http://yourdomain.com/index.php/login
You can go a step further by adding URL suffix in codeigniter config settings ( \application\config\config.php)
$config['url_suffix'] = '.html';
so that the URL to the log in page will be;
http://yourdomain.com/index.php/login.html
You can even remove the /index.php part of the URL. See this forum here