php yii-widgets-ActiveForm类(方法)实例源码

下面列出了php yii-widgets-ActiveForm 类(方法)源码代码实例,从而了解它的用法。

作者:frostiks2    项目:rzwebsys   
/**
  * Формирование Html кода поля для вывода в форме
  * @param ActiveForm $form объект форма
  * @param array $options массив html атрибутов поля
  * @param bool|int $index инднкс модели при табличном вводе
  * @return string
  */
 public function renderInput(ActiveForm $form, array $options = [], $index = false)
 {
     $options = ArrayHelper::merge($this->options, $options);
     $attr = $this->modelField->attr;
     $defaults = ["maxFileSize" => $this->modelField->model->maxFileSize, "uploadRoute" => $this->defaultRoute];
     $widgetOptions = ArrayHelper::merge($defaults, $this->widgetOptions, ["options" => $options]);
     $attr = $this->getFormAttrName($index, $attr);
     return $form->field($this->modelField->model, $attr)->widget(Html5Widget::className(), $widgetOptions);
 }

作者:frostiks2    项目:rzwebsys   
/**
  * Формирование Html кода поля для вывода в форме
  * @param ActiveForm $form объект форма
  * @param array $options массив html атрибутов поля
  * @param bool|int $index инднкс модели при табличном вводе
  * @return string
  */
 public function renderInput(ActiveForm $form, array $options = [], $index = false)
 {
     $options = ArrayHelper::merge($this->options, $options);
     $widgetOptions = ArrayHelper::merge(["visibleOptions" => ["class" => "form-control"]], $this->widgetOptions, ["options" => $options]);
     $attr = $this->getFormAttrName($index, $this->modelField->attr);
     return $form->field($this->modelField->model, $attr)->widget(AutoComplete::className(), $widgetOptions);
 }

作者:barie    项目:yii2-tool   
/**
  * Button with multiple submit options.
  * @param ActiveForm $form
  * @param $model
  * @param $attribute
  * @param $items
  * @param string $content
  * @param array $options
  * @return string
  */
 public static function submitDropdown(ActiveForm $form, $model, $attribute, $items, $content = "Save", $options = [])
 {
     if (count($items) == 1) {
         return $form->field($model, $attribute, ['options' => ['class' => 'pull-left']])->label(false)->hiddenInput(['value' => key($items)]) . Html::submitButton(reset($items), $options);
     }
     $lis = '';
     foreach ($items as $key => $name) {
         $lis .= Html::tag('li', "<a href='#'>{$name}</a>", ['onclick' => "\$(this).closest('div').find('input').val('{$key}');\n                    \$(this).parents('form').submit();", 'class' => $model->{$attribute} == $key ? 'active' : '']);
     }
     return Html::beginTag('div', ['class' => 'btn-group']) . $form->field($model, $attribute, ['options' => ['class' => 'pull-left']])->label(false)->hiddenInput() . Html::button($content . '<span class="caret"></span>', ['class' => 'btn dropdown-toggle btn-primary', "data-toggle" => "dropdown"]) . Html::beginTag('ul', ['class' => 'dropdown-menu']) . $lis . Html::endTag('ul') . Html::endTag('div');
 }

作者:skeeks-cm    项目:cms-sho   
public function renderConfigForm(ActiveForm $activeForm)
 {
     echo $activeForm->field($this, 'isLive')->checkbox();
     echo $activeForm->field($this, 'sMerchantLogin')->textInput();
     echo $activeForm->field($this, 'sMerchantPass1')->textInput();
     echo $activeForm->field($this, 'sMerchantPass2')->textInput();
 }

作者:frostiks2    项目:rzwebsys   
/**
  * Формирование Html кода поля для вывода в форме
  * @param ActiveForm $form объект форма
  * @param array $options массив html атрибутов поля
  * @param bool|int $index инднкс модели при табличном вводе
  * @return string
  */
 public function renderInput(ActiveForm $form, array $options = [], $index = false)
 {
     $options = ArrayHelper::merge($this->options, $options);
     $widgetOptions = ArrayHelper::merge($this->widgetOptions, ["options" => $options]);
     $attr = $this->getFormAttrName($index, $this->modelField->attr);
     return $form->field($this->modelField->model, $attr)->widget(MarkItUp::className(), $widgetOptions);
 }

作者:frostiks2    项目:rzwebsys   
/**
  * @inheritdoc
  */
 public function getExtendedFilterForm(ActiveForm $form, array $options = [])
 {
     $data = $this->defaultGridFilter();
     if (!isset($options['prompt'])) {
         $options['prompt'] = '';
     }
     return $form->field($this->model, $this->attr)->dropDownList($data, $options);
 }

作者:aivavi    项目:yii   
public function testBooleanAttributes()
    {
        $o = ['template' => '{input}'];
        $model = new DynamicModel(['name']);
        ob_start();
        $form = new ActiveForm(['action' => '/something']);
        ob_end_clean();
        $this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]" required>
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => true]));
        $this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]">
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => false]));
        $this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]" required="test">
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => 'test']));
    }

作者:frostiks2    项目:rzwebsys   
/**
  * Формирование Html кода поля для вывода в форме
  * @param ActiveForm $form объект форма
  * @param array $options массив html атрибутов поля
  * @param bool|int $index инднкс модели при табличном вводе
  * @return string
  */
 public function renderInput(ActiveForm $form, array $options = [], $index = false)
 {
     $data = $this->modelField->getDataValue();
     if (empty($data)) {
         return false;
     }
     $options = ArrayHelper::merge($this->options, $options, ["multiple" => true]);
     $widgetOptions = ArrayHelper::merge(["data" => $data], $this->widgetOptions, ["options" => $options]);
     $attr = $this->getFormAttrName($index, $this->modelField->attr);
     return $form->field($this->modelField->model, $attr)->widget(MultiSelect::className(), $widgetOptions);
 }

作者:frostiks2    项目:rzwebsys   
/**
  * Формирование Html кода поля для вывода в форме
  * @param ActiveForm $form объект форма
  * @param array $options массив html атрибутов поля
  * @param bool|int $index инднкс модели при табличном вводе
  * @return string
  */
 public function renderInput(ActiveForm $form, array $options = [], $index = false)
 {
     $options = ArrayHelper::merge($this->options, $options);
     $widgetOptions = ArrayHelper::merge(["options" => ["class" => "form-control"]], $this->widgetOptions, ["options" => $options]);
     $fieldOptions = ["options" => ["class" => "form-group col-xs-6"]];
     $html = Html::beginTag('div', ['class' => 'row']);
     $html .= $form->field($this->modelField->model, $this->fromAttr, $fieldOptions)->widget(DatePicker::className(), $widgetOptions);
     $html .= $form->field($this->modelField->model, $this->toAttr, $fieldOptions)->widget(DatePicker::className(), $widgetOptions);
     $html .= Html::endTag('div');
     return $html;
 }

作者:engmohamedame    项目:teston   
public function actionEdit($id)
 {
     if (!($model = Item::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['articleThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'sections');
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/sections', 'Article updated'));
                 return $this->redirect(['/admin/' . $this->module->id . '/items/edit', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }

作者:skeeks-cm    项目:cm   
public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsTree
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         if ($model->save() && $relatedModel->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . $errors);
         }
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel]);
 }

作者:alejandrosos    项目:A   
/**
  * VISTA PUBLICAR ARTICULO
  * @return string
  */
 public function run()
 {
     $session = Yii::$app->session;
     $idUsuario = Yii::$app->user->getId();
     $claveSession = ImagenHelper::SESSION_IMAGEN_ARTICULO . $idUsuario;
     $model = new CrearEditarDescuentoForm();
     $model->scenario = CrearEditarDescuentoForm::ESCENARIO_CREAR;
     $model->usuario = $idUsuario;
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($session->has($claveSession)) {
             $files = $session->get($claveSession);
             $model->imagenes = $files['file'];
             $model->principal = Yii::$app->request->post('dropzone_imagen_principal');
         }
         if ($model->crear()) {
             // file is uploaded successfully
             $session->remove($claveSession);
             //Toast::widget(['tipo'=>'success', 'mensaje'=>'Se ha creado la categor�a con �xito']);
             Yii::$app->session->setFlash('success', 'Se ha creado la categoria con exito');
             return $this->controller->redirect('/');
             $data = 'Se ha publicado';
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return $data;
         }
     } else {
         $session->remove($claveSession);
         return $this->controller->render('publicar-descuento', ['model' => $model]);
     }
 }

作者:godzukiso    项目:mngrAp   
/**
  * Creates a new Staff model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('admin')) {
         $model = new Staff();
         if (Yii::$app->request->isAjax && $model->load($_POST)) {
             Yii::$app->response->format = 'json';
             return \yii\widgets\ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post())) {
             $user = new Users();
             $user->usertype = 'Staff';
             $user->password = strtolower($model->apellido1 . substr($model->rut, 5, -2));
             $user->email = $model->correo;
             $model->save();
             $user->id_orig = $model->id;
             $user->username = $model->nombre . " " . $model->apellido1;
             $user->save();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }

作者:alejandrosos    项目:A   
/**
  * Creates a new Usuarios model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCrear()
 {
     $model = new CrearUsuarioForm();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword($model->clave_hash);
         $model->generateAuthKey();
         $model->tipo = Usuarios::ES_VISITA;
         $model->save();
         $archivo_tmp_original = Yii::getAlias('@backend') . '/web/' . str_replace(".", '-original.', $model->imagen_nombre);
         $archivo_tmp = Yii::getAlias('@backend') . '/web/' . $model->imagen_nombre;
         $imagen_nombre = $model->idusuario . '_' . uniqid() . '.png';
         $ruta = Yii::getAlias('@common') . '/imagenes/usuarios/' . $imagen_nombre;
         $data = base64_decode($model->imagen_data);
         file_put_contents($ruta, $data);
         if (file_exists($ruta)) {
             $imgModel = Usuarios::find()->where(['idusuario' => $model->idusuario])->one();
             $imgModel->foto = $imagen_nombre;
             $imgModel->save();
             if (file_exists($archivo_tmp)) {
                 unlink($archivo_tmp);
                 unlink($archivo_tmp_original);
             }
         }
         return $this->redirect(['detalle/' . $model->idusuario]);
     } else {
         return $this->render('crear', ['model' => $model]);
     }
 }

作者:Brother-Simo    项目:easyi   
public function actionEdit($id)
 {
     $model = Carousel::findOne($id);
     if ($model === null) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if ($fileInstanse = UploadedFile::getInstance($model, 'image')) {
                 $model->image = $fileInstanse;
                 if ($model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'carousel');
                 } else {
                     $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                     return $this->refresh();
                 }
             } else {
                 $model->image = $model->oldAttributes['image'];
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/carousel', 'Carousel updated'));
             } else {
                 $this->flash('error', Yii::t('easyii/carousel', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }

作者:cindymin    项目:yii-advanc   
public function actionValidateadd()
 {
     if (Yii::$app->request->get('type') == 'out') {
         $model = new OutRecord();
     } else {
         $model = new InRecord();
     }
     Yii::$app->response->format = yii\web\Response::FORMAT_JSON;
     if ($model->load(Yii::$app->request->post())) {
         $member = Member::isExist($model->membername);
         $result = yii\widgets\ActiveForm::validate($model);
         if (!$member) {
             $model->addError('membername', '用户编号不存在,请确认后输入');
         } else {
             if (Yii::$app->request->get('type') == 'out') {
                 if ($model->account_type == 1) {
                     $compareData = $member->finance_fund;
                 } else {
                     $compareData = $member->stack_fund;
                 }
                 if ($model->amount > $compareData) {
                     $model->addError('amount', '账户余额不足,理财账户余额: ' . $member->finance_fund . '. 购股账户余额: ' . $member->stack_fund);
                 }
             }
         }
         foreach ($model->getErrors() as $attribute => $errors) {
             $result[yii\helpers\Html::getInputId($model, $attribute)] = $errors;
         }
         echo json_encode($result);
     } else {
         echo json_encode(array());
     }
     Yii::$app->end();
 }

作者:chaimvai    项目:linet   
public function actionCreate($type = 0)
 {
     $model = new FormOutcome();
     if ($type == 1) {
         $model->account_id = \app\helpers\Linet3Helper::getSetting("company.acc.payvat");
         $model->sum = Accounts::findOne($model->account_id)->getBalance();
     }
     if ($type == 2) {
         $model->account_id = \app\helpers\Linet3Helper::getSetting("company.acc.natinspay");
         $model->sum = Accounts::findOne($model->account_id)->getBalance();
     }
     if ($type == 3) {
         $model->account_id = \app\helpers\Linet3Helper::getSetting("company.acc.pretax");
         $model->sum = Accounts::findOne($model->account_id)->getBalance();
     }
     // Uncomment the following line if AJAX validation is needed
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return \yii\widgets\ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->transaction()) {
             \Yii::$app->getSession()->setFlash('success', Yii::t('app', 'transaction Success'));
         }
     }
     return $this->render('create', array('model' => $model));
 }

作者:radiegty    项目:easyi   
public function actionEdit($id)
 {
     if (!($model = Category::findOne($id))) {
         return $this->redirect(['/admin/catalog']);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['categoryThumb']) {
                 $model->thumb = UploadedFile::getInstance($model, 'thumb');
                 if ($model->thumb && $model->validate(['thumb'])) {
                     $model->thumb = Image::upload($model->thumb, 'catalog', $this->module->settings['categoryThumbWidth'], $this->module->settings['categoryThumbHeight'], $this->module->settings['categoryThumbCrop']);
                 } else {
                     $model->thumb = $model->oldAttributes['thumb'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/catalog', 'Category updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }

作者:nsep    项目:yii2-listinpu   
/**
  * @inheritdoc
  */
 public function run()
 {
     parent::init();
     ListInputAsset::register($this->view);
     $pluginOptions = Json::encode($this->pluginOptions);
     $this->view->registerJs(sprintf('$("#%s").listinput(%s)', $this->options['id'], $pluginOptions));
     if ($this->hasModel()) {
         if ($this->form == null) {
             throw new InvalidConfigException(__CLASS__ . '::$form must be specifed.');
         }
         return $this->form->field($this->model, $this->attribute, ['template' => $this->template])->textInput($this->options);
     } else {
         return Html::textInput($this->name, $this->value, $this->options);
     }
 }

作者:jlorent    项目:yii2-model-imag   
/**
  * @inheritdoc
  */
 public function run()
 {
     $id = Html::getInputId($this->model, 'image_deleted');
     $options = ['options' => ['accept' => 'image/*'], 'pluginOptions' => ['showUpload' => false], 'pluginEvents' => ['fileclear' => "function() { \$('#{$id}').val(1);}"]];
     if ($this->model->imageUrl !== null) {
         $options['pluginOptions']['initialPreview'] = [Html::img($this->model->imageUrl, ['class' => 'file-preview-image'])];
     }
     echo $this->form->field($this->model, 'image_deleted', ['template' => '{input}'])->hiddenInput();
     echo $this->form->field($this->model, 'image')->widget(FileInput::classname(), $options);
 }


问题


面经


文章

微信
公众号

扫码关注公众号