I moved cakephp installation to a different host and got this error(the code segment is the output I get including the php code, it is suggesting AppController would extend AppController):
Missing Method in AppController
Error: The action index is not defined in controller AppController
Error: Create AppController::index() in file: app/Controller/AppController.php.
<?php
class AppController extends AppController {
public function index() {
}
}
My database is now located on a different host altogether and I tested the remote connection and cake doesn't complain about that anymore. Any suggestions what could've caused this?
Related
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.
in my installation of php 5.5.9 on ubuntu 14.04 server, I get error when subclass is declared before parent.
testing.class.php
<?php
class mysubclass extends parentclass
{
}
class parentclass
{
}
myheader.inc.php
<?php
// empty header
index.php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'myheader.inc.php';
require_once 'testing.class.php';
echo "testing";
I get the following error
Fatal error: Cannot redeclare class mysubclass in /var/www/clients/client1/web3/web/central/try/php559/testing.class.php on line 4
when I replace the places of parent and subclass in testing.class.php I do not get the error.
The only possible explanation for this is that you have set up an autoloader. When PHP hits extends parentclass, it autoloads the file again to get its implementation, which also reloads mysubclass, which leads to the error.
You need to include/define/load parent classes before subclasses, there's no other way. Preferably every class should be defined in its own file as well.
after months, I found the source of the problem; it is not PHP, it is xcache. Since PHP 5.5 includes opcache, I was running both xcache and opcache on server. I uninstalled xcache and problem disappeared. I don't know which one is better, I prefer to use what comes with PHP.
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).
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.
I have downloaded Zend latest version(Zend Framework 1.11), then created the project using command line tool.
Also I've created controller in the created project. In the created controller Just I've added new method,
<?php
class UserController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
public function chatAction()
{
echo 'Test';
}
}
then tried to access in the browser
http://localhost/user/chat
I got the following error
Fatal error: Undefined class constant 'EXCEPTION_NO_ROUTE' in F:\xampp\htdocs\z_app\application\controllers\ErrorController.php on line 16
Thanks in advance.
You probably have the wrong zend library included.
Check your version via echo Zend_Version::VERSION; in index.php and die() before bootstrapping (as your mvc is broken).
You may need to update your include path to the correct location of the 1.11 zend framework library. Probably you have multiple versions (i.e. zend studio comes with its own) installed.
Thank you friends, Finally I resolved the issue by just copying the Zend directory inside of the library of Zend framework directory to my project directory. Now it is working.
F:\xampp\htdocs\zend\library
To
F:\xampp\htdocs\z_app\library
Even though I've added the include path in the php.ini to the zend framework library directory like below,
include_path = ".;F:\xampp\php\PEAR;F:\xampp\htdocs\zend\library
It wasn't working.