本文整理汇总了PHP中CHtml::listData方法的典型用法代码示例。如果您正苦于以下问题:PHP CHtml::listData方法的具体用法?PHP CHtml::listData怎么用?PHP CHtml::listData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHtml
的用法示例。
在下文中一共展示了CHtml::listData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderValue
/**
* @param $attribute
* @param $value
* @return string
*/
public static function renderValue(Attribute $attribute, $value, $template = '<p>{item}</p>')
{
$unit = $attribute->unit ? ' ' . $attribute->unit : '';
$res = null;
switch ($attribute->type) {
case Attribute::TYPE_TEXT:
case Attribute::TYPE_SHORT_TEXT:
case Attribute::TYPE_NUMBER:
$res = $value;
break;
case Attribute::TYPE_DROPDOWN:
$data = CHtml::listData($attribute->options, 'id', 'value');
if (is_array($value)) {
$value = array_shift($value);
}
if (isset($data[$value])) {
$res .= $data[$value];
}
break;
case Attribute::TYPE_CHECKBOX_LIST:
$data = CHtml::listData($attribute->options, 'id', 'value');
if (is_array($value)) {
foreach (array_intersect(array_keys($data), $value) as $val) {
$res .= strtr($template, ['{item}' => $data[$val]]);
}
}
break;
case Attribute::TYPE_CHECKBOX:
$res = $value ? Yii::t("StoreModule.store", "Yes") : Yii::t("StoreModule.store", "No");
break;
}
return $res . $unit;
}
示例2: actionEditOrder
/**
* @param array $variables
*
* @throws HttpException
*/
public function actionEditOrder(array $variables = [])
{
$this->requireAdmin();
$variables['orderSettings'] = craft()->market_orderSettings->getByHandle('order');
if (empty($variables['order'])) {
if (!empty($variables['orderId'])) {
$variables['order'] = craft()->market_order->getById($variables['orderId']);
if (!$variables['order']->id) {
throw new HttpException(404);
}
} else {
$variables['order'] = new Market_OrderModel();
}
}
if (!empty($variables['orderId'])) {
$variables['title'] = "Order " . substr($variables['order']->number, 0, 7);
} else {
$variables['title'] = Craft::t('Create a new Order');
}
$variables['orderStatuses'] = \CHtml::listData(craft()->market_orderStatus->getAll(), 'id', 'name');
if ($variables['order']->orderStatusId == null) {
$variables['orderStatuses'] = ['0' => 'No Status'] + $variables['orderStatuses'];
}
$this->prepVariables($variables);
$this->renderTemplate('market/orders/_edit', $variables);
}
示例3: SearchID
public function SearchID($subject_name)
{
$subject_name = trim($subject_name, " \n\t");
if ($subject_name == 'республика Чувашская') {
$subject_name = 'Чувашская республика';
}
$subjects = $this->findAll();
$_RF_SUBJECTS = CHtml::listData($subjects, 'id', 'name');
$result = $this->gs_array_search($subject_name, $_RF_SUBJECTS);
if (!$result) {
$_RF_SUBJECTS = CHtml::listData($subjects, 'id', 'name_full');
$result = $this->gs_array_search($subject_name, $_RF_SUBJECTS);
}
if (!$result) {
$subject_name = explode(' ', $subject_name);
foreach ($subject_name as $s) {
$ls = mb_strtolower($s, 'UTF-8');
if ($ls == 'республика' || $ls == 'край' || $ls == 'область' || $ls == 'округ') {
continue;
}
$result = $this->gs_array_search($s, $_RF_SUBJECTS);
if ($result) {
break;
}
}
}
return $result;
}
示例4: actionSetSorters
public function actionSetSorters()
{
$sql = 'SELECT id, name_' . Yii::app()->language . ' AS name FROM {{location_country}} ORDER BY name_' . Yii::app()->language . ' ASC';
$res = Yii::app()->db->createCommand($sql)->queryAll();
$countries = CHtml::listData($res, 'id', 'name');
$co = 1;
foreach ($countries as $coid => $coname) {
$sql = 'UPDATE {{location_country}} SET sorter="' . $co . '" WHERE id = ' . $coid . ' LIMIT 1';
Yii::app()->db->createCommand($sql)->execute();
$sql = 'SELECT id, name_' . Yii::app()->language . ' AS name FROM {{location_region}} WHERE country_id = :country ORDER BY name_' . Yii::app()->language . ' ASC';
$res = Yii::app()->db->createCommand($sql)->queryAll(true, array(':country' => $coid));
$regions = CHtml::listData($res, 'id', 'name');
$r = 1;
foreach ($regions as $rid => $rname) {
$sql = 'UPDATE {{location_region}} SET sorter="' . $r . '" WHERE id = ' . $rid . ' LIMIT 1';
Yii::app()->db->createCommand($sql)->execute();
$sql = 'SELECT id, name_' . Yii::app()->language . ' AS name FROM {{location_city}} WHERE region_id = :region ORDER BY name_' . Yii::app()->language . ' ASC';
$res = Yii::app()->db->createCommand($sql)->queryAll(true, array(':region' => $rid));
$cities = CHtml::listData($res, 'id', 'name');
$c = 1;
foreach ($cities as $cid => $cname) {
$sql = 'UPDATE {{location_city}} SET sorter="' . $c . '" WHERE id = ' . $cid . ' LIMIT 1';
Yii::app()->db->createCommand($sql)->execute();
$c++;
}
$r++;
}
$co++;
}
echo 'ok';
}
示例5: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['EvaAttributesMatrix'])) {
$model->attributes = $_POST['EvaAttributesMatrix'];
if ($model->save()) {
$this->redirect(['index']);
}
}
$dropDownData = [];
$survObjCriteria = new CDbCriteria();
$survObjCriteria->with = ['options'];
$survObjCriteria->select = 'inputName';
$survObjCriteria->condition = "inputName='survObj' AND options.frameworkFieldId=t.id";
$rsSurveillanceObjective = FrameworkFields::model()->find($survObjCriteria);
$dropDownData['objectives'] = CHtml::listData($rsSurveillanceObjective->options, 'optionId', 'label');
$rsQuestionGrp = EvaQuestionGroups::model()->find(['select' => 'questions']);
$questionsArray = array_keys((array) json_decode($rsQuestionGrp->questions));
$dropDownData['groups'] = array_combine($questionsArray, range(1, count($questionsArray)));
//print_r($dropDownData['groups']); die;
$dropDownData['attributes'] = CHtml::listData(EvaAttributes::model()->findAll(), 'attributeId', 'name');
$this->menu = [['label' => 'Add Attribute Relevance', 'url' => $this->createUrl('create')], ['label' => 'List Attribute Relevance', 'url' => $this->createUrl('index')]];
$this->render('update', ['model' => $model, 'dropDownData' => $dropDownData]);
}
示例6: actionEdit
/**
* Create/Edit TaxZone
*
* @param array $variables
*
* @throws HttpException
*/
public function actionEdit(array $variables = [])
{
$this->requireAdmin();
if (empty($variables['taxZone'])) {
if (!empty($variables['id'])) {
$id = $variables['id'];
$variables['taxZone'] = craft()->market_taxZone->getById($id);
if (!$variables['taxZone']->id) {
throw new HttpException(404);
}
} else {
$variables['taxZone'] = new Market_TaxZoneModel();
}
}
if (!empty($variables['id'])) {
$variables['title'] = $variables['taxZone']->name;
} else {
$variables['title'] = Craft::t('Create a Tax Zone');
}
$countries = craft()->market_country->getAll();
$states = craft()->market_state->getAll();
$variables['countries'] = \CHtml::listData($countries, 'id', 'name');
$variables['states'] = \CHtml::listData($states, 'id', 'name');
$this->renderTemplate('market/settings/taxzones/_edit', $variables);
}
示例7: getCommentsByPage
public static function getCommentsByPage($id, $classify, $page = 1, $pageSize = 30, $field = "id,uid,username,logid,tocommentid,content,cTime")
{
if (!$id || !$classify) {
return array();
}
$page = $page <= 1 ? 1 : $page;
$pageSize = !$pageSize ? 30 : $pageSize;
$limitStart = ($page - 1) * $pageSize;
$sql = "SELECT {$field} FROM {{comments}} WHERE logid='{$id}' AND classify='{$classify}' AND status=" . Posts::STATUS_PASSED . " ORDER BY cTime LIMIT {$limitStart},{$pageSize}";
$items = Yii::app()->db->createCommand($sql)->queryAll();
if (!empty($items)) {
$uids = array_filter(array_keys(CHtml::listData($items, 'uid', '')));
$uidsStr = join(',', $uids);
if ($uidsStr != '') {
$usernames = Yii::app()->db->createCommand("SELECT id,truename FROM {{users}} WHERE id IN({$uidsStr})")->queryAll();
if (!empty($usernames)) {
foreach ($items as $k => $val) {
foreach ($usernames as $val2) {
if ($val['uid'] > 0 && $val['uid'] == $val2['id']) {
$items[$k]['loginUsername'] = $val2['truename'];
}
}
}
}
}
}
return $items;
}
示例8: layout
public function layout($model)
{
echo CHtml::openTag('div', array('class' => 'widget categories content-inner widget_post_category'));
if ($this->data('title') != '') {
echo CHtml::openTag('h3', array('class' => 'main-color widget_header'));
echo $this->data('title');
echo CHtml::closeTag('h3');
}
echo CHtml::openTag('div', array('class' => 'row'));
echo CHtml::openTag('div', array('class' => 'col-xs-12'));
$first = true;
$end = CHtml::listData($model, 'ID', 'ID');
foreach ($model as $post) {
if ($this->data('showThumbPost')) {
echo CHtml::openTag('div', array('class' => 'single_comments'));
echo "<span>";
if ($post->post_image != '') {
echo CHtml::image(Helper::getThumb('content', $post->post_image));
}
echo "</span>";
$this->getLink($post, true, $this->data('showExcerpt'), 20);
echo CHtml::closeTag('div');
} else {
echo CHtml::openTag('div', array('class' => 'single_comments'));
$this->getLink($post, true, $this->data('showExcerpt'), $this->data('batasJudul'));
echo CHtml::closeTag('div');
}
}
if ($this->data('showIndexLink')) {
echo CHtml::Link('<i class="glyphicon glyphicon-plus"></i> Indeks ', array('indeks/populer'), array('class' => 'indeks'));
}
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
}
示例9: authenticate
/**
* Authenticates a user.
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$user = User::model()->findByAttributes(array('username' => $this->username));
if ($user === null) {
// No user found!
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if ($user->password !== SHA1($this->password)) {
// Invalid password!
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
// Okay!
if (!$user->admin) {
$ARData = DeviceUser::model()->with('device')->findAllByAttributes(array('user_id' => $user->id));
$devices = CHtml::listData($ARData, 'device_id', 'device.reference');
$menu = array();
$mydevices = array();
foreach ($devices as $id => $name) {
$menu[] = array('label' => $name, 'url' => '/client/status/' . $id);
$mydevices[] = $id;
}
$this->setState('clientMenu', $menu);
$this->setState('devices', $mydevices);
}
$this->setState('isAdmin', $user->admin ? true : false);
$this->_id = $user->id;
$this->errorCode = self::ERROR_NONE;
}
}
return !$this->errorCode;
}
示例10: insertOrUpdate
public function insertOrUpdate($relatedType, $relatedId, $lang, $currentKeywords)
{
$currentKeywordList = self::convert2Array($currentKeywords);
$criteria = new CDbCriteria();
$criteria->compare('related_type', $relatedType);
$criteria->compare('related_id', $relatedId);
$criteria->compare('lang', $lang);
$keywords = self::model()->findAll($criteria);
$oldKeywordList = CHtml::listData($keywords, 'internal_link_keyword_id', 'keyword');
$flag = 0;
// 需要删除的
$deleteKeywordList = array_diff($oldKeywordList, $currentKeywordList);
$criteria = new CDbCriteria();
$criteria->compare('related_type', $relatedType);
$criteria->compare('related_id', $relatedId);
$criteria->compare('lang', $lang);
$criteria->addInCondition('keyword', $deleteKeywordList);
$flag += self::model()->deleteAll($criteria);
// 需要添加的
$addKeywordsList = array_diff($currentKeywordList, $oldKeywordList);
foreach ($addKeywordsList as $addKeyword) {
$keyword = new self();
$keyword->related_type = $relatedType;
$keyword->related_id = $relatedId;
$keyword->lang = $lang;
$keyword->keyword = $addKeyword;
if ($keyword->save()) {
$flag++;
}
}
return $flag;
}
示例11: layout
public function layout($model)
{
echo CHtml::openTag('div', array('class' => 'widget categories content-inner '));
if ($this->data('title') != '') {
echo CHtml::openTag('h3', array('class' => 'main-color widget_header'));
echo $this->data('title');
echo CHtml::closeTag('h3');
}
echo CHtml::openTag('div', array('class' => 'row'));
echo CHtml::openTag('div', array('class' => 'col-xs-12'));
$first = true;
$end = CHtml::listData($model, 'ID', 'ID');
foreach ($model as $post) {
if ($this->data('showThumbPost')) {
echo CHtml::openTag('div', array('class' => 'single_comments'));
if ($this->getFoto($post) != '') {
echo CHtml::image(Helper::getThumb('content', $this->getFoto($post)));
}
$this->getLink($post);
echo CHtml::closeTag('div');
} else {
echo CHtml::openTag('div', array('class' => 'single_comments'));
$this->getLink($post);
echo CHtml::closeTag('div');
}
}
if ($this->data('showIndexLink')) {
echo CHtml::Link('<i class="fa fa-angle-double-right"></i> Index Photo', array('/photohome'), array('class' => 'indeks'));
}
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
}
示例12: getVariantsValuesList
public static function getVariantsValuesList()
{
if (self::$_variantsValuesList === null) {
self::$_variantsValuesList = CHtml::listData(EavVariant::model()->findAll(), 'id', 'title');
}
return self::$_variantsValuesList;
}
示例13: layout
public function layout($model)
{
echo CHtml::openTag('div', array('class' => 'widget categories content-inner widget_post_category'));
if ($this->data('title') != '') {
echo CHtml::openTag('h3', array('class' => 'main-color widget_header'));
echo $this->data('title');
echo CHtml::closeTag('h3');
}
echo CHtml::openTag('div', array('class' => 'row'));
echo CHtml::openTag('div', array('class' => 'col-xs-12'));
$first = true;
$end = CHtml::listData($model->posts($this->criteria()), 'ID', 'ID');
foreach ($model->posts($this->criteria()) as $post) {
if ($this->data('showThumbPost')) {
echo CHtml::openTag('div', array('class' => 'single_comments'));
echo "<span>";
if ($post->post_image != '') {
echo CHtml::image(Helper::getThumb('content', $post->post_image));
}
echo "</span>";
$this->getLink($post, $this->data('showIntro'));
echo CHtml::closeTag('div');
} else {
echo CHtml::openTag('div', array('class' => 'single_comments'));
$this->getLink($post, $this->data('showIntro'));
echo CHtml::closeTag('div');
}
}
if ($this->data('showIndexLink')) {
echo CHtml::Link('<i class="glyphicon glyphicon-plus"></i> Indeks', array('/label/index', 'id' => $model->term_id, 'slug' => $model->slug), array('class' => 'indeks'));
}
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
}
示例14: refreshEavAttributes
protected function refreshEavAttributes()
{
$attachedEavAttributes = $this->attachedEavAttributes;
$oldEavAttributes = EavAttributeToSet::model()->findAllByAttributes(array('eav_set_id' => $this->id));
$orderArray = CHtml::listData($oldEavAttributes, 'eav_attribute_id', 'weight');
EavAttributeToSet::model()->deleteAllByAttributes(array('eav_set_id' => $this->id));
if (is_array($attachedEavAttributes)) {
$counter = end($orderArray) + 10;
//var_dump($counter);
//exit();
foreach ($attachedEavAttributes as $key => $id) {
if (EavAttribute::model()->exists('t.id = :id', array(':id' => $id))) {
$rel = new EavAttributeToSet();
$rel->eav_set_id = $this->id;
$rel->eav_attribute_id = $id;
if (key_exists($id, $orderArray)) {
$rel->weight = $orderArray[$id];
} else {
$rel->weight = $counter;
$counter += 10;
}
$rel->save();
}
}
}
}
示例15: actionAddPaid
public function actionAddPaid($id = 0, $withDate = 0)
{
$model = new AddToUserForm();
$tariffs = TariffPlans::getAllTariffPlans(true, true);
$tariffsArray = CHtml::listData($tariffs, 'id', 'name');
$request = Yii::app()->request;
$data = $request->getPost('AddToUserForm');
if ($data) {
$userId = $request->getPost('user_id');
$withDate = $request->getPost('withDate');
$model->attributes = $data;
if ($model->validate()) {
$user = User::model()->findByPk($userId);
$tariff = TariffPlans::getFullTariffInfoById($model->tariff_id);
if (!$tariff || !$user) {
throw new CException('Not valid data');
}
if (TariffPlans::applyToUser($userId, $tariff['id'], $model->date_end, null, true)) {
echo CJSON::encode(array('status' => 'ok', 'userId' => $userId, 'html' => TariffPlans::getTariffPlansHtml($withDate, true, $user)));
Yii::app()->end();
}
} else {
echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('_add_to_user', array('id' => $userId, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray), true)));
Yii::app()->end();
}
}
$renderData = array('id' => $id, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray);
if (Yii::app()->request->isAjaxRequest) {
$this->renderPartial('_add_to_user', $renderData);
} else {
$this->render('_add_to_user', $renderData);
}
}