V
V
Vlad Sharikov2014-05-08 13:08:00
Zend Framework
Vlad Sharikov, 2014-05-08 13:08:00

How to organize a module so that it can be conveniently administered?

Hello. I want to make a news module, because I did not find a ready-made solution (there are blogs, yes). The tasks of the module are clear from the name.
The question arises how to administer it later. In the admin panel in the "News" section, it is clear that there will be some kind of list of news, you can click on the news and edit it. I would like to add the ability to preview the news, that is, show the title, text of the news and tags, but without comments, likes and other garbage, which should be in the normal view of the news for a visitor to the site.
That is, the content of the news for the visitor: title, news text, tags, comments, likes.
For preview: title, text, tags, but without comments and likes.
An action like fullAction() will be responsible for receiving the news by the user, and something like editAction() for editing. Different controllers, different views.
The problem is that you have to copy-paste the view of one action into the view of another. And if you edit duck in general tin. If you change something in one, you will have to change in the other.
As a result, the question is: how to organize such a module so that you do not need to copy views (because this is not cool and finally) or how you can connect another in one view. And make, as it were, another view, a helper, in which pure news will be displayed, in edit just display this helper, and in full display helper + comments + something else (the word helper is used without understanding what helpers mean in zf2, just makes sense, it seems).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2014-05-08
@viktorvsk

Well, in general, what you describe looks like a partial template engine
. I'm not familiar with php. In Rails, everything is clear.
In php, the simplest "partials" I got like this:

class View{
public function render($template, $locals=array()){
ob_start();
extract($locals);
$View = new View();
include("/path/to/partials/${template}.php");
return ob_get_clean();
}
}

fullAction:
It is possible to render a partial within a partial.
I will only note that the decision is terrible, because. not really on topic. But in Rails, the form builder helpers and templating engines solve these things. I think in any php framework there is something similar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question