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?
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With