Welcome to the Cookbook

loading...

4.2 Oczyszanie danych

Klasa oczyszczania może być użyta do pozbycia się przesłanych przez użytkowników podejrzanych lub niechcianych informacji. Klasa ta jest wbudowaną biblioteczką, więc może być użyta gdziekolwiek w naszej aplikacji, ale najlepiej jeśli zrobimy to w kontrolerze lub modelu.

CakePHP already protects you against SQL Injection if you use CakePHP's ORM methods (such as find() and save()) and proper array notation (ie. array('field' => $value)) instead of raw SQL. For sanitization against XSS its generally better to save raw HTML in database without modification and sanitize at the time of output/display.

All you need to do is include the Sanitize core library (e.g. before the controller class definition):

App::import('Sanitize');

class MyController extends AppController {
    ...
    ...
}
  1. App::import('Sanitize');
  2. class MyController extends AppController {
  3. ...
  4. ...
  5. }

Once you've done that, you can make calls to Sanitize statically.