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

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

作者:bfda    项目:yii2-widget-form-generato   
/**
  * @param array $config
  * @return string
  */
 public static function generate($config = [])
 {
     $reservedAttributeNames = ['plainHTML'];
     ob_start();
     $form = ActiveForm::begin($config['formConfig']);
     foreach ($config['fields'] as $attribute => $fieldConfig) {
         if (in_array($attribute, $reservedAttributeNames)) {
             echo $fieldConfig;
         } else {
             if (isset($fieldConfig['render'])) {
                 $render = $fieldConfig['render'];
                 switch ($render['type']) {
                     case 'inline':
                         $method = $render['method'];
                         $options = isset($render['options']) ? $render['options'] : [];
                         echo $form->field($fieldConfig['model'], $attribute, isset($fieldConfig['options']) ? $fieldConfig['options'] : [])->{$method}($options);
                         break;
                     case 'widget':
                         $class = $render['class'];
                         $options = isset($render['options']) ? $render['options'] : [];
                         echo $form->field($fieldConfig['model'], $attribute, isset($fieldConfig['options']) ? $fieldConfig['options'] : [])->widget($class, $options);
                         break;
                 }
             } else {
                 echo $form->field($fieldConfig['model'], $attribute, isset($fieldConfig['options']) ? $fieldConfig['options'] : []);
             }
         }
     }
     ActiveForm::end();
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }

作者:webvimar    项目:ybc-conten   
/**
  * Scan directory with templates and show them in dropdown list
  *
  * @param \yii\bootstrap\ActiveForm $form
  *
  * @return string
  */
 public function layoutSelector($form)
 {
     $items = [];
     $pathToTemplates = Yii::getAlias('@app/templates/');
     Yii::$app->assetManager->publish($pathToTemplates);
     $assetUrl = Yii::$app->assetManager->getPublishedUrl($pathToTemplates);
     $layoutFolders = scandir($pathToTemplates);
     foreach ($layoutFolders as $layoutFolder) {
         if (!in_array($layoutFolder, ['.', '..']) && is_dir($pathToTemplates . $layoutFolder)) {
             $items[$layoutFolder] = Html::img($assetUrl . '/' . $layoutFolder . '/backend_image.png');
         }
     }
     return $form->field($this, 'layout')->radioList($items);
 }

作者:nicdnep    项目:skido   
/**
  * регистрация юзера по имейл
  * если регистрация для покупки, то передаются параметры рекомендатель и урл
  * @param type $affiliate_id
  * @param type $url_id
  * @return type
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionUser($affiliate_id = null, $url_id = null)
 {
     $request = Yii::$app->request;
     $model = new \app\models\registration\UserForm();
     if ($request->isAjax && $model->load($request->post())) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load($request->post()) && $model->validate()) {
         $user = User::findByUsername($model->email);
         if (!$user) {
             $user = $model->save();
         }
         $user->setCookie();
         if ($affiliate_id === null || $url_id === null) {
             Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту');
             return $this->goHome();
         }
         $url = Url::findOne($url_id);
         if (!$url) {
             throw new \yii\web\NotFoundHttpException('Урл не найден');
         }
         $user->purchase($affiliate_id, $url);
         return $this->redirect($url->link);
     }
     return $this->render('user', ['model' => $model]);
 }

作者:chaimvai    项目:linet   
public function actionUser()
 {
     //make a db con or go back
     $db = new InstallConfig();
     try {
         $db->con();
     } catch (\yii\db\Exception $e) {
         return $this->render('config', array('model' => $db, "error" => "No DB"));
     }
     if (!User::find()->All() == null) {
         return $this->redirect('?r=install/finish');
         //Yii::$app->end();
     }
     //user
     $model = new User();
     $model->scenario = 'create';
     $model->language = 'he_il';
     $model->timezone = 'Asia/Jerusalem';
     if ($model->load(Yii::$app->request->post())) {
         //$model->save();
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return \yii\bootstrap\ActiveForm::validate($model);
         }
         if ($model->save()) {
             $this->redirect('?r=install/finish');
         }
     }
     return $this->render('user', array('model' => $model));
 }

作者:cheaterB    项目:yii2-users-modul   
public function saveData()
 {
     if ($this->model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             // perform AJAX validation
             echo ActiveForm::validate($this->model);
             Yii::$app->end();
             return '';
         }
         /** @var User|bool $registeredUser */
         $registeredUser = $this->model->register();
         if ($registeredUser !== false) {
             $module = UsersModule::module();
             // login registered user if there's no need in confirmation
             $shouldLogin = $module->allowLoginInactiveAccounts || $module->emailConfirmationNeeded === false;
             if ($module->emailConfirmationNeeded === true && $registeredUser->is_active) {
                 $shouldLogin = true;
             }
             if ($shouldLogin && $registeredUser->login(UsersModule::module()->loginDuration)) {
                 $returnUrl = Yii::$app->request->get('returnUrl');
                 if ($returnUrl !== null) {
                     return $this->controller->redirect($returnUrl);
                 }
             }
             return $this->controller->goBack();
         }
     }
     return '';
 }

作者:Bibihelpe    项目:Project201   
public function actionValidateOptionsForm()
 {
     $cOptFrm = new OptionsForm();
     if (Yii::$app->request->isAjax && $cOptFrm->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($cOptFrm);
     }
 }

作者:asinfotrac    项目:yii2-comment   
/**
  * @inheritdoc
  */
 public function run()
 {
     $form = ActiveForm::begin();
     echo $form->errorSummary($this->commentModel);
     echo $form->field($this->commentModel, 'title')->textInput(['maxlength' => true]);
     echo $form->field($this->commentModel, 'content')->textarea($this->textAreaOptions);
     echo Html::submitButton(empty($this->buttonLabel) ? Yii::t('app', 'Save') : $this->buttonLabel, $this->buttonOptions);
     ActiveForm::end();
 }

作者:sircovs    项目:yii2-sslab-blo   
public function run()
 {
     $request = Yii::$app->getRequest();
     $this->modelComment = new BlogComment();
     if ($request->isAjax && $this->modelComment->load($request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $errors = ActiveForm::validate($this->modelComment);
         echo json_encode($errors);
     }
 }

作者:size    项目:yii2-tod   
public function run()
 {
     parent::run();
     $model = new \app\models\ProjectSimpleForm();
     $form = ActiveForm::begin(['id' => 'project-simple-form', 'action' => ['/project/simplecreate'], 'layout' => 'inline', 'validateOnChange' => false, 'validateOnBlur' => false]);
     echo $form->field($model, 'title')->textInput(['maxlength' => 255, 'class' => 'form-control input-sm'])->label(false);
     echo '<div class="form-group">' . Html::submitButton(Yii::t('app', 'Create'), ['class' => 'btn btn-sm btn-success', 'style' => 'margin: 5px 5px 5px 0;']) . Html::resetButton(Yii::t('app', 'Cancel'), ['class' => 'btn btn-xs', 'style' => 'margin: 5px;']) . '</div>';
     ActiveForm::end();
     $this->registerJs();
 }

作者:Brother-Simo    项目:easyi   
public function api_form($options = [])
 {
     $model = new Subscriber();
     $options = array_merge($this->_defaultFormOptions, $options);
     ob_start();
     $form = ActiveForm::begin(['enableAjaxValidation' => true, 'action' => Url::to(['/admin/subscribe/send']), 'layout' => 'inline']);
     echo Html::hiddenInput('errorUrl', $options['errorUrl'] ? $options['errorUrl'] : Url::current([self::SENT_VAR => 0]));
     echo Html::hiddenInput('successUrl', $options['successUrl'] ? $options['successUrl'] : Url::current([self::SENT_VAR => 1]));
     echo $form->field($model, 'email')->input('email', ['placeholder' => 'E-mail']);
     echo Html::submitButton(Yii::t('easyii/subscribe/api', 'Subscribe'), ['class' => 'btn btn-primary', 'id' => 'subscriber-send']);
     ActiveForm::end();
     return ob_get_clean();
 }

作者:mademingshiw    项目:todolis   
public function actionInfo($id = '')
 {
     $model = new MenuForm();
     if (Yii::$app->request->isAjax && \Yii::$app->request->post('ajax', '') == 'info-form' && $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->save();
         Yii::$app->end();
     }
     $model->update($id);
     return $this->render('info', ['model' => $model]);
 }

作者:sgsan    项目:yii.projec   
public function actionRegister()
 {
     $model = new SignupForm();
     $model->scenario = 'short_register';
     if (\Yii::$app->request->isAjax && \Yii::$app->request->isPost) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->signup()) {
         print_r($model->getAttributes());
         die;
     }
     return $this->render("register", ['model' => $model]);
 }

作者:dram100    项目:bogda   
public function actionPassword_change()
 {
     $model = new \app\models\Form\PasswordNew();
     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->action(\Yii::$app->user->identity)) {
         Yii::$app->session->setFlash('contactFormSubmitted');
         return $this->refresh();
     } else {
         return $this->render(['model' => $model]);
     }
 }

作者:GAMIT    项目:yii2-multiple-inpu   
public function run()
 {
     Yii::setAlias('@unclead-examples', realpath(__DIR__ . '/../'));
     $model = new ExampleModel();
     $request = Yii::$app->getRequest();
     if ($request->isPost && $request->post('ajax') !== null) {
         $model->load(Yii::$app->request->post());
         Yii::$app->response->format = Response::FORMAT_JSON;
         $result = ActiveForm::validate($model);
         return $result;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
     }
     return $this->controller->render('@unclead-examples/views/example.php', ['model' => $model]);
 }

作者:HaseProgra    项目:royalteam   
public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     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->login()) {
         return $this->goBack();
     }
     return $this->render('login_form', ['model' => $model]);
 }

作者:karli    项目:construction_compan   
public function actionRegister()
 {
     $model = new SignupForm();
     //$model->scenario = 'short_register';
     if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
         if ($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->signup()) {
         Yii::$app->session->setFlash('success', 'Success register');
     }
     return $this->render('register', ['model' => $model]);
 }

作者:scorp7mi    项目:yi   
public function actionContact()
 {
     $this->layout = 'inner';
     $model = new ContactForm();
     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->validate()) {
         $body = " <div>Body: <b> " . $model->body . " </b></div>";
         $body .= " <div>Email: <b> " . $model->email . " </b></div>";
         Yii::$app->common->sendMail($model->subject, $body);
         print 'Send success';
         die;
     }
     return $this->render('contact', ['model' => $model]);
 }

作者:promo-p    项目:cm   
public function run()
 {
     $this->options['class'] = 'ajax-form';
     parent::run();
     $content = ob_get_clean();
     return Html::tag('div', $content, ['class' => 'ajax-form-wrapper', 'style' => "max-width:{$this->maxWidth}px"]);
 }

作者:semn    项目:tp0   
public function field($model, $attribute, $options = [])
 {
     if (!isset($options['labelOptions']['label'])) {
         $options['labelOptions']['label'] = Html::encode($model->getAttributeLabel($attribute)) . ':';
     }
     return parent::field($model, $attribute, $options);
 }

作者:elitedivisio    项目:amos-cor   
public function init()
 {
     $this->fieldConfig = ['template' => "<div class=\"row\">\n                <div class=\"col-xs-6\">{label}</div>\n                <div class=\"col-xs-6\"> <span class=\"tooltip-field pull-right\"> {hint} </span> <span class=\"tooltip-error-field pull-right\"> {error} </span> </div>\n            \n<div class=\"col-xs-12\">{input}</div>\n            </div>"];
     $this->fieldClass = ActiveField::className();
     echo Html::tag('span', AmosIcons::show('alert'), ['id' => 'errore-alert-common', 'class' => 'errore-alert bk-noDisplay', 'title' => \Yii::t('app', 'La tab contiene degli errori')]);
     parent::init();
 }


问题


面经


文章

微信
公众号

扫码关注公众号