changed default_controller gives 404 codeigniter - php

I am using codeigniter 2.1.2, WAMP, im just learning it and encountered a problem.
all i did was following
-> created a view "home.php" with some text in it.
-> created a controller "homecontroller.php" as follows:
<?php
class homecontroller extends CI_Controller{
function iloadhomepage(){
$this->load->view('home');
}
}
up till here it works fine when i run
"http://localhost/CodeIgniterTut/index.php/homecontroller/iloadhomepage"
next I changed the default controller in "routes.php" (in config) to
$route['default_controller'] = "homecontroller";
so that when i run "http://localhost/CodeIgniterTut/index.php" i would get my "home.php"
but rather im getting a 404 error, am i doing a mistake anywhere? please help

put this in homecontroller.php
class Homecontroller extends CI_Controller{
public function index(){
$this->load->view('home');
}
then type localhost/CodeIgniterTut/index.php,and also make every class name begin with a capital letter (thats a standard of coding).
"The "index" function is always loaded by default if the second segment of the URI is empty,The second segment of the URI determines which function in the controller gets called". according to ci manual.

Related

CodeIgniter Model Locate Issue After Upload to server

After Hosting Php codeignitor website I Got a Error "Unable to locate the model you have specified: Common_model"
But Its Works in my local server
How I can solve this issue
I already change First letter of the model class name capitalized but no result
my model class
class Common_model extends CI_Model
{
}
and controller is
<?php
class Show extends CI_Controller
{ var $pageLimit = 6;
public function __construct()
{
parent::__construct();
$this->load->library('ion_auth');
$this->load->model('common/Common_model');
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('custom');
}
}
If you are are using Codeignitor 3 than make sure you file name also start with capital letter as:
Common_model.php
It's recommended to use your models inside the model folder not model/anyfolder
Codeignitor 3 Change Log User Manual
I hope Your model file structure is like
application
model
common
Common_model.php
File name should be Common_model.php.
Load in Controller should be
$this->load->model('common_model');
I always load it with the name only, this way
$this->load->model('Common_model');
Always the controller is on the same module (if you are using modules)

Controller can't find requested when calling a standard action in Yii 1.x

While trying to execute a standard Yii action, I'm getting an exception, that HotelController cannot find the requested view hotellist.
My controller code is (important parts):
class HotelController extends Controller
{
public $defaultAction = 'HotelList';
public function actionHotelList()
{
$model = new HotelRev;
$this->render('hotellist', array('model'=>$model));
}
}
What am I missing or doing wrong?
I found the problem - the first letter of the directory created in protected/views cannot start with a capital letter (on Linux systems anyway).
if views/Hotel than make them views/hotel

cakephp controller not working; view page not found

i installed fresh cakephp. its app controller working fine. but when i write my controller and its view but this result in page not found. My code is given below
class PostsController extends Controller {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
and create folder named Posts in view folder and over there create index.ctp file as well. but its result in page not found. Please help what may be mistake by me or is there any need to configuration. Thanks
Your controller should be named PostsController.php (ie plural)
Just spotted it, you need to extend AppController in CakePHP 2.x, not Controller: ie:
class PostsController extends AppController {
there might problem apache rewrite module. if you are using WAMP, just put on your rewrite module.

PHP Codeigniter with Apache on alpine linux

i have written a small codeigniter test app that is currently running on my windows box.
i created a linux vm and have tried to install the app on this new virtual server.
some of my web app is running properly but other parts, no.
specifically, this works:
http://123.123.123.123/myapp/controller1/
but this does not:
http://123.123.123.123/myapp/controller2/mymethod/1/2/3
It fails with an error that it can't load controller2_model.
Here's the actual code for the controller that is failing (it's really called xferLogger vs. controller2):
class xferLogger extends CI_Controller {
public function __construct() {
parent::__construct();
echo(2);
$this->load->model('xferLogger_model');
$this->load->helper('date'); //this library is needed for the base_url() method that is being called in the view "result.php"
$this->load->helper('url');
}
and here's the model:
class xferLogger_model extends CI_Model {
public function __construct() {
$this->load->database();
}
The full error message is: An error was encountered. Unable to locate the model you have specified: xferlogger_model.
Here's something I noticed. in the error message, you'll notice that the "L" in logger is lowercase. but in my code, it's a capital L.
I've checked in my controller, the model itself, and also the routes.php file. I can't seem to find any problems with my casing.
??
From the userguide: Class names must have the first letter capitalized with the rest of the name lowercase. So therefore:
class Xferlogger_model extends CI_Model // First letter capitalised
and your model load
$this->load->model('xferlogger_model'); // lower case
and your PHP filename
xferlogger_model.php // lower case
Codeigniter Model Userguide

Can't access a Codeigniter controller in sub folder

I have set up a folder with a controller in it: controllers/admin/home.php, but I get a 404 from the browser when I try to access it.
This is my routes file:
$route['employers'] = "employers/home";
//$route['employers/dash'] = "employers/dash";
$route['default_controller'] = "home";
$route['404_override'] = '';
This is the controller file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class home extends CI_Controller {
function __construct(){
parent::__construct();
/*
enable profiler
*/
//$this->output->enable_profiler(TRUE);
$this->load->helper('url');
$this->load->library('ion_auth');
$this->load->library('session');
$this->load->library('form_validation');
$this->load->helper('layout');
}
}
.htaccess seems fine standard. Any ideas on what i'm doing wrong?
Note some things:
1) Routes are executed in the order they're written, and your custom routes MUST follow the default ones. So, it should be:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['employers'] = "employers/home";
This if your controller "home" is inside the folder "employers".
2) Controllers don't need all that stuff you wrote, indeed you don't even need to call the parent constructor unless you're planning to load libraries and resource for the whole controller's methods (which can be achieve also by autoloading them in the autoload.php file), so it could simply be:
file: application/controllers/employers/home.php
class Home extends CI_Controller {
function index()
{
// this is the method you're calling with your URL!
}
}
3) As per above, and as already pointed out by #Wesley, with your url you're trying to access the INDEX method of your controller HOME in your subfolder EMPLOYERS. But you didn't defined an index() method (which is the one called by default if no other is supplied).
It seems, instead, that CI is trying to look for an employers controller and a home method; if it doesnt find it, but you have a employers folder, it tries to access the index method in the home controller in the employers folder. And, since it didn't find it either, you're getting the 404 page.
Hope I'm clear, otherwise just ask.
You failed to say how you were trying to access it via url. It should be:
{YOUR_BASE_URL}admin/home
... followed by optional URL segments (/method/param1/param2/etc).
Without the additional segments, this would by default load the index method. However, since you don't have any methods defined, there's nothing to load.
If this still fails after you define a method, move the controller file out of the sub-directory for starters, and make sure it works.

Categories