Difference between #18 and #19 of
By Example: CHtml

Revision #19 has been created by wei on Oct 26, 2010, 3:43:51 AM with the memo:

formatting
« previous (#18) next (#20) »

Changes

Title unchanged

By Example: CHtml

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

Content changed

[...]
Smarthead will be pulling these from the forum when he is not finding the answers on his own. Please request examples using the comments below or ask for an example in the forum. Thanks.

Avaiable methods:<br>

- CHtml::link()

 
- CHtml::button()
 
- CHtml::textField()
 
- CHtml::listData()
 
- CHtml::dropDownList() <br>
 
 
<a name="link"></a>
 
## ::
## CHtml::link() method
[...]
***

### **Example 1: Linking to a controller action
 
**

```php
[...]
#### **HTML Output:
 
**

```php
[...]
***

### **Example 2: Linking to a controller action with querystring parameters**

```php
[...]
```

#### **HTML Output:**
[...]
***

### **Example 3: Linking to a controller action with multiple querystring parameters**

```php
[...]
```

#### **HTML Output:**
[...]
***

### **Example 4: Link opening a new page**

```php
[...]
```

#### **HTML Output:**
[...]
***

### **Example 5: Linking to a controller action inside the actual controller **
(Suppose you are in the PostController/view and wants to link to PostController/create)
[...]
***

### **Example 6: Linking to a controller action from the site root**
(Suppose you are inside a module and wants to make the link from a controller of the root application)
[...]
***

### **Example 7: Linking to a controller action from another module**

Replace below the module-id with desired module id .
[...]
***

### **Example 8: Linking to a controller action from the same module**

This is useful when you want to make absolute paths avoiding to use static module names.
[...]
```

_  
 
 
_  
 
 
 
<a name="button"></a>
 
## ::
## CHtml::button() method

~~~
[...]
***

### **Example 1: Connecting a button to a controller action**

```php
[...]
```

#### **HTML Output:
 
**

```php
[...]
```


 
_  
 
 
_  
 
 
 
<a name="textField"></a>
 
## ::
## CHtml::textField() method

~~~
[...]
***

### **Example 1: Generating an empty textfield, just with a name**

```php
[...]
***
### 
 
**
Example 2: Generating a textfield with name and value**

```php
[...]
***
### 
 
**
Example 3: Generating a textfield with customized id, width and maxlength**

```php
[...]
***
### 
 
**
Example 4: Generating a disabled textfield **

```php
[...]
```


 
_  
 
 
_  
 
 
 
<a name="textField"></a>
 
## ::
## CHtml::listData() method

~~~
[...]
***

### **Example 1: Generating a list data for categories**

```php
[...]
```

#### **HTML Output (Example):**

```php
[...]
***

### **Example 2: Generating an ordered list data for categories using findAll parameter**

```php
[...]
```

#### **HTML Output (Example):**

```php
[...]
```


 
_  
 
 
_  
 
 
 
<a name="textField"></a>
 
## ::
## CHtml::dropDownList() method

~~~
[...]
***

### **Example 1: Generating a simple dropdownlist for gender**

```php
[...]
***

### **Example 2: Generating a simple dropdownlist for gender with an 'empty' element.**

This example will avoid the dropdownlist to be blank when no value, outputing some proper information to the user
[...]
***

### **Example 3: Using data from a model function.**

It is better to have you gender list definition inside your model definition.
[...]
***

### **Example 4: Using data from db**

In order to create a dropdownList with data from db, you have to combine it with listData method that will format models from db into array of $key=>$value.
[...]
***
You cand find CHtml class at
`yii/framework/web/helpers/CHtml.php` ### Links [Russian Version dropDownList()](http://dbhelp.ru/by-example-chtml-dropdownlist/page/)
 
   [Russian Version listData()](http://dbhelp.ru/by-example-chtml-listdata/page/)
 
   [Russian Version textField()](http://dbhelp.ru/by-example-chtml-textfield/page/)
 
   [Russian Version link()](http://dbhelp.ru/by-example-chtml/page/)
 
78 0
75 followers
Viewed: 881 636 times
Version: 1.1
Category: Tutorials
Written by: jonah
Last updated by: glicious
Created on: Sep 25, 2009
Last updated: 2 years ago
Update Article

Revisions

View all history