Codeigniter site working in MAMP but not LAMP - php

I am using MAMP to locally host my codeigniter project. Each of my controllers extends MY_Controller. MY_Controller looks like the following:
class MY_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->user_model->do_something();
}
}
Using MAMP, on my macbook, this works fine. However, when I upload my site to my linux server running apache, I get the following error:
Unable to locate the model you have specified: User_model
Why?
UPDATE
I changed the capitalization to be like this:
$this->load->model('User_model');
$this->User_model->do_something();
and the problem continues

Linux is a case-sensitive operating system, and as such you need to be really careful when developing on Windows and deploying to Linux.
Your issue stems from the line :
$this->user_model->do_something();
Which should be :
$this->User_model->do_something();
As it is the name of an object you are trying to access.
The line which loads it is fine, as CodeIgniter doesn't mind which case you use to load the models, but PHP will get somewhat picky on Linux when it comes to names of things.

Related

404 with Codeigniter 3 on LAMP, but however working on MAMP

I started a new project on CI3.
I developed it on my MB with MAMP. Everything works fine !
This afternoon I tried to publish the code on my VM serveur ( Ubuntu 18.04, php 7.2.19 ).
The welcome page works good, but impossible to use a routes.
localhost/index.php -> good
localhost/index.php/push/ -> 404 ( still working on MAMP )
I tried to use an .htacces, create a route in router.php file, ....
/application/controllers/api.php :
class Push extends REST_Controller{
public function _construct(){
....
}
public function index_post(...){
...
}
}
always a 404 NOT FOUND on LAMP only
The problem is that the Mac OS is case insensitive, but the Linux OS is case sensitive. CodeIgniter requires that file and class names match exactly and that they have an uppercase first character in the name with all other characters being lowercase. On a case insensitive system you can get away with ignoring that convention, but on a case sensitive system you cannot.
BTW, it is Controllers, Models, and Libraries that are case sensitive. In essence, any file that defines a PHP class.

How can I get CodeIgniter 2.1.4 to load my extended Controller Class?

I have looked for this answer all through stackoverflow and none have been able to help me.
my file name is: application/core/MY_Controller.php
class MY_Controller extends CI_Controller {
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
}
}
I made a post in this thread asking if anyone had found an answer. I tried everything in that thread, and in all suggested links.
I'm at a complete loss.
Everything works on my local WAMP server (apache 2.4 php 5.4) and not on the production server (Ubuntu 12.04, apache 2.4, php 5.5)
error:
PHP Fatal error: Class 'MY_Controller' not found in filepath/application/controllers/welcome.php on line 7.
Line 7 is where I define the class: class welcome extends MY_Controller {
EDIT
Thanks for all the help. I figured out what was wrong.
When I initially started trying to figure out this problem, I noticed that I did not have my case right on the name of MY_Controller.php, it was My_Controller.php.
So, what I found out was that even though I changed the name of the file on my local machine, when I uploaded it, the name still didn't change. So, when I went to change it to all lower case I decided to do that directly on the production server and found that after all this time it was still named with the lowercase y when I thought I had changed that. I hope this helps anyone else who migrates from a WAMP environment to a LAMP environment to know that even though the case is changed, it is still the same name, and may or may not be changed when you upload it.
please go to your application/config/config.php and on the bottom insert this code
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
#include_once( APPPATH . 'core/'. $class . EXT );
}
}
Now you are good to go.
please try creating file MY_Controller.php in /core folder with this body
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
$this->output->enable_profiler(TRUE);
}
}
and use welcome controller if it works.
I missed note: Everything works on my local WAMP server (apache 2.4 php 5.4) and not on the production server (Ubuntu 12.04, apache 2.4, php 5.5)
Please check your case of files/controllers
Please try editing/renaming everything in to lower case (even my_controller extends CI_Controller).

Extending Core Class Codeigniter - 500 Error

In my web app I'm extending the Codeigniter core using applicaiton/core/MY_controller as below:
class MY_Controller extends CI_Controller {
function __construct(){
parent::__construct();
}
}
And in my controller I have:
class Dashboard extends MY_Controller {
public function __construct(){
parent::__construct();
// Your own constructor code
}
public function index(){
}
}
This work perfectly on my localhost, however on my production server it returns a 500 error with an error message of "PHP Fatal error: Class 'MY_Controller' not found...".
PHP version on localhost is 5.4.10 and on production is 5.4.15.
I'm using the latest version of Codeigniter.
Thanks in advance!
You're developing under Windows (which is case-insensitive) and deploying on a UNIX-based host (which is case-sensitive). Rename MY_controller.php to MY_Controller.php, with a capital C.

CodeIgniter - Controller Double Inheritence Breaking When Deploying To Server

I really need some guidance here as this issue is pretty confusing and extremely different to understand for a beginner like myself.
I am running a WAMP server with the latest CI version.
In core/MY_Controller.php I have:
public GeneralController extend CI_Controller {
public GeneralController() {
parent::__construct();
// Does some stuff
}
}
public AuthenticatedController extend GeneralController {
public AuthenticatedController() {
parent::__construct();
if(!loggedIn()) redirect("/login");
// Does some stuff
}
}
public UnauthenticatedController extend GeneralController {
public UnauthenticatedController() {
parent::__construct();
if(loggedIn()) redirect("/home");
// Does some stuff
}
}
My login controller is:
class Login extends UnauthenticatedController {
So basically if they are logged in and load "/login" they will be routed to "/home".
This works perfectly on my local environment.
Once I upload it to my server and navigate to "/login" I get an infinite loop. After debugging I figured out that the Login controller loads AuthenticatedController instead of UnauthenticatedController so it keeps redirecting back to "/login" infinitely.
Well, now the inheritance is broken for some reason so I need to check if it calls both Auth and Unauth controllers. Nope. Just calls Auth even though it extends UnauthenticatedController.
I am at a loss here, I've tried everything I can imagine but as a new php programmer I thought I would pick some of your brains on things to try!
Thank you!
Solution:
Check your production server php version vs. local
I also had this problem with extending core classes. My problem was that is was working on my local server, but not on my production server. I was receiving the 404 error in production, and only on my controllers that used the class extensions. After some research I noticed that my local server was running php version 5.3.x, while my production server was running 5.2.x. To fix this I had to upgrade my production server to 5.3.
To find out what version of php your site is using, place this command in your view:
<?php echo phpversion() ?>

"PHP Fatal error: Class 'AppController' not found" running CakePHP 2.0.5 on Windows IIS7

I have a CakePHP (version 2.0.5) app that runs perfectly in my MAMP development environment. When I deploy it to a Windows IIS7 server I get the following error for any page I try to load:
PHP Fatal error: Class 'AppController' not found in
[my path]\app\Controller\PagesController.php on line 8
If I install a totally clean/new version of CakePHP version 2.0.5 to that IIS server, it runs without error. The IIS log file shows me nothing useful. Here's what the first few lines of PagesController.php looks like:
<?php
App::uses('AppController', 'Controller');
/**
* Pages Controller
*
* #property Page $Page
*/
class PagesController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('index','view','home');
}
...
I'm at a loss as to what else I can check. Any ideas?
And to pre-empt the inevitable "don't use Windows server" replies - if it were up to me, I wouldn't.
usually that is a 2.1 problem but take a look at:
http://book.cakephp.org/2.0/en/appendices/2-1-migration-guide.html
=> your controller has to be in your APP now (it is not part of the core anymore)- so just create one.

Categories