1

In

@dektrium/user/views/admin/_account.php
@dektrium/user/views/admin/_info.php
@dektrium/user/views/admin/_profile.php

there are

<?php $this->beginContent('@dektrium/user/views/admin/update.php', ['user' => $user]) ?>
'the rest codes'
<?php $this->endContent() ?>

and in @dektrium/user/views/admin/update.php there're

<div class="col-md-9">
    <div class="panel panel-default">
        <div class="panel-body">
            <?= $content ?>
        </div>
    </div>
</div>

the $content will be replaced by code between 'beginContent' and 'endContent', how to implement this kind of layout in my new backend model 'Rayon'? I tried write a similar CRUD code, but keep getting an error 'Undefined variable content'.

Thank you for your help.

exneval
  • 43
  • 1
  • 4

1 Answers1

1

the row with code

 <?php $this->beginContent('@dektrium/user/views/admin/update.php', ['user' => $user]) ?>

tells to the "view" which is, to take the code from the reference and add it to the place where the call is invoked ..

It performs an equivalent action to "include" within more the possibility of pass the variables to use in the "content"

then you should create the part of view that you want to reuse .. and the views in which you want to call to add this type of call

You can do something similar directly reusing the render () function inside de view and indicating which (other) view and which variables to use.

for (simple) example

view container_view.php in yourapp/views

 <div>my container test</div>
 <?= $content ?>

then You want that the code in container_view is placed in a way that the code inside beginContent and endContent of the

create.php in yourapp/views/ is place in the same place you have $content in the container

<?php $this->beginContent('yourapp/views/container_view.php', ['model' => $model]) ?>
 <div>this code is placed in $container</div>
 <div>and the value of the var model is passed</div>
 <br />
 <?= $model->name '>
 <?php $this->endContent() ?>
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • can you give me an example of "then you should create the part of view that you want to reuse .. and the views in which you want to call to add this type of call" I still don't know how variable $content can be passed from those files to update.php – exneval Aug 17 '16 at 18:57
  • I have update with a basic sample .. hope is useful .. anyway could be that the approach based on this type of yii2 obejct is a bit complex .. in this case you can try looking for layouts .. – ScaisEdge Aug 17 '16 at 19:19