Codeigniter error on moving the website from localhost to server - php

We are using Code Igniter version 2.2 to develop an application. We have created it locally and it works fine however when uploaded onto the server we get the following error:
An Error Was Encountered
Unable to load the requested file: Abc/xyz.php
(file name changed for question)
Code in controller:
class Abc extends CI_Controller {
public function xyz(){
$this->load->view(__CLASS__."/".__FUNCTION__);
}
When I modify the code to the following the page appears:
class Abc extends CI_Controller {
public function xyz(){
$this->load->view("Abc/xyz");
}
How can I get the above code run using Class & Function?
Thanks for your time & efforts.

Can you use echo __CLASS__."/".__FUNCTION__ to debug this value on server.

Related

Codeigniter Model loading error

I had a working project uploaded to server 2 week before. It was working fine until now. Below is code for model awsmodel.php
class Awsmodel extends MY_Model {
function __construct()
{
}
// some other functions
}
MY_Model again extends to CI_model.
class MY_Model extends CI_Model {
// required functions
}
From controller pages.php I am calling the function like below.
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
$this->load->view('home_pz',$data);
}
}
The above code suddenly stooped working today. After some test and tries, I got to know that when I comment below 2 lines from controller function then The page loads.
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
I have changed environment variable to 'development' and tested but still no error message shows. In firefox its showing a blank page, where as in chrome it shows 500 server error. The same code was working since 2 weeks. Don't know why its not working now. If anyone can help me out ?
I am using CI version 2.1.4
If you using CI 3.0 please load model like this
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('awsmodel'); //as your model filename: awsmodel.php
$data['featured'] = $this->Awsmodel->featuredProp();
//$data['featured'] = $this->awsmodel->featuredProp();// for CI version 2.1.4 –
$this->load->view('home_pz',$data);
}
}

Unable to locate the model after upgrate

i started a website using codeigniter 3 -dev about couple of month ago , today i've upgrade it to latest version on github .... it works fine on localhost but when i upload it on server it couldn't find the models !!
http://epatil.com/ci_test
my only controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->model('test');
$this->test->echo_print();
$this->load->view('welcome_message');
}
}
my test.php model
<?php
class test extends CI_Model {
public function __construct(){
parent::__construct();
}
function echo_print(){
echo 1234;
}
}
her eis the result :
Unable to locate the model you have specified: Test
btw changing it's name to Test wouldn't help and it used to work fine with lowercase before upgrade
According to the version 3 user guide, the class names MUST match the file name, whereas this wasn't the case, in version 2.
http://www.codeigniter.com/userguide3/general/models.html#anatomy-of-a-model

CodeIgniter Loading Database Error

When using Codeigniter to load the database, I am getting the following error message in a simple file where I load the database:
An Error Was Encountered
Unable to load the requested class: database
The controller for this code is called db.php, and the code for it is as follows:
<?php
class Db extends MY_Controller {
function __construct() {
parent::__construct();
$this->load->library('database');
}
public function index() {}
}
I do not have the database loaded in to autoload.php. I also know that I have the correct database information in my config.php file. My CodeIgniter application is in a subdomain if that might cause any problems.
Any ideas on what could be causing the problem? Thanks.
Use $this->load->database();
Instead of $this->load->library('database');

changed default_controller gives 404 codeigniter

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.

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

Categories