Problem With Layout

hello everybody

I have got a small problem …

when I applied my own layout file to a certain action, then the page is displayed in the browser was very different from the standard: padding disappeared …

Why has this happened?

I just kind of kept main.php under a different name and did not change the path to the css-files

enclose screenshots

I remember getting the same problem when I started playing with Yii’s layout. By default, Yii uses the ‘column1’ as it’s main layout, which in turn calls the main.php. There’s an extra div on column1, which is why you see the extra padding.

B

Fine! Thanks, BCR! I understand now.

If I want to use my own layout file I need to insert in controller this string = public $layout=’//layouts/my-own-layout’;, but in this case the layout file will be applied to all actions… and I want to apply it to only one action

what should I do about it in this case?

yes you are right style room… in that case you can use the conditions like this for some controller and some action:




	   <?php if($this->id=='site' && $this->action->id=='index'){?>

           <?php  echo "content";?> 

cheers

Well, setting $this->layout in that specific action in the controller should load a specific layout for that action.

B

thanks everybody

that’s my opinion =

your version of the markup can be applied or 1) to the controller as a whole (if it will be applied to all the methods of the controller), or only 2) to one of the controller methods

it should be remembered that for a particular page layout meet two files - one for each page as a whole, and one - only for content, respectively, to change the layout, we need two files:

 my.php - containing doctype, html, body, etc. = It will determine the layout of the whole page


 column_my.php - responsible for creating content

Here we note that column_my.php will be manages the my.php

do it:

 create file my.php which prescribes all right (doctype, html, body, etc.)


 create column_my.php by resaving column1.php and replace my main on the line [u]&lt;?php &#036;this-&gt;beginContent('//layouts/my2');?&gt;[/u]

Option 1: use your layout to the controller as a whole = somewhere over the public function actionIndex () to insert a row public $layout = ‘//layouts/column_my’;

Option 2: apply its markup to only one controller method = method you want to insert in the line $this->layout = ‘// layouts/column_my’; or a line $this->layout = ‘column_my’;

Do I understand correctly?

Yes, you understood it correctly.

However, you could also directly include the extra div of the column1.php in main.php (If you’re using the default Yii layout), or if you’re using your own layout, there’s no real need for 2 files IMO.

There’s a 3rd way of setting the layout - in the components/Controller.php. Since every controller that you create extends from that file, you can set a global “public $layout” in Controller.php which will apply across all controllers & actions. Unless ofcourse you have a specific layout set for a particular controller or action.

thanks for your tips and on-line communication