Set a condition to get all the pictures with the extension * .png from the database.

Method:

public function getFotoByParentIdWithPng () { $asutpService = $this->getAsutpRepository(); $foto = ['parentId' => '2', 'image' => 'sh1.png']; return $asutpService->findBy($foto); } 

it returns from the database all the names of pictures that meet two criteria.

How to correctly write the second criterion in the array, so that all files with the .png extension are output , and not just like the one sh1.png file now ?

    2 answers 2

    Try this:

     'image' => 'LIKE "%.png"' 
    • Unfortunately, Zend does not understand this design. I have already tried. - Nikolai Gromov

    In order not to write a custom query, I used the standard Doctrin method findBy. It turned out so

     public function getFotoByParentIdWithPng ($menuId) 

    {$ asutpService = $ this-> getAsutpRepository ();

     return $asutpService->findByParentId($menuId); 

    }

    And already in the view or in the view helper (depending on where you will use this query), loop through the object with the condition

     foreach ($this->thumb as $item) { if (preg_match('/[az][0-9]+\.[png]+/i', $item['image'] )) { return $item; } }