CakePHP sanitizes utils

I can not get it to work in my controller. The code:

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 did I miss?

+4
source share
1 answer

In CakePHP 2.x, the import of core files has been changed, which means that you need to change App::import('Sanitize'); on App::uses('Sanitize', 'Utility'); . Also remove the $uses statement, it is for loading models and Sanitize not a model.

With these changes, your snippet will look like this:

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

Source: https://habr.com/ru/post/1397204/


All Articles