1

I am new to CakePHP and I had trouble organizing my helper files. I searched through the web and doesn't seem to find an answer for this.

I have no problem using the helpers if I put them under app/Views/Helpers/test.

But when I put it under app/Views/Helpers/Global/test,

and

class AppController extends Controller {

public $helpers = array('Form', 'Html', 'Js', 'Time', 'Text', 'Session','Global/testHelper');

I get a "Cannot redeclare class testHelper"

Does anyone have any idea?

Oldskool
  • 34,211
  • 7
  • 53
  • 66
AbSoLution8
  • 1,203
  • 1
  • 18
  • 27

2 Answers2

1

The best way to organize and package your code is using Plugins.

You cannot have subfolders under your app's Helpers directory. But you can use App::build() to specify alternate locations for your helpers.

ADmad
  • 8,102
  • 16
  • 18
0

The error is pretty self explanatory. You can not literally call your helper TestHelper, as that name is already taken by the CakePHP Test Suite (defined in lib/Cake/Test/Case/View/HelperTest.php).

Just name your helper something else and you should be fine.

Oldskool
  • 34,211
  • 7
  • 53
  • 66
  • TestHelper is just an example that I used here. Sorry it was a bad example, but the real situation I used was SideMenuHelper. Any ideas on how to use helper classes in subdirectories? Is it supposed to just work? – AbSoLution8 Jan 12 '13 at 13:30