CakePHP清理工具

时间:2012-02-18 15:29:28

标签: php cakephp controller

我无法在我的控制器中使用它。代码是:

 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);
       }
 }

我错过了什么?

1 个答案:

答案 0 :(得分:13)

在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);
   }
}