Organizing helpers in sub-directories

227 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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.

1
On

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.