D
D
DarkByte20152017-10-18 10:11:35
Yii
DarkByte2015, 2017-10-18 10:11:35

How to make template inheritance?

Is it possible to do template inheritance in Yii2 like in Django? I know that by default there is already inheritance of all templates from layout, but I need to inherit a template from another template inherited from layout. Those. layout -> template1 -> template2. I was also told that such things can be somehow solved with the help of widgets, but I don’t understand how this can be done in this case.
The idea is simple: I need tabs on the page. I use these ones (although there are standard ones in Yii - I know). I tried to deal with Ajax loading of content, but gave up this idea - it's too difficult. I need each tab to be accessible via a link like "/edit?step=1". Those. each tab is a model editing step.
Now I did this: I created an action for each step (actionEditStep1, actionEditStep2 ...) and in each I return the same view in which the tab widget is created, but I determine the active tab directly in the view using a dirty hack - I get the name of the called action, I take the step number from it and render the view of the desired step. Those. my views are called view.php, step1.php, step2.php...
But I want to do something better. I just don’t know how ... If I could inherit the tab view from the view in which the widget with all the tabs (view.php) is created, it would be ideal. I could then return from each action the already necessary step view. Another thing I don't like is that the link is like "/edit/step1" instead of "/edit?step=1". Those. it would probably be better to have one action for editing, although I'm not sure here ... In general, tell me how best to do it?
PS PHP 5.6, Yii2.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-10-18
@webinar

You are clearly using the word "inheritance" in a different sense than others understand. What's wrong with ajax loading?

$this->registerJs("
$('.someLink').on('click',function(){
    $('.someBlock').load('/someContrioller/someAction');
});
");

public function actionSomeAction(){
    return $this->renderAjax('some_view');
}

M
Maxim Fedorov, 2017-10-18
@qonand

I know that by default there is already inheritance of all templates from layout, but I need to inherit a template from another template inherited from layout.

There is no inheritance from layout, the content of the desired page is simply transferred to the layer and inserted. You can inherit the View object, but it doesn't make sense for your purposes.
Don't reinvent the wheel, use wizard forms like this one or look for another one
well, these are the UrlManager settings, you can customize it however you want
it is better to do step-by-step data editing on the front and then send the entire data array to the back

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question