4

I deployed my app on a remote host and everything works as expected. But when I try to test my code on localhost, it gives me the following error, without any change to the code working on the host:

Fatal error: Class 'AppHelper' not found in [path]

I am using CakePHP 2.1 and MySQL as my default datasource.

I connect to my local database just like to the remote one (with authentication changes):

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => '',
    'database' => 'database',
    'prefix' => '',
    'encoding' => 'utf8',
);

Why isn't this working on my localhost? Thank you

linkyndy
  • 17,038
  • 20
  • 114
  • 194
  • It is possible that you have a helper that is't in $helpers array in the Controller ?? Or a wrong route for a helper – Crsr Mar 07 '12 at 07:46
  • My helpers array looks like `public $helpers = array('Html', 'Form', 'Session', 'Js', 'Text', 'Time');`. Anyway, the thing is that on my remote host the same code works fine. – linkyndy Mar 07 '12 at 08:07
  • then verify your routes... remote != localhost ... it's another environment :) Anyway.. have a class that is extends in AppHelper ? (verify in helpers) If you have, change it in Helper. Teoreticaly, this erros is caused by two problems, wrong route or missing helper in helpers folder – Crsr Mar 07 '12 at 08:17
  • I don't have any custom helper. The only route I've added is `Router::parseExtensions('json');`, because I need the JsonView. Could that be the problem? – linkyndy Mar 07 '12 at 08:19
  • Add 'Json' to the $helpers array in the Controller because you don't have it and check your App::uses('AppHelper', 'View/Helper') for eliminate 'uses' problem – Crsr Mar 07 '12 at 08:34
  • I've added the Json to the helpers and still the same issue. Regarding the other part, where to check the App::uses()? – linkyndy Mar 07 '12 at 08:48
  • doesn't matter .. is't in a core.. it must be right. what is the [path] ? paste please first 20 lines from that helper (i suppose it's a json helper...) – Crsr Mar 07 '12 at 09:26
  • Please, switch to debug 2 and post full stack trace. – bancer Mar 07 '12 at 09:28
  • 1
    Figured it out. I was missing the AppHelper file from my app. I thought it was included in the Cake core. Thank you for all your help. – linkyndy Mar 07 '12 at 09:32

1 Answers1

5

Two possible things: either you didnt know about the AppHelper requirement for 2.1: http://book.cakephp.org/2.0/en/appendices/2-1-migration-guide.html

or you forget to declare the helper at the very top of your class:

 App::uses('AppHelper', 'View/Helper');

Although the second one is highly unlikely if you are not running any unit tests. So my bet is on the first one.

mark
  • 21,691
  • 3
  • 49
  • 71
  • That's right, I figured it out already, have posted in the question's comments :) Thank you anyway! – linkyndy Mar 07 '12 at 16:29
  • Ah, ok. But you should add the uses statement to your helper file, as well. It will break on test cases, otherwise. – mark Mar 07 '12 at 16:55
  • 1
    I don't have any custom helper files. This is what I added in the `AppHelper.php`: `App::uses('Helper', 'View'); class AppHelper extends Helper {}` – linkyndy Mar 07 '12 at 16:58