Revision #46                                    has been created by  Rohit Suthar                                    on Nov 26, 2014, 9:08:00 AM with the memo:
 Rohit Suthar                                    on Nov 26, 2014, 9:08:00 AM with the memo:
                                
                                
                                    correction                                
                                                                    « previous (#37)                                                                                                    next (#47) »                                                            
                            Changes
                            
    Title
    unchanged
    By Example: CHtml
    Category
    unchanged
    Tutorials
    Yii version
    unchanged
    
    Tags
    changed
    listData, chtml, link, button, ByExample, ajax, ajax link, image
    Content
    changed
    [...]
- [CHtml::link()](#hh0)
- [CHtml::ajaxLink()](#hh1)
- [CHtml::button()](#hh2)
- [CHtml::textField()](#hh3)
- [CHtml::listData()](#hh4)
- [CHtml::dropDownList()](#hh5)
 
- [Chtml::image()](#hh6) - Added new tag
## CHtml::link() method[...]
array('id'=>'idTextField', 
       'width'=>100, 
       'maxlength'=>100)); ?>
```[...]
```php
<?php echo CHtml::dropDownList('categories', $category, 
              $list
,
 
              array('empty' => '(Select a category'));
 
```
 
 
With condition -
 
 
 
```php 
echo CHtml::dropDownList('categories', $category, 
 
              CHtml::listData(categories::model()->findAll("Status=1"),
 
              'category_id', 'category_name'),
              array('empty' => '(Select a category'));
```
 
 
 
**Example 5: Generating dropdownlist with option groups.**
If you need to generate dropdownlist using both `optgroup` and `option` tags use the following code.[...]
```
 
## CHtml::image() method
 
 
 
```php 
public static string image(string $src, string $alt='', array $htmlOptions=array ( ))
 
```
 
 
 
Generates a image tag.
 
 
***
 
 
**Example 1: Image only**
 
 
```php 
<?php echo CHtml::image(Yii::app()->request->baseUrl.'/img/image.png'); ?>
 
```
 
 
**HTML Output:**
 
 
 
```php 
<img src="/img/image.png" />
 
```
 
 
 
***
 
 
**Example 2: Image with alt attribute**
 
 
```php 
<?php echo CHtml::image(Yii::app()->request->baseUrl.'/img/image.png', 
 
'this is alt tag of image'); ?>
 
```
 
 
**HTML Output:**
 
 
 
```php 
<img src="/img/image.png" alt="this is alt tag of image" />
 
```
 
 
 
 
***
 
 
**Example 3: Add width, height and others attribute for image**
 
 
```php 
<?php echo CHtml::image(Yii::app()->request->baseUrl.'/img/image.png',
 
      'this is alt tag of image',
 
      array('width'=>'100px','height'=>'100px','title'=>'image title here')); ?>
 
```
 
 
**HTML Output:**
 
 
 
```php 
<img src="/img/image.png" alt="this is alt tag of image" title="image title here" width="100" height="100" />
 
```
 
 
You can also add another html attributes like class, id etc. for image in the similar way to adding width and height attribute for image above.
 
 
 
***
 
 
**Example 4: Image with link**
 
 
```php 
<?php $image = CHtml::image(Yii::app()->request->baseUrl.'/img/image.png',
 
      'this is alt tag of image');
 
      
 
      echo CHtml::link($image,array('book/view','id'=>'book_id')); ?>
 
```
 
 
**HTML Output:**
 
 
 
```php 
<a href="index.php?r=book/view&id=book_id"><img src="/img/image.png" alt="this is alt tag of image" /></a>
 
```
 
 
 
 
 
***
You can find CHtml class at `yii/framework/web/helpers/CHtml.php` view on [Github](https://github.com/yiisoft/yii/blob/1.1.14/framework/web/helpers/CHtml.php ""), all [CHtml methods here](http://yii.codexamples.com/v1.1/CHtml/ "").
## Links
### Russian[...]