X
X
Xintrea2014-10-03 13:34:25
Yii
Xintrea, 2014-10-03 13:34:25

Yii 1.xx Controllers, layouts and widgets... Which project structure should I choose?

The question is quite general, but I need to figure it out, because I'm just starting to master Yii.
* * *
I made the following application structure. To begin with, the terms in which I think.
- The page area (pageAreaName) is a "named" point in the main site layout. For example title , menu , info , text , bottom .
- Site area (siteAreaName) is the name of the site section. In fact, this is the controller ID. For example main , guestBook , newsArchive .
There is a basic page layout. This is pure HTML, it only "marks" the page areas ( pageAreaName ) as a call to the special widget CDrawPageArea :

<!-- Виджет меню -->
<?php $this->widget('CDrawPageArea', array('params'=>array(
         'pageAreaName'=>'menu', 
         'siteAreaName'=>Yii::app()->getController()->getId() ))); ?>

The CDrawPageArea widget (let's call it "intermediate"), based on the information in which place of the site and in which place of the page the call occurred (parameters pageAreaName and siteAreaName ), calls (according to tables) other "final" widgets, passing them information about pageAreaName and siteAreaName . Thus, the final widgets know in what place of the site and in what place of the page they are called. And they can change their behavior accordingly, if necessary. It is very comfortable. It is also convenient that the call table of "final" widgets is concentrated in one place, and the entire structure of the site is immediately visible.
The application execution sequence is as follows. The controller action is called, it has only one command - rendering an empty view. At the moment of rendering an empty view, the rendering of the main layout is called. And widgets are already called from it in the way described above.
* * *
However, this approach has problems:
1. The site must have CNC ( controller / action / Parameter name1 / value 1 / Parameter name 2 / value 2). No _GET parameters. Then in the controller, the action parameters can be obtained as function parameters. It's beautiful and right. But here's the question. How to transfer these parameters to the "final" widgets? In addition, the action parameters should not fall into all the "final" widgets, but only into those to which they are intended. For example, if you want to display the article articles/show/articreId/123 , then the articleId of 123 should only go to the "end" titleAreaDraw and textAreaDraw widgets , not the menuAreaDraw , bottomAreaDraw , etc. widgets.
Prescribing in the action code (in some format) information about which widgets the data should go to is ideologically wrong, because the entire sitemap is concentrated in one place - in the "intermediate" widget CDrawPageArea . And it is also wrong to prescribe where the data should go in the CDrawPageArea itself , because data with the same name (for example, pageNum) can arrive from different controllers, it is not clear how to distinguish them.
2.It is not clear how to use the advantages of Yii with such a structure. For example, user entry-exit and standard Yii access control at the controller level, because controllers in the structure I described essentially do nothing (all logic is in widgets). I get the impression that I'm somehow using Yii wrong. In the primitive blog that comes as an example, the site structure is spread over the controllers, and it is invisible, there is no control point (like I have in CDrawPageArea ). But for some reason, people use Yii "on the forehead". But you can't keep such a big project going. I took a wrong turn somewhere, but I don't know where. After all, a framework should not impose a [u]structure[/u] of building a site, it is just a tool with its own standards for designing code and directories, nothing more. But I don't understand what I'm doing wrong.
These are the two issues I want to address.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grechushnikov, 2014-10-03
@maxyc_webber

https://www.google.com/search?q=yii+boilerplate&gw...
more specifically yiinitializr.2amigos.us

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question