P
P
Petr Fronin2016-03-15 18:52:53
Yii
Petr Fronin, 2016-03-15 18:52:53

Yii2 how to escape data written to the database?

Example:

$message = new Messages();
$message->message = $this->message;
$message->save()

$this->message; - data entered by the user

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Bay, 2016-03-15
@amar_std

1) When writing data to the database using AR , the lines are escaped. Those. you won't have sql injection there.
You can clear tags in two ways:
1) when displayed in a view, for example:
2) Clear using Htmlpurify, in the beforeSave method, for example:

$this->content = HtmlPurifier::process($this->content) ;

D
Dmitry Voronkov, 2016-03-15
@DmitryVoronkov

Do whatever you want with the data, with the help of validators (I just didn't understand what you meant by "escaping").

A
Alexander Makarov, 2016-03-15
@SamDark

No way. Use parameters (prepared statements).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question