本文整理汇总了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
}
示例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;
}
}
示例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';
}
}
示例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));
}
示例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];
}
}
示例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;
}
}
示例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));
}
示例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;
}
}
示例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));
}
示例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;
}
示例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;
}
}
示例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;
}
示例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
}
示例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]);
}
示例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);
}