Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theming and layout in yii framework

I am a newbie in Yii Framework and creating a CRM which is module based. Using different tutorials I am able to create my own theme, but now I am stucked at one point.

In my theme, the upper <nav> and left <nav> remains the same throughout the app, until user is logged in. That's why I made it a part of my main.php, but in the login page there are no buttons to show, just simple login form with 2 textfields.

How can I implement this form in my application using custom themes?

I have tried to define a layout in that particular action but not succeeded. Any help would be appreciated.

like image 607
Code Prank Avatar asked Apr 25 '12 10:04

Code Prank


People also ask

What is widget in Yii Framework?

Widgets are reusable building blocks used in views to create complex and configurable user interface elements in an object-oriented fashion. For example, a date picker widget may generate a fancy date picker that allows users to pick a date as their input.

What is routing in Yii Framework?

When a Yii application starts processing a requested URL, the first step it takes is to parse the URL into a route. The route is then used to instantiate the corresponding controller action to handle the request. This whole process is called routing.

Is Yii an MVC framework?

Yii implements the model-view-controller (MVC) design pattern, which is widely adopted in Web programming. MVC aims to separate business logic from user interface considerations, so that developers can more easily change each part without affecting the other.


2 Answers

Using a custom layout for your view is the right way to go. You can either set the layout in the controller action or in the view.

$this->layout = "//layouts/mylayout";

Note that the default layouts column1.php and column2.php also use the main.php layout file.

like image 146
schmunk Avatar answered Sep 23 '22 01:09

schmunk


Try this step by step :

  1. Create New theme

    You can create a new theme and add this to the directory Application_Root/themes.

    Look at the themes/classic directory to get an an idea of the structure of the directory. The important file (at this stage) is :- Application_Root/themes/views/layouts/main.php

  2. Customise your theme contents

    Copy the css, image, js files etc to the correct directory and change the main.php file to your liking. For example, if your main.php says

    <link href="css/mystyle.css" rel="stylesheet">

    Then you will have a file Application_Root/css/mystyle.css

  3. Create the content placeholder.

    Somewhere in your main.php, there will be a placeholder for dynamic text, which is specified by.

    <?php echo $content; ?>

  4. Tell yii to use the theme. Change the file Application_Root/protected/config/main.php by adding the following line just before the last line (containing the closing bracket).

    'theme'=>'surveyhub'

  5. Create the layout placeholders.

    Create an HTML segment that will be written into the $contents portion of main.php. Call it for example one_column.php. The file path will therefore be Application_Root/themes/views/layouts/one_column.php In that file, where you want the dynamic text to be placed, create a placeholder.

    <?php echo $content; ?>

  6. Tell Yii to use the layout.

    In the file Application_Root/protected/components/Controller.php, add or modify the layout variable to read :

    public $layout='//layouts/one_column.php';

  7. Refresh the page

like image 34
crafter Avatar answered Sep 23 '22 01:09

crafter