V
V
Vlad2019-02-12 15:28:29
PHP
Vlad, 2019-02-12 15:28:29

Beautiful photo output script. What is the best way to create a link to an image?

Hello. For the sake of interest, I wrote the output of pictures as in user posts on the wall vk, fb, etc.
Now I want to brush it all up and put it in free use on github. There was a question how it is better to make creation of links to pictures.
At the moment there are two ideas:

  1. By inheriting the main class. (Everyone will create a function in which he himself will draw a link, taking into account his needs)
  2. Create a link when adding an image to a class.

First option.
class MyPhotoLayout extend PhotoLayout 
{
// Функция пользователя для создания ссылки. Вызывается из основного класса.
public function createLink(Item $item)
    {
        $data = $item->getData(); // Данные пользователя, при добавлении Item
        // Создание пользователем ссылки на картинку
        // <a href="/photo/id/'.$data->getId().'" onclick=""> или же подобное
    }
}

   $photo_layout = new MyPhotoLayout();

    $item = new Item();
    $item->setData(''); // Данные пользователя, для построения ссылки в классе // Например PhotoItem

    $photo_layout->addItem($item);

Second option
$photo_layout = new PhotoLayout();

    $item = new Item();
    $item->setLink('link');
    $item->setOnclick('js');

    $photo_layout->addItem($item);

What do you advise, which option is preferable, which option is more correct from the point of view of the Open Source library?
Perhaps you can suggest a better solution?
PS work example
5c62c6ba24ce9886900329.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-02-12
@Compolomus

Do not mix logic and presentation, the first option is better, but again, the link is on the side of the controller and the request. Generation on the fly or with saving somewhere?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question