I'm just starting use CodeIgniter and I have created a controller called Dashboard, inside that I have the following method:
public function index()
{
$this->load->view('dashboard/home');
}
then I have defined inside the folder Views a folder called dashboard which have the following content:
then inside routes.php I have defined as default controller dashboard:
$route['default_controller'] = 'dashboard';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
when I start the application I get:
Unable to load the requested file: dashboard/home.php
that's weird because I have no upper case letter
Check .htaccess file inside the root folder of project.If .htaccess file not exist create .htacess file in root folder and add this below line.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Related
My CodeIgniter code in a subdirectory, so only index page is working when I hit any other request than it loading the parent folder index file.
Structure is:
Parent folder
index.php
sub folder / codeigniter set up
I have tried the htaccess code and request_uri in config.
I want to hit all my Codeigniter URL properly. Because on any request it loading the parent folder index.php file content.
Please set your .htaccess to this
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
And in the config use this
$base = "http://".$_SERVER['HTTP_HOST'];
$base .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base;
$config['index_page'] = '';
Hopefully it will work :)
in the config file set your base url to the hosting site
$config['base_url'] = 'http://whateverthesitepathis';
then in the routes do this
$route['default_controller'] = 'folder/controller';
$route['(:any)'] = 'folder/controller/$1';
I'm new in CodeIgniter and trying to create a simple link on Homepage but it is redirecting to localhost on WAMP Server, here is my code
autoload.php in config folder
$autoload['helper'] = array('html', 'url');
config.php in config folder
$config['base_url'] = 'http://localhost:8080/OTI-CI';
routes.php in config folder
$route['default_controller'] = 'site';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
here is my controller: site.php
class Site extends CI_Controller {
public function index() {
$this->home();
}
public function home() {
$this->load->view("header");
$this->load->view("content_home");
$this->load->view("footer");
}
}
here is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /OTI-CI/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
here is my view of header include a link like
Home
is there anything I'm missing about it?
In CodeIgniter 3.x version, you should capitalize Controllers, Libraries and Models name. Like that Site.php
Wrong:
/application/controllers/site.php
Right:
/application/controllers/Site.php
I created a project using CI(version 3.0.0), and it works perfectly in XAMPP localhost. And i upload that project to sub domain then its giving an error Click here.
I Handle Router's and config setting as well. So what is this error?? how to avoid this?? There are some answers, But not suit for this.
Config.php
$config['base_url'] = '';
$config['index_page'] = '';
Routes.php
$route['default_controller'] = 'shop';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Change the name of your controller, model, and other your class to Capitalize.
Example :
your own controller test.php change to Test.php
It should be work.
Its because your server is Linux, and Linux is case sensitive.
I'm a newbie to CodeIgniter. In my 'views' folder, I've created 2 PHP pages - home.php and register.php. I've also created the header and footer PHP pages in a templates folder.
Here is my pages.php code which is the controller class:
<?php
class Pages extends CI_Controller
{
public function view($page)
{
if(!file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
and here is my routes.php code:
$route['register'] = "pages/view/register";
$route['default_controller'] = 'pages/view/home';
I have not yet written anything into the .htaccess file.
My project home directory is 'ED'
I am able to navigate to the home page with this URL: http://localhost/ED
However I'm unable to navigate to the registration page with these URLs:
localhost/ED/register
or
localhost/ED/register.php
Please help as to how can I achieve this.
You have to have the index.php by default because according to CodeIgniter URLs
By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article
So if you want to remove the index.php, you can follow this simple step:
You can easily remove this file by using a .htaccess file with some
simple rules. Here is an example of such a file, using the "negative"
method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP
request other than those for index.php, images, and robots.txt is
treated as a request for your index.php file.
Just put your .htaccess file(with the mod rewrite) in you main appplication folder and voila it's done.
What I did with my .htaccess was this one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /name_of_your_codeigniter_folder/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
my page url is
http://example.com/ci/pages/portofolio
My roots in config/routes.php
$route['default_controller'] = "index";
$route['pages/(:any)'] = 'display/display_pages/$1';
$route['404_override'] = '';
My controller in controllers/display.php
class display extends MY_Controller{
function __construct(){
parent::__construct();
}
public function display_pages($seo_name){
echo $seo_name;
}
}
i receive this message
Not Found
The requested URL /ci/pages/portofolio was not found on this server.
Try removing $1 at the end of your route. Make it look like this :
$route['pages/(:any)'] = 'display/display_pages';
Your route.php is correct. The way you are printing the $seo_name is not.
public function display_pages(){
echo $this->uri->segment(3); // it will print $1
}
Check http://ellislab.com/codeigniter/user-guide/libraries/uri.html
The htaccess should be something like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>