I'm migrating a CakePHP 1.3 app from an old server to a new one, the website works fine but the Shells fail with the following error:
PHP Fatal error: Class 'AppModel' not found
And the error points to the declaration of a model that extends from the AppModel class. It also somewhat strangely prints the contents of the AppModel class to stdout. Full stack trace below.
PHP Fatal error: Class 'AppModel' not found in /home/andyburchill/src/site/app/models/account.php on line 3
PHP Stack trace:
PHP 1. {main}() /home/andyburchill/src/site/cake/console/cake.php:0
PHP 2. ShellDispatcher->ShellDispatcher() /home/andyburchill/src/site/cake/console/cake.php:665
PHP 3. ShellDispatcher->dispatch() /home/andyburchill/src/site/cake/console/cake.php:139
PHP 4. Shell->initialize() /home/andyburchill/src/site/cake/console/cake.php:337
PHP 5. Shell->_loadModels() /home/andyburchill/src/site/cake/console/libs/shell.php:180
PHP 6. ClassRegistry->init() /home/andyburchill/src/site/cake/console/libs/shell.php:257
PHP 7. App->import() /home/andyburchill/src/site/cake/libs/class_registry.php:143
PHP 8. App->__find() /home/andyburchill/src/site/cake/libs/configure.php:962
PHP 9. App->__load() /home/andyburchill/src/site/cake/libs/configure.php:1043
PHP 10. require() /home/andyburchill/src/site/cake/libs/configure.php:1067
I'm running the shell from the root directory with the following command:
./cake/console/cake queue
The most notable difference between the servers is the PHP version, the shells are working on PHP 5.4.9 and are not working on PHP 5.5.9.
I have been googling this for a couple of days, usually people seem to get this error after upgrading to CakePHP 2.x and the fixes don't work for CakePHP 1.3.
I'm beginning to think the only solution is going to be upgrading to 2.x, but this is not a trivial task.
Is there something I can do in the mean time to get this working?, can anyone suggest troubleshooting tips?.
Ok I feel a bit silly now.
I had tried Raphael's suggestion of requiring the class file previously but I decided to try again and noticed that the AppModel class file started with a short open tag instead of <?php.
After changing it the shells now work.
Related
I am trying to initialize php unit testing with my wordpress plugin using phpunit. I am running xampp on windows. My xampp installation is also on my E: drive if that makes any difference. I am following along with this tutorial:
https://www.smashingmagazine.com/2017/12/automated-testing-wordpress-plugins-phpunit/
I have gotten to the part where I run
install-wp-tests.sh wordpress_test root '' localhost latest
I run that and it pops up and closes quickly, so I don't know if it is really working or not. I then try to run
phpunit tests/test-sample.php
and I get:
PHP Fatal error: Class 'WP_UnitTestCase' not found in E:\xampp\htdocs\wp-content\plugins\SRBC\tests\test-sample.php on line 11
Fatal error: Class 'WP_UnitTestCase' not found in E:\xampp\htdocs\wp-content\plugins\SRBC\tests\test-sample.php on line 11
I assume that means the install-wp-test.sh isn't installing correctly and it is missing those classes. Any ideas?
Ended up needing to install SVN for windows. Also had to add the mysqladmin.exe path to the PATH environment variable. Then finally needed this :
https://wordpress.stackexchange.com/questions/249402/error-when-setting-up-phpunit-tests-with-wp-cli-scaffold
And after all that and 3 hours! I got it to work correctly!
Hope this helps someone else.
I get the following exception while using Idea 13.1.3 with PHPUnit 4.5.0. In some other threads I have seen it was a bug but I this seems to be a problem with latest version also.
Testing started at 17:06 ...
Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest) in /private/var/folders/yc/cc0z8db95hx4l_d0fvtrx2yxsjjh3x/T/ide-phpunit.php on line 504
Call Stack:
0.0014 854704 1. {main}() /private/var/folders/yc/cc0z8db95hx4l_d0fvtrx2yxsjjh3x/T/ide-phpunit.php:0
Variables in local scope (#1):
$PHPUnitVersionId = *uninitialized*
Process finished with exit code 255
Found from IntelliJ forum that IntelliJ 13 is only compatible with PHPUnit 3.x.
However instead of downgrading, I managed to patch the framework itself for now in this way.
go to /plugins/php/lib
make a backup of php.jar
Use whatever tool you have to open the file, usually zip or other compress tools or under ubuntu the file roller.
Go to scripts/phpunit.php
Modify it, searching for the "IDE_PHPUnit_Framework_TestListener" class and adding there the following line:
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception
$e, $time) {}
save the file and update the php.jar
After following the user guide instructions found here: http://ellislab.com/codeigniter/user-guide/general/cli.html I'm unable to run the test script via command line.
My controller located at /var/www/mysite/application/controllers/
class Tools extends CI_Controller {
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
In my browser I can access
http://mysite/tools/message/ben
And the function correctly outputs "Hello ben"
From terminal I should be able to run:
$ php index.php tools message "Ben"
My terminal should print: "Hello Ben"
However I get the following error:
PHP Fatal error: Class 'CI_Controller' not found in /var/www/mysite/system/core/CodeIgniter.php on line 233
My server is pretty standard; ubuntu LAMP. Codeigniter is pretty standard too and I have no problem running non CI scripts via command line
My PHP binary is only located in /usr/bin/php <-- This post suggests an issue running CI directly from usr/bin/php, however I'm not operating a shared PHP service, and I don't see why this would make a difference to how PHP executes a CI script.
Any help or just an indication on how to debug this would be greatly appreciated.
Thanks in advance.
Solved! (partly) the issue was CodeIgniters error logging.
In application/config/config.php, I modified the following config property:
$config['log_threshold'] = 0;
This disables logging, and allows $ php index.php to execute.
If anyone can explain why CI only shows this error on CLI PHP - might help anyone else who has this issue and needs it resolved with error logging on.
To solve error "Class 'CI_Controller' not found" try going to Application -> Config -> database.php then check the database details like hostname, username, password and database.
To Mijahn:
I had this same problem, and after about two hours of tracing through code to figure out the problem, it seems that there is some sort of conflict with loading the CI_Controller when utilizing the native PHP load_class function.
I worked around this issue by making the following changes to the Common.php file (hack, I know).
//$_log =& load_class('Log');
require_once('system/libraries/Log.php');
$_log = new CI_Log();
My logs then where created exactly like I wanted. Hope this hack helps.
This site says to run codeigniter from the command line, one must set the $_SERVER['PATH_INFO'] variable.
$_SERVER['PATH_INFO'] is usually supplied by php when a web request is made. However, since we are calling this script from the command line, we need to emulate this small part of the environment as a web request.
The answer provided in this Stack Overflow post worked for me.
Within system/core/CodeIgniter.php, on around line 75, change:
set_error_handler('_exception_handler');
to...
set_exception_handler('_exception_handler');
Other users have reported that this gave them a better backtrace with which to debug the underlying issue, but for me, this actually removed the problem altogether.
I install ZF2 on my localhost and then I test the public page and it is work.
I tried to download a module MwopGuestbook and then zend show me an error:
Fatal error: Interface 'Zend\Module\Consumer\AutoloaderProvider' not
found in D:\xampp\htdocs\zend\module\MwopGuestbook\Module.php on line 8
How can we solve this problem?
Looks like outdated code there, I'm guessing that's an early incarnation of the Zend\ModuleManager\Feature\* implementations
If it is, you can try changing the first 7 lines in MwopGuestbook/Module.php to the following...
<?php
namespace MwopGuestbook;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
class Module implements AutoloaderProviderInterface
{
It should solve the complaints about not finding the interface, no guarantees there aren't other parts of that code using outdated calls though :-/
I am upgrading a site from Fedora 14, PHP4, and PEAR DB to Fedora 16, PHP 5.4 and PEAR MDB2 2.5.0b3, and I am getting the error
Fatal error: Call to undefined function: MDB2_Driver_MYSQL::getAll(). in /usr/share/php/MDB2.php on line 1892
Obviously, I've checked line 1892 of the MDB2.php file, and it contains the error reporting code for the __call magic method (allows you to call a specific function by passing it into __call)
I have checked for usages of __call, and there don't seem to be any. Likewise, when I try to find where MDB2_Driver_MYSQL is coming from, the only place it is even mentioned is in MDB2.php (as a comment about the driver for MySQL), in the class declaration (class MDB2_Driver_mysql extends MDB2_Driver_Common), and the description title in the .xml file.
I have manually included the /usr/share/php/MDB2/Extended.php file in the file where the MDB2_Driver_mysql class is defined, and that didn't help (not that this would have been a permanant fix...)
Has anyone encountered this error, and if so, what did you do to fix it? Google has proved nearly useless, as the only place it is specifically mentioned doesn't really deal with fixing it.
change getAll() in your class, to queryAll(), cause there some difference between DB & MDB2, and the same with getOne, getRow - they all changed to queryOne, queryRow. Here you can read about it http://www.phpied.com/db-2-mdb2/
Make sure you load the extended module in your code prior to making a query, similar to below:
$db->loadModule('Extended');