當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CHtml::modelName方法代碼示例

本文整理匯總了PHP中CHtml::modelName方法的典型用法代碼示例。如果您正苦於以下問題:PHP CHtml::modelName方法的具體用法?PHP CHtml::modelName怎麽用?PHP CHtml::modelName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CHtml的用法示例。


在下文中一共展示了CHtml::modelName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: init

 public function init()
 {
     $this->filtered_options = $this->options;
     if (empty($_POST)) {
         if ($this->element && $this->element->{$this->relation}) {
             foreach ($this->element->{$this->relation} as $item) {
                 $this->selected_ids[] = $item->{$this->relation_id_field};
                 unset($this->filtered_options[$item->{$this->relation_id_field}]);
             }
         } elseif (!$this->element || !$this->element->id) {
             if (is_array($this->default_options)) {
                 $this->selected_ids = $this->default_options;
                 foreach ($this->default_options as $id) {
                     unset($this->filtered_options[$id]);
                 }
             }
         }
     } else {
         if (isset($_POST[$this->field]) && is_array($_POST[$this->field])) {
             foreach ($_POST[$this->field] as $id) {
                 $this->selected_ids[] = $id;
                 unset($this->filtered_options[$id]);
             }
         } elseif (isset($_POST[CHtml::modelName($this->element)][$this->relation])) {
             foreach ($_POST[CHtml::modelName($this->element)][$this->relation] as $id) {
                 $this->selected_ids[] = $id;
                 unset($this->filtered_options[$id]);
             }
         }
     }
     //NOTE: don't call parent init as the field behaviour doesn't work for the relations attribute with models
 }
開發者ID:code-4-england,項目名稱:OpenEyes,代碼行數:32,代碼來源:MultiSelectList.php

示例2: __construct

 public function __construct(array $models, $config = array())
 {
     $this->_models = $models;
     $this->setId(CHtml::modelName($this->_models[0]));
     foreach ($config as $key => $value) {
         $this->{$key} = $value;
     }
 }
開發者ID:shnellpavel,項目名稱:bcgroup_lk,代碼行數:8,代碼來源:MultiLocatedSurveysDataProvider.php

示例3: init

 /**
  * Publishes the required assets
  */
 public function init()
 {
     parent::init();
     if (!isset($this->htmlOptions['id']) && !isset($this->fileKey)) {
         $this->htmlOptions['id'] = \CHtml::modelName($this->model);
     } elseif (!isset($this->htmlOptions['id']) && isset($this->fileKey)) {
         $this->htmlOptions['id'] = \CHtml::modelName($this->model) . $this->fileKey;
     }
     if (!isset($this->htmlOptions['enctype'])) {
         $this->htmlOptions['enctype'] = 'multipart/form-data';
     }
 }
開發者ID:hanterrian,項目名稱:xupload-fpm-tmp,代碼行數:15,代碼來源:XUpload.php

示例4: getView

 public function getView()
 {
     if ($this->view) {
         return $this->view;
     }
     $model = CHtml::modelName($this);
     if (strstr($model, '_')) {
         $segments = explode('_', $model);
         $model = array_pop(explode('_', $model));
     }
     return '_' . strtolower(preg_replace('/^Report/', '', $model));
 }
開發者ID:code-4-england,項目名稱:OpenEyes,代碼行數:12,代碼來源:BaseReport.php

示例5: init

 public function init()
 {
     if (empty($_POST)) {
         if (isset($this->element->{$this->field})) {
             $this->checked[$this->field] = (bool) $this->element->{$this->field};
         } else {
             $this->checked[$this->field] = false;
         }
     } else {
         $this->checked[$this->field] = (bool) @$_POST[CHtml::modelName($this->element)][$this->field];
     }
 }
開發者ID:openeyes,項目名稱:openeyes,代碼行數:12,代碼來源:CheckBox.php

示例6: __construct

 /**
  * Constructor.
  * @param mixed $modelClass the model class (e.g. 'Post') or the model finder instance
  * (e.g. <code>Post::model()</code>, <code>Post::model()->published()</code>).
  * @param array $config configuration (name=>value) to be applied as the initial property values of this class.
  */
 public function __construct($modelClass, $config = array())
 {
     if (is_string($modelClass)) {
         $this->modelClass = $modelClass;
         $this->model = $this->createModel($this->modelClass);
     } elseif ($modelClass instanceof Model) {
         $this->modelClass = get_class($modelClass);
         $this->model = $modelClass;
     }
     $this->setId(\CHtml::modelName($this->model));
     foreach ($config as $key => $value) {
         $this->{$key} = $value;
     }
 }
開發者ID:codemix,項目名稱:restyii,代碼行數:20,代碼來源:DataProvider.php

示例7: run

 /**
  * Allow the user to enter a promo code to receive a specified price.
  *
  * @author Drozdenko Anna
  */
 public function run()
 {
     $model = new PromoCodeModel('search');
     if (isset($_POST[\CHtml::modelName($model)])) {
         $model->attributes = $_POST[\CHtml::modelName($model)];
         if (PromoCodeType::DISCOUNT_TYPE_PERCENTAGE == $model->discountType) {
             $model->scenario = 'percentage';
         }
         if ($model->save()) {
             $this->controller->refresh();
         }
     }
     $dataProvider = new \CActiveDataProvider('yii_ext\\promo\\models\\PromoCodeModel', array('pagination' => array('pageSize' => 20)));
     $this->controller->render($this->view, array('model' => $model, 'dataProvider' => $dataProvider));
 }
開發者ID:yii-ext,項目名稱:promo,代碼行數:20,代碼來源:IndexAction.php

示例8: init

 public function init()
 {
     parent::init();
     if (empty($_POST)) {
         if ($this->selected_item !== null) {
             $this->value = $this->selected_item;
         } elseif (isset($this->element->{$this->field})) {
             $this->value = $this->element->{$this->field};
         }
     } else {
         $this->value = @$_POST[CHtml::modelName($this->element)][$this->field];
     }
     if ($this->no_element) {
         $this->name = $this->field;
     }
 }
開發者ID:openeyes,項目名稱:openeyes,代碼行數:16,代碼來源:RadioButtonList.php

示例9: actionAdd

 public function actionAdd()
 {
     $model = new TicketsForm();
     $ticketModel = new Tickets();
     if (isset($_POST[CHtml::modelName($model)])) {
         $model->setAttributes($_POST[CHtml::modelName($model)]);
         if ($model->validate()) {
             $transaction = db()->beginTransaction();
             try {
                 // Сохраняю тикет
                 $ticket = new Tickets();
                 $ticket->category_id = $model->category_id;
                 $ticket->priority = $model->priority;
                 $ticket->date_incident = $model->date_incident;
                 $ticket->char_name = $model->char_name;
                 $ticket->title = $model->title;
                 $ticket->new_message_for_admin = 1;
                 $ticket->gs_id = user()->getGsId();
                 $ticket->status = Tickets::STATUS_ON;
                 $ticket->save(FALSE);
                 $ticketId = db()->getLastInsertID();
                 // Сохраняю переписку для тикета
                 $ticketAnswer = new TicketsAnswers();
                 $ticketAnswer->ticket_id = $ticketId;
                 $ticketAnswer->text = $model->text;
                 $ticketAnswer->save(FALSE);
                 // Логирую действие юзера
                 if (app()->params['user_actions_log']) {
                     $log = new UserActionsLog();
                     $log->user_id = user()->getId();
                     $log->action_id = UserActionsLog::ACTION_CREATE_TICKET;
                     $log->save(FALSE);
                 }
                 notify()->adminNoticeTicketAdd(array('user' => user()->getUser(), 'ticket' => $ticket));
                 user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Тикет создан.'));
                 $transaction->commit();
                 $this->redirect(array('index'));
             } catch (Exception $e) {
                 $transaction->rollback();
                 user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.'));
                 Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__ . ' ' . __LINE__);
             }
             $this->refresh();
         }
     }
     $this->render('//cabinet/tickets/add', array('model' => $model, 'ticketModel' => $ticketModel));
 }
開發者ID:mmorpg2015,項目名稱:ghtweb5,代碼行數:47,代碼來源:TicketsController.php

示例10: getMatchingImgs

 private function getMatchingImgs($imgs, $assetManager)
 {
     $matchImgs = array();
     $className = CHtml::modelName($this->owner);
     $fields = implode('|', $this->owner->fieldImages());
     //\bname_name-(filippo|pino)-(6|5|9).jpg+\b
     $pattern = "/" . $className . "-" . "(" . $fields . ")-(.*).jpg/i";
     foreach ($imgs as $img) {
         if (preg_match($pattern, $img, $matches)) {
             $matchImgs[$matches[2]] = $assetManager->getPublishedPathOfAlias(self::FIELDS_IMAGES_ALIAS) . DIRECTORY_SEPARATOR . basename($matches[0]);
         }
     }
     if (empty($matchImgs)) {
         return array();
     }
     return $matchImgs;
 }
開發者ID:code-4-england,項目名稱:OpenEyes,代碼行數:17,代碼來源:FieldImages.php

示例11: __construct

 public function __construct($modelClass, $query, $config = array())
 {
     if ($query instanceof ESphinxQL === false) {
         throw new CException("Query param must be instance of EsphinxQL");
     }
     if (is_string($modelClass)) {
         $this->modelClass = $modelClass;
         $this->model = CActiveRecord::model($this->modelClass);
     } elseif ($modelClass instanceof CActiveRecord) {
         $this->modelClass = get_class($modelClass);
         $this->model = $modelClass;
     }
     $this->setId(CHtml::modelName($this->model));
     $this->query = $query;
     foreach ($config as $key => $value) {
         $this->{$key} = $value;
     }
 }
開發者ID:maduhu,項目名稱:openbay,代碼行數:18,代碼來源:LSphinxDataProvider.php

示例12: validate

 public static function validate($models, $attributes = null, $loadInput = true)
 {
     $result = array();
     if (!is_array($models)) {
         $models = array($models);
     }
     foreach ($models as $model) {
         $modelName = CHtml::modelName($model);
         if ($loadInput && isset($_POST[$modelName])) {
             $model->attributes = $_POST[$modelName];
         }
         $model->validate($attributes);
         foreach ($model->getErrors() as $attribute => $errors) {
             $result[CHtml::activeId($model, $attribute)] = $errors;
         }
     }
     return $result;
 }
開發者ID:mmorpg2015,項目名稱:ghtweb5,代碼行數:18,代碼來源:ActiveForm.php

示例13: init

 public function init()
 {
     $this->filtered_options = $this->options;
     if (empty($_POST)) {
         if ($this->element && $this->element->{$this->relation}) {
             foreach ($this->element->{$this->relation} as $item) {
                 $this->selected_ids[] = $item->{$this->relation_id_field};
                 unset($this->filtered_options[$item->{$this->relation_id_field}]);
             }
         } else {
             if (!$this->element || !$this->element->id) {
                 if (is_array($this->default_options)) {
                     $this->selected_ids = $this->default_options;
                     foreach ($this->default_options as $id) {
                         unset($this->filtered_options[$id]);
                     }
                 }
             }
         }
     } else {
         if (isset($_POST[$this->field])) {
             foreach ($_POST[$this->field] as $id) {
                 $this->selected_ids[] = $id;
                 unset($this->filtered_options[$id]);
             }
         } else {
             if (isset($_POST[CHtml::modelName($this->element)][$this->relation])) {
                 foreach ($_POST[CHtml::modelName($this->element)][$this->relation] as $id) {
                     $this->selected_ids[] = $id;
                     unset($this->filtered_options[$id]);
                 }
             }
         }
     }
     // if the widget has javascript, load it in
     if (file_exists("protected/widgets/js/" . get_class($this) . ".js")) {
         $this->assetFolder = Yii::app()->getAssetManager()->publish('protected/widgets/js');
     }
     //NOTE: don't call parent init as the field behaviour doesn't work for the relations attribute with models
 }
開發者ID:openeyeswales,項目名稱:OpenEyes,代碼行數:40,代碼來源:MultiSelectList.php

示例14: actionLogin

 /**
  * 用戶登錄
  */
 public function actionLogin()
 {
     /** @var CMemCache $memCache */
     $memCache = Yii::app()->memCache;
     $memCache->set('test', 1111, 10);
     echo $memCache->get('test');
     exit;
     $this->layout = '//layouts/main';
     if (!$this->app->user->isGuest) {
         $this->redirect(array('index'));
     }
     $model = new LoginForm('create');
     $model->unsetAttributes();
     $modelName = CHtml::modelName($model);
     if (isset($_POST[$modelName])) {
         $model->setAttributes($_POST[$modelName]);
         if ($model->validate() && $model->login()) {
             $this->redirect($this->app->user->returnUrl);
         }
     }
     $this->render($this->action->id, ['model' => $model]);
 }
開發者ID:wuhailin,項目名稱:composer,代碼行數:25,代碼來源:IndexController.php

示例15: validateTabular

 /**
  * Validates an array of model instances and returns the results in JSON format.
  * This is a helper method that simplifies the way of writing AJAX validation code for tabular input.
  * @param mixed $models an array of model instances.
  * @param array $attributes list of attributes that should be validated. Defaults to null,
  * meaning any attribute listed in the applicable validation rules of the models should be
  * validated. If this parameter is given as a list of attributes, only
  * the listed attributes will be validated.
  * @param boolean $loadInput whether to load the data from $_POST array in this method.
  * If this is true, the model will be populated from <code>$_POST[ModelClass][$i]</code>.
  * @return string the JSON representation of the validation error messages.
  */
 public static function validateTabular($models, $attributes = null, $loadInput = true)
 {
     $result = array();
     if (!is_array($models)) {
         $models = array($models);
     }
     foreach ($models as $i => $model) {
         $modelName = CHtml::modelName($model);
         if ($loadInput && isset($_POST[$modelName][$i])) {
             $model->attributes = $_POST[$modelName][$i];
         }
         $model->validate($attributes);
         foreach ($model->getErrors() as $attribute => $errors) {
             $result[CHtml::activeId($model, '[' . $i . ']' . $attribute)] = $errors;
         }
     }
     return function_exists('json_encode') ? json_encode($result) : CJSON::encode($result);
 }
開發者ID:hanyilu,項目名稱:iQuestion,代碼行數:30,代碼來源:CActiveForm.php


注:本文中的CHtml::modelName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。