How to alter the string?

Hello.
I have a simple, but I that was confused.
I used to have in view was the image display
<img src="<?= $this->url('application', ['action'=>'file'], 
 ['query'=>['name'=>$foto], 'thumbnail'=>true]); ?>" alt class="d-block w-100" data-toggle="modal" data-target="#exampleModal">

now I bring it into helper types and I need to change this line under php.
Should be something like this
$result .= '<img src="'.('application', ['action'=>'file'],
 ['query'=>['name'=>$escapeHtml($foto)], 'thumbnail'=>true]).'" alt class="d-block w-100" data-toggle="modal" data-target="#exampleModal">';

The method $this->url() in the helper not if at the same time tell me how to get it there, I would be very grateful.
June 5th 19 at 21:23
2 answers
June 5th 19 at 21:25
not very clear what you want, although you would have written frameworks and libraries you use
Use Zend Framework3. - Corrine commented on June 5th 19 at 21:28
June 5th 19 at 21:27
You need to pass, or just the url in the widget (helper species)
Example:
https://olegkrivtsov.github.io/using-zend-framewor...
I need the widget to register the address of the photos. - Corrine commented on June 5th 19 at 21:30
well , so pass in the array with addresses in the widget. All the same as in the example on the link. - Corrine commented on June 5th 19 at 21:33
There is an array of addresses. What do you suggest I used for the menu. View the link for the same book just a different partition. I have passed to address just the file name. - Henderson_Beat commented on June 5th 19 at 21:36
Why the book? You better give your code. The whole object, not pieces - Corrine commented on June 5th 19 at 21:39
Yes no question))
In IndexController is a DB query to get all photos meet the criteria.
namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;



class IndexController extends AbstractActionController
{
/**
 * Traits.
*/
 use \Fork\Zend\ServiceManager\Traits\ServiceManagerAwareTrait;
 use \Application\Service\Traits\AsutpServiceAwareTrait;
 use \Application\Service\Traits\MenuServiceAwareTrait;
 use \Application\Service\Traits\FotoServiceAwareTrait;


 public function indexAction()
{
 $menu = $this->getMenuService()->getMenu();
 $viewModel = new ViewModel(['menu' => $menu]);
 return $viewModel;
}

 public function asutpAction()
{
 $menuId = $this->params()->fromRoute('id', -1);
 $foto = $this->getAsutpService()->getFotoByParentId($menuId);
 $menu = $this->getMenuService()->getMenu();
 $files = $this->getFotoService()->getSavedFiles();
 /**$debugObject = $foto;
// $debugObject = array_keys($debugObject);
 if (is_object($debugObject)) {
 \Zend\Debug\Debug::dump(get_class_vars(get_class($debugObject)) + get_class_methods($debugObject), '<p style="color:blue">' . get_class($debugObject) . '</p>');
}
 else {
\Zend\Debug\Debug::dump($debugObject);
}*/
 $viewModel = new ViewModel(['foto' => $foto,
 'menu' => $menu,
 'files' => $files]);

 return $viewModel;
 }

The resulting object returned in the view.
In the view process object and an array to pass it as a widget
$thumb = [];

 foreach ($foto as $f)
{
 $thumb[] = $f;
}
 $this->miniFoto()->setThumb($thumb, $files);
 echo $this->miniFoto()->render();


Well the widget itself.
namespace Application\View\Helper;

use Zend\View\Helper\AbstractHelper;


class Thumb extends AbstractHelper
{
/**
 * Thumb-Menu array.
 * @var array
*/
 protected $thumb;

 protected $files;

/**
 * Constructor.
 * @param array $thumb Thumb Thumb.
*/
 public function __construct($thumb=[], $files=[])
{
 $this->thumb = $thumb;
 $this->files = $files;
}

/**
 * Sets the thumb thumb.
 * @param array $thumb Thumb Thumb.
*/
 public function setThumb($thumb)
{
 $this->thumb = $thumb;

}

 public function render()
{
 if (count($this->thumb)==0)
 return "; // Do nothing if there are no items.

 $result = '<div class="col-2">';
 $result .= '<div class="row">';
 $result .= '<div class="col">';
 $result .= '<p class="text-center">Examples of projects</p>';
 $result .= '</div>';
 $result .= '</div>';

 // Render elements

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

 $result .= '</div>';

 return $result;
}

 protected function renderItem($item)
{
 $image = isset($item['image']) ? $item['image'] : ";
 $foto = ";
 foreach ($this->files as $file)
{
 if ($image == $file)
{
 $foto = $file;
}
}
var_dump($foto);
 $result = ";

 $escapeHtml = $this->getView()->plugin('escapeHtml');

 $result .= '<div class="row">';
 $result .= '<div class="col mb-1">';
 $result .= '<img src="'.('application', ['action'=>'file'],
 ['query'=>['name'=>$escapeHtml($foto)], 'thumbnail'=>true]).'" alt class="d-block w-100" data-toggle="modal" data-target="#exampleModal">';
 $result .= '</div>';
 $result .= '</div>';


 return $result;
}
}
- Henderson_Beat commented on June 5th 19 at 21:42

Find more questions by tags Zend Framework