Sunday, January 12, 2014

Some useful HTML elements in Yii

Create Html Link in Yii

  1. The code below creates a html link to user view which has id = 23
    <?php echo CHtml::link(CHtml::encode('View User with ID = 23'), array('user/view', 'id'=>23)); ?>
    
  2. The code below creates a html link to the html form for creating a user
  3. <?php echo CHtml::link(CHtml::encode('Create User'), array('user/create')); ?>
    

Create Html Label in Yii

The code below creates a html label

<?php echo CHtml::label(CHtml::encode('Some Text'), 'Some Text'); ?>

Create Html ComboBox in Yii

The code below creates a html combobox

<?php echo $form->dropDownList($model, 'field_name', array(1=>'test1', 2=>'test2'));?>
The code belows creates a html combobox with list data populating dropdown from database values
<?php echo $form->dropDownList($model,'node_types_id', CHtml::listData(NodeTypes::model()->findAll(array('order' => 'name')),'id','name'));?>

No comments:

Post a Comment