We did a fresh install of codeigniter 3.0.6 in our hosting and everytime we are changing
$route['default_controller'] = 'welcome';
to
$route['default_controller'] = 'home';
we are receiving a 404 error message.
Does anyone know how to fix this?
CodeIgniter 3.0+ has changed there naming conversations.
In your image your controller name define as home.php. Check first letter. Its should be caps.
change home.php to Home.php
Inside Home.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
}
Related
Controllers/home.php code is:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->load->view('index');
}
}
?>
Config/routes.php code is:
$route['default_controller'] = 'home';
This code is for view only index page. I create folder in views named pitanja, and several pages in that folder. Problem is when i click on site on that pages, i get error 404 page. Where i miss?
$this->load->view('pitanja/index');// relative to APPPATH.'views' directory
Just store pitanja folder with application|system|user_guid and it will display pages. Solved!
I am new to coding and have fallen in love with codeigniter and recently moved from a wamp server to a LAMP server. I've extracted codeigniter into /var/www/ and set the root directory of the host in apache. I can see the codeigniter welcome page, however if I change the default controller in config.php to my controller and load this controller:
class Site extends CI_Controller {
public function index() {
$this->load->view('home_view');
}
}
I get this text in my browser:
$this -> load -> view ('home_view'); }}
The only line of my index function as well as a codeigniter generated 404 error below it.
base_url() and default controller are set, codeigniter welcome page works fine, but my page does not.
Does anyone have an idea as to why? Your help is very much appreciated.
Make sure your controller is inside application/controllers and the name is site.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('home_view');
}
}
I also done a single webpage into the codeigniter.
But performing "href" it doesn't works.
Give a solution for how to include whole site into the codeigniter.
I think may be i need to create controller(into the directory) files for each and every view(into the directory) files.
Note : My whole templates are in the "view/pages" folder.
i already created "pages.php" in controller folder.
After changing route.php it only works on index.php. not for all other pages when perform links from index page.
My pages.php code is below
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller
{
function view()
{
$this->load->view('templates/header.php');
$this->load->view('pages/index');
//$this->load->view('pages/login');
$this->load->view('templates/footer.php');
}
}
?>
I dont understand you. Do you mean something like this?
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller
{
function index()
{
$this->load->view('templates/header.php');
$this->load->view('pages/index');
//$this->load->view('pages/login');
$this->load->view('templates/footer.php');
}
function aboutUs()
{
$this->load->view('templates/header.php');
$this->load->view('pages/aboutUs');
$this->load->view('templates/footer.php');
}
}
?>
In this way you reach your index page through www.yourserver.ext/pages/ (or www.yourserver.ext/pages/index) and, for example, your about us page through www.yourserver.ext/pages/aboutUs
Also you can set a param and load the page depending on it
I have some codeigniter application. It works well on my local server. After I uploaded it to the hosting server it won't work and resulting an error:
Fatal error: Class 'System_Controller' not found in /home/k2113138/public_html/test/application/controllers/login.php on line 3
Here is my System Controller that extending CI_Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//location: application/core/
class System_Controller extends CI_Controller {
public function __construct(){
parent::__construct();
//some code
}
}
my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//location: application/controllers/
class Login extends System_Controller {
public function __construct()
{
parent::__construct();
}
}
i have set my config as my desired configuration like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['base_url'] = 'http://xx.com/subfolder/';
$config['subclass_prefix'] = 'System_';
?>
I have read many article that discuss this matter but still cannot found the solution. Really confuse about the problem, because everything works well in local server. I have configured the config file as what it's needed like the database and the routes configuration. Is there any other things that i need to re-configure?
EDIT: My Codeigniter version is 2.1.3
Ok, you changed the filename to lowercase, now, try change the classname too:
class system_controller extends CI_Controller
If don't run, play with the classname and the filename, this is a problem of your server, very common in shared servers.
Sometimes, the PHP version and its configuration, play a important rol in this cases.
This is my first hmvc attempt and it's going wrong... I'm trying to separate my site zones through different modules. My intention then is control the access using ion_auth for hmvc. Thats my initial structure:
/application
/modules <-- hmvc
/public_zone
/controller
public_zone.php
/view
...
/private_zone
...
So, to do this (being installed hmvc on core and third_party folders) I tried to setup as 'default_controller' the 'public_zone' controller. His mission is load the root page ('localhost'), but *it returns a 404 error.*
This is my public_zone.php file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Public_zone extends MX_Controller {
public function index()
{
$this->load->view('include/header');
$this->load->view('frontpage');
$this->load->view('include/footer');
}
}
Maybe the problem is on routes.php (application/config/routes.php) file? I'll tried this:
$route['default_controller'] = "public_zone";
$route['404_override'] = '';
Anyone can tell me what Im doing wrong? For sure I misunderstood some hmvc concept... But the fact is I don't know why it doesn't works :(
First, it's important that you leave the CI structure intact.
So you need the structure:
/application
/controllers
public_zone.php
/views
frontpage.php
/include
header.php
footer.php
/models
Ofcourse, you need also the other folders that comes with CI.
Second, you need some changes in the controller in order to make it work.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Public_zone extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('include/header');
$this->load->view('frontpage');
$this->load->view('include/footer');
}
}
After this changes it's supposed to work :)
Be also sure to read the user guide: http://codeigniter.com/user_guide/
It might cost you some time to read, but later it will save you a lot of time.
Good luck!