E
E
EVOSandru62015-08-12 12:28:54
Yii
EVOSandru6, 2015-08-12 12:28:54

How to check if a model is a single instance or a collection in yii?

Good afternoon,
How to catch the difference between the two models in the code?
$model = Cars::model()->findAll(); // there can be 1 - up to infinity of entries
and
$model = Cars::model()->findByPk();
This is necessary in order - to use or not use foreach in a certain place ;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maximw, 2015-08-12
@maximw

is_array()
But in general, if such a problem arose, then its solution is a crutch. This should not be, these are problems in the application architecture.

C
corpsepk, 2015-08-12
@corpsepk

Write $models = Cars::model()->findAll();, don't you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question