CakePHP 清理实用程序
我无法让它在我的控制器中工作。代码是:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CakePHP 2.x 中导入核心文件已更改,这意味着您必须将
App::import('Sanitize');
更改为App::uses('Sanitize', 'Utility' );
。还要删除$uses
语句,它用于加载模型,而Sanitize
不是模型。经过这些修改,您的代码片段将如下所示:
Importing core files has changed in CakePHP 2.x, which means you have to change
App::import('Sanitize');
toApp::uses('Sanitize', 'Utility');
. Also remove the$uses
statement, it's for loading models andSanitize
is not a model.With those modifications, your snippet will look like: