Yii2 Layouts

hi in yii1 i was able to create additional layouts like column1, column2 how to achieve this with yii2? Thanks

You can do the same in Yii2. For example a column1.php layout can be created like this:


<?php $this->beginContent('@app/views/layouts/main.php'); ?>

	<div class="container">

		<?= $content ?>

	</div>

<?php $this->endContent();

thanks

The View class has no layout property. How do you use newly created layout?

Edit:

I found the layout property, it is still in the Controller. I am probably wrong but it was logical to me to search layout property in the View class, since in Yii2 View is separated from Controller. I think that presentation layer shoud deal with layout.

If you want to use the layout globally, you can set it in your config file rather than adding it to all of your controllers:




    'layout' => 'column2',



Yes… layout in Yii2 same with Yii1

excuse me, i’m trying to set Yii2 layout with 3 column

I set the config in web.php




...

$config = [

     'layout' => 'column3',

...



i create the column3.php like this:




<?php $this->beginContent('@app/views/layouts/main.php'); ?>

        <div class="container">

            

            <div class="span-4">

                <p>

                    SideLeft

                </p>

            </div>


            <div id="content" class="span-14">

                    <?php echo $content; ?>

            </div><!-- content -->


            <div class="span-4">

                <p>

                    SideRight

                </p>

            </div>


        </div>

<?php $this->endContent();



But probably i forgot to set the .css beacuse the layout is all in one column

– side left

– content

– side right

and not

side left || content || side right

can someone help me telling what is the css and what change must i do?

thank’s

EDIT: for now i solve editing ../web/css/site.css adding these lines copyied from yii1





[class*="span"] {

  float: left;

  min-height: 1px;

  margin-left: 20px;

}

//.container {width:950px;margin:0 auto;}

.column, .span-1, .span-2, .span-3, .span-4, .span-5, .span-6, .span-7, .span-8, .span-9, .span-10, .span-11, .span-12, .span-13, .span-14, .span-15, .span-16, .span-17, .span-18, .span-19, .span-20, .span-21, .span-22, .span-23, .span-24 {float:left;margin-right:10px;}

.last {margin-right:0;}

.span-1 {width:30px;}

.span-2 {width:70px;}

.span-3 {width:110px;}

.span-4 {width:150px;}

.span-5 {width:190px;}

.span-6 {width:230px;}

.span-7 {width:270px;}

.span-8 {width:310px;}

.span-9 {width:350px;}

.span-10 {width:390px;}

.span-11 {width:430px;}

.span-12 {width:470px;}

.span-13 {width:510px;}

.span-14 {width:550px;}

.span-15 {width:590px;}

.span-16 {width:630px;}

.span-17 {width:670px;}

.span-18 {width:710px;}

.span-19 {width:750px;}

.span-20 {width:790px;}

.span-21 {width:830px;}

.span-22 {width:870px;}

.span-23 {width:910px;}

.span-24 {width:950px;margin-right:0;}






Hi,

Yii 2 comes with bootstrap integrated, so I would do the following to create 3 columns:




<?php $this->beginContent('@app/views/layouts/main.php'); ?>

        <div class="container">

            

            <div class="col-sm-4">

                <p>

                    SideLeft

                </p>

            </div>


            <div id="content" class="col-sm-4">

                    <?php echo $content; ?>

            </div><!-- content -->


            <div class="col-sm-4">

                <p>

                    SideRight

                </p>

            </div>


        </div>

<?php $this->endContent();



More info on bootstrap columns here: http://getbootstrap.com/css/#grid

thank’s for the Help!

hi again, I think you should also put the <div class="row">:


<?php $this->beginContent('@app/views/layouts/main.php'); ?>

        <div class="container">

          <div class="row">

            <div class="col-sm-4">

                <p>

                    SideLeft

                </p>

            </div>


            <div id="content" class="col-sm-4">

                    <?php echo $content; ?>

            </div><!-- content -->


            <div class="col-sm-4">

                <p>

                    SideRight

                </p>

            </div>

          </div>

        </div>

<?php $this->endContent();

Still didn’t get how to use it.

The code bellow is for ‘layouts/main.php’ ?

I need to have a few different lyaouts, in Yii 1.1 It could be done by creating layout files and set it in view.

So where to create those layouts, in the same location? How to set witch layout to be used?