php - how to check or declare array values of an array like an instanceof a Class/Entity -


in symfony project have array $productcontainer values (php dump):

array:2 [▼   0 => "value1"   1 => "value2" ] 

i pass array in product entity findby method in controller this:

$products = $this->getdoctrine()->getrepository('mybundle:product')                                 ->findbyvalue($productcontainer); 

the results between findby method , array values match well.

but when check if array an instance of class product this:

dump($products instanceof product); die; 

it retuns me : false

i understand $products array , not object, how can declare array $products instanceof product entity ?

edit

in order more precise, need declare or check if values of array $products instanceof product because in same controller, have pass array $products in querybuilder entity this:

$entity = $this->getdoctrine()->getrepository('mybundle:entity')                               ->getentitywithproducts($slug, $products); 

i recover array $products $_post method (request $request) controller method retun jsonresponse, why proceed in way.

try findonebyvalue instead findbyvalue if need 1 product.
or extract 1 element received array, because receive array of entities after invoking findbyvalue.
or traverse elements in received array check them.
or maybe in product repository present method findbyvalue staff you.

but anyway sounds strange check after doctrine returns appropriate class instance...
if use getarrayresult you'll receive array, otherwise you'll receive instance of appropriate entity.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -