CakePHP 清理实用程序

发布于 2025-01-06 16:44:30 字数 470 浏览 1 评论 0原文

我无法让它在我的控制器中工作。代码是:

 App::import('Sanitize');
 class MyController extends AppController
 {
       public $uses = array('Sanitize');
       function Foo()
       {
             // Fatal error: Class 'Sanitize' not found
             $test = Sanitize::paranoid($data);
             // Fatal error: Call to a member function paranoid() on a non-object
             $test = $this->sanitize->paranoid($data);
       }
 }

我错过了什么?

I can't get it works in my controller. The code is:

 App::import('Sanitize');
 class MyController extends AppController
 {
       public $uses = array('Sanitize');
       function Foo()
       {
             // Fatal error: Class 'Sanitize' not found
             $test = Sanitize::paranoid($data);
             // Fatal error: Call to a member function paranoid() on a non-object
             $test = $this->sanitize->paranoid($data);
       }
 }

What have I missed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

德意的啸 2025-01-13 16:44:30

CakePHP 2.x 中导入核心文件已更改,这意味着您必须将 App::import('Sanitize'); 更改为 App::uses('Sanitize', 'Utility' );。还要删除 $uses 语句,它用于加载模型,而 Sanitize 不是模型。

经过这些修改,您的代码片段将如下所示:

App::uses('Sanitize', 'Utility');
class MyController extends AppController
{
   function Foo()
   {
         $test = Sanitize::paranoid($data);
   }
}

Importing core files has changed in CakePHP 2.x, which means you have to change App::import('Sanitize'); to App::uses('Sanitize', 'Utility');. Also remove the $uses statement, it's for loading models and Sanitize is not a model.

With those modifications, your snippet will look like:

App::uses('Sanitize', 'Utility');
class MyController extends AppController
{
   function Foo()
   {
         $test = Sanitize::paranoid($data);
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文