Answer the question
In order to leave comments, you need to log in
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
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');
}
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question