CHtml::create() ->p() ->a(array('href' => 'http://habrahabr.ru', 'class' => 'btn')) ->text('') ->render();
<p><a href="http://habrahabr.ru" class="btn"></a></p>
$arr = array('1' => '', '2' => ''); CHtml::create() ->select($options) ->each(CHtml::plainArray($arr, 'value', 'text')) ->option('array("value" => $data->value)') ->text('$data->text') ->end() ->endEach()
$arr = array( array('value' => '1', 'text' =>''), array('value' => '2', 'text' => '') );
$columns = array( array('id' => 'NAME', 'label' => ''), array('id' => 'AGE', 'label' => '') ); $data = array( array('NAME' => '', 'AGE' => 29), array('NAME' => '', 'AGE' => 32) ); CHtml::create() ->table() ->thead() ->tr() ->each($columns) ->th() ->text(function($column){ return $column['label']; }) ->end() ->endEach() ->end() ->end() ->tbody() ->each($data) ->tr() ->each($columns) ->td() ->text(function($row, $column) { return $row[$column['id']]; }) ->end() ->endEach() ->end() ->endEach() ->render();
class CMyHtml extends CHtml { public function a($options = array()) { $default = array( 'href' => 'javascript:void(0)' ); return parent::a(array_replace($default, $options)); } }
class CForm { private $_lastLabel = ''; public function __construct(CModel $model, CHtml $html = null) { $this->_model = $model; $this->_html = $html ?: CHtml::create(); } public function __call($method, $ps) { $options = $ps ? $ps[0]: array(); if ($method === 'label') { $this->_lastLabel = isset($options['for']) ? $this->_model->getLabel($options['for']) : ''; } if ($method === 'text' && $this->_lastLabel) { $options = $options ?: $this->_lastLabel; $this->_lastLabel = ''; } $this->_html->$method($options); return $this; } }
Source: https://habr.com/ru/post/270147/