Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP sanitize utils

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?

like image 298
Max Frai Avatar asked Dec 10 '22 02:12

Max Frai


1 Answers

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);
   }
}
like image 200
dhofstet Avatar answered Dec 28 '22 07:12

dhofstet