Skip to main content

Posts

Showing posts from April 24, 2014

Edit View Files in Yii Basics

In the HEAD, you’ll see that external files are linked using <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" /> Whenever you see Yii::app(), that refers to the Web application as a whole. You can access information about the user viewing a page, about the current or previously-viewed page, etc., there. Yii::app()->request specifically references the current page being accessed (or requested). The ->baseUrl part refers to the root URL for the application, like http://www.example.com. You should use Yii::app()->request->baseUrl for references to external files—CSS, JavaScript, images, and so forth—as the relative path to them can become muddled with the changed Yii URLs (like www.example.com/index.php/site/login). If you’re viewing a page like www.example.com/index.php/employee/view/id/1, which is intended to show the employee with an ID of 1, the actionView() method o...

Yii CHtml static class

Avaiable methods: CHtml::link() CHtml::ajaxLink() CHtml::button() CHtml::textField() CHtml::listData() CHtml::dropDownList() CHtml::link() method  public static string link ( string $text , mixed $url = ' # ' , array $htmlOptions = array ( ) ) Generates a hyperlink tag. Example 1: Linking to a controller action <?php echo CHtml :: link ( ' Link Text ' , array ( ' controller/action ' ) ) ; ?> HTML Output: < a href = " index.php?r=controller/action " > Link Text </ a > Example 2: Linking to a controller action with querystring parameters <?php echo CHtml :: link ( ' Link Text ' , array ( ' controller/action ' , ' param1 ' => ' value1 ' ) ) ; ?> HTML Output: < a href = " index.php?r=controller/action&param1=value1 " > Link Text </ a > Example 3: Linking to a control...