当前位置: 首页>>代码示例>>PHP>>正文


PHP Staff::validate方法代码示例

本文整理汇总了PHP中Staff::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Staff::validate方法的具体用法?PHP Staff::validate怎么用?PHP Staff::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Staff的用法示例。


在下文中一共展示了Staff::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 public function actionCreate()
 {
     $model = new Staff();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile), 'staff-form');
     if (isset($_POST['Staff'])) {
         $model->attributes = $_POST['Staff'];
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $realp = PasswordHelper::generateStrongPassword();
             $model->password = $realp;
             $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password);
             $model->password = PasswordHelper::hashPassword($model->password);
             $model->status = 0;
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 if (!empty($_POST['Profile']['group_id'])) {
                     foreach ($_POST['Profile']['group_id'] as $groupid) {
                         $userGroup = new UserGroup();
                         $userGroup->profile_id = $model->id;
                         $userGroup->group_id = $groupid;
                         $userGroup->save();
                     }
                 }
                 $passwordHistory = new PasswordHistory();
                 $passwordHistory->profile_id = $model->id;
                 $passwordHistory->password = $model->password;
                 $passwordHistory->save();
                 if (Yii::app()->getModule('user')->sendActivationMail) {
                     $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: " . $model->username . "<br/>Password: " . $realp . "<br/>", array('{activation_url}' => $activation_url)));
                 }
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->redirect(array('view', 'id' => $model->id));
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'An error occured while trying to create new user, please try again.');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->render('create', array('model' => $model, 'profile' => $profile));
             }
         } else {
             $profile->validate();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
开发者ID:Rudianasaja,项目名称:cycommerce,代码行数:57,代码来源:StaffController.php

示例2: actionCreate

 public function actionCreate()
 {
     $this->hasPrivilege(Acl::ACTION_CREATE);
     $this->pageTitle = Lang::t('New ' . $this->resourceAddLabel);
     // User information
     $user_model = new Users(ActiveRecord::SCENARIO_CREATE);
     $user_model->status = Users::STATUS_ACTIVE;
     $user_model_class_name = $user_model->getClassName();
     //personal information
     $person_model = new Person();
     $person_model_class_name = $person_model->getClassName();
     //staff information
     $staff_model = new Staff(ActiveRecord::SCENARIO_CREATE);
     $staff_model->status = Staff::STATUS_ACTIVE;
     $staff_model_class_name = $staff_model->getClassName();
     if (Yii::app()->request->isPostRequest) {
         $user_model->attributes = $_POST[$user_model_class_name];
         $person_model->attributes = $_POST[$person_model_class_name];
         $staff_model->attributes = $_POST[$staff_model_class_name];
         $person_model->validate();
         $staff_model->validate();
         $user_model->validate();
         if (!$user_model->hasErrors() && !$staff_model->hasErrors() && !$person_model->hasErrors()) {
             if ($user_model->save(FALSE)) {
                 $person_model->id = $user_model->id;
                 if ($person_model->save(FALSE)) {
                     $staff_model->person_id = $person_model->id;
                     $staff_model->save(FALSE);
                     Yii::app()->user->setFlash('success', Lang::t('Staff added successfully.'));
                     $this->redirect(Controller::getReturnUrl($this->createUrl('view', array('id' => $staff_model->id))));
                 }
             }
         }
     }
     $this->render('create', array('staff_model' => $staff_model, 'user_model' => $user_model, 'model' => $person_model));
 }
开发者ID:jacjimus,项目名称:furahia_mis,代码行数:36,代码来源:DefaultController.php


注:本文中的Staff::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。