I'm working on codeigniter. I want to ask that where should i check(Is it false? Come 0 record or more? vs.) data comes from db? In model or in controller? Now I check its in controller.
Depends on you logic and code style. I prefer do it in model with the data modification if need (mysql date to data/time), and return the result array. In this way you can write a clearer controller with less nested If methods, also in views echo foreach :)
The goal of the Model is to interact with the database: select
, insert
, update
, delete
[...] data. By the way, Model is not always a database. But it is, most of the time.
Following your needs, The first idea would be to do the check in the controller.
If you do not use the result got from your model for another treatment inside the controller. Do the check in the view. For instance, in the case you want to know if you have retrieve products from your database I prefer to do it in the view :
if( count($possibleData) > 0) {
foreach($possibleData as $values) {
// Show your data
}
}
else {
echo 'no products';
}
To conclude, I would not do the check in the Model. To me, both Controller and View are correct, but not inside the Model which the aim is just to get / push data.