简体   繁体   English

在子目录中组织助手

[英]Organizing helpers in sub-directories

I am new to CakePHP and I had trouble organizing my helper files. 我是CakePHP的新手,在组织助手文件时遇到了麻烦。 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. 如果将助手放在app / Views / Helpers / test下,则使用它们没有问题。

But when I put it under app/Views/Helpers/Global/test, 但是当我将其放在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" 我收到“无法重新声明类testHelper”

Does anyone have any idea? 有人有什么主意吗?

The best way to organize and package your code is using Plugins . 组织和打包代码的最佳方法是使用Plugins

You cannot have subfolders under your app's Helpers directory. 您的应用程序的“助手”目录下不能有子文件夹。 But you can use App::build() to specify alternate locations for your helpers. 但是您可以使用App :: build()为助手指定备用位置。

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 ). 您不能从字面上调用您的助手TestHelper ,因为CakePHP测试套件已经使用了该名称(在lib/Cake/Test/Case/View/HelperTest.php )。

Just name your helper something else and you should be fine. 只是给您的助手命名其他名称,您就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM