Let's say that model insert data to database.
class Model
{
public function insert($value) {
// putting $value to database to integer field
}
}
I want to convert $value
to int by (int) $value
to prevent the insertion of the non-numeric value.
Where should I do this? In model method or in controller?
class Controller
{
public function indexAction() {
$model = new Model;
$model->insert($_POST['user_id']);
}
}
integer
, it'll just work with it the same way and convert implicitly when actually necessary.Controller just takes user input and provides data to a model. Controller shouldn't know nothing about databases and storing formats. Theoretically you can change one DB to another with another data types and it will be problem of your model, not controller.
you should have to do it in controller only... bcz this is best practice i can say...
so from controller you can convert $value
in to (int) form and send
you can do it in controller
$data = (int) $value;
$model->interst($data);