Issue
I want to get all product related to 'products' table. But when $product_key blank ,the code will give errors. I want the blank array without elements. My code in the controller like that.
$ProductTable = TableRegistry::get('products');
$ProductData = $ProductTable->find('All') ->where(['product_key' => $product_key]) ->first() ->toArray();
Solution
You should put the {$ProductData} inside if condition like this:
$ProductTable = TableRegistry::get('products');
$ProductData = $ProductTable->find('All') ->where(['product_key' => $product_key]) ->first();
if($ProductData){
$ProductData = $ProductData->toArray();
}else{
$ProductData = [];
}
Answered By - amar9312
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.