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


PHP Requirement::validate方法代碼示例

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


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

示例1: actionRequirement

 public function actionRequirement()
 {
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile(Yii::app()->baseUrl . '/css/requirement.css', 'screen');
     $model = new Requirement();
     // uncomment the following code to enable ajax-based validation
     /*
     if(isset($_POST['ajax']) && $_POST['ajax']==='requirement-requirement-form')
     {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     */
     if (isset($_POST['Requirement'])) {
         $model->attributes = $_POST['Requirement'];
         if ($model->validate()) {
             // form inputs are valid, do something here
             return;
         }
     }
     $this->render('requirement', array('model' => $model));
 }
開發者ID:ngdvan,項目名稱:lntguitar,代碼行數:22,代碼來源:SongController.php

示例2: actionPost

 public function actionPost()
 {
     Yii::beginProfile('requirement_post');
     $userId = Yii::app()->user->id;
     $model = new Requirement();
     $modelState = new GeoState();
     $requirementCities = new RequirementCities();
     $requirementAmenities = new RequirementAmenities();
     $requirementPropertyTypes = new RequirementPropertyTypes();
     $requirementBedrooms = new RequirementBedrooms();
     $amenities = null;
     $propertyTypes = null;
     $bedrooms = null;
     $cities = null;
     $this->performAjaxValidation(array($model));
     if (isset($_POST['minsubmit'])) {
         $modelState->attributes = $_POST['GeoState'];
     } elseif (isset($_POST['PostRequirementMin'])) {
         $model->attributes = $_POST['Requirement'];
         if (isset($_POST['GeoCity']['city'])) {
             $cities[0] = $_POST['GeoCity']['city'];
         }
     } elseif (isset($_POST['submit'])) {
         $model->attributes = $_POST['Requirement'];
         $amenities = isset($_POST['amenity_id']) ? $_POST['amenity_id'] : null;
         $propertyTypes = isset($_POST['property_type_id']) ? $_POST['property_type_id'] : null;
         $bedrooms = isset($_POST['bedrooms']) ? $_POST['bedrooms'] : null;
         $cities = isset($_POST['city_id']) ? $_POST['city_id'] : null;
         $valid = true;
         $model->user_id = $userId;
         $valid = $valid && $model->validate();
         if ($propertyTypes == null) {
             $requirementPropertyTypes->addError('property_type_id', 'Property Type cannot be blank.');
             $valid = false;
         }
         if ($cities == null || empty($cities) || $cities[0] == '') {
             $requirementCities->addError('city_id', 'City cannot be blank.');
             $valid = false;
         }
         if ($valid) {
             $data = $_POST['Requirement'];
             if ($data['covered_area_from'] == null) {
                 $data['covered_area_from'] == 0;
             }
             if ($data['min_price'] == null) {
                 $data['min_price'] = 0;
             }
             $requirement = RequirementApi::createRequirement($userId, $data);
             if (!$requirement->hasErrors()) {
                 $addAmenities = true;
                 $addCities = true;
                 $addBedrooms = true;
                 $addPropertyTypes = true;
                 if (isset($_POST['amenity_id'])) {
                     $addAmenities = RequirementAmenitiesApi::addAmenitiesForRequirement($requirement->id, $_POST['amenity_id']);
                 }
                 if (isset($_POST['city_id'])) {
                     $addCities = RequirementCitiesApi::addCitiesForRequirement($requirement->id, $_POST['city_id']);
                 }
                 if (isset($_POST['bedrooms']) && !empty($_POST['bedrooms'])) {
                     $addBedrooms = RequirementBedroomsApi::addBedroomForRequirement($requirement->id, $_POST['bedrooms']);
                 }
                 if (isset($_POST['property_type_id'])) {
                     $addPropertyTypes = RequirementPropertyTypesApi::addPropertyTypesForRequirement($requirement->id, $_POST['property_type_id']);
                 }
                 if ($addAmenities && $addCities && $addBedrooms && $addPropertyTypes) {
                     //$this->refresh();
                     $this->redirect('/requirement/' . $requirement->id);
                 } else {
                     RequirementAmenitiesApi::deleteAllAmenitiesForRequirement($requirement->id);
                     RequirementCitiesApi::deleteAllCitiesForRequirement($requirement->id);
                     RequirementBedroomsApi::deleteAllBedroomsForRequirement($requirement->id);
                     RequirementPropertyTypesApi::deleteAllPropertyTypesForRequirement($requirement->id);
                 }
             } else {
                 if (isset($property->id)) {
                     PropertyApi::deletePropertyById($property->id);
                 }
             }
         }
     }
     $this->render('post', array('model' => $model, 'modelState' => $modelState, 'requirementCities' => $requirementCities, 'requirementAmenities' => $requirementAmenities, 'requirementPropertyTypes' => $requirementPropertyTypes, 'requirementBedrooms' => $requirementBedrooms, 'amenities' => $amenities, 'propertyTypes' => $propertyTypes, 'bedrooms' => $bedrooms, 'cities' => $cities));
     Yii::endProfile('requirement_post');
 }
開發者ID:romeo14,項目名稱:wallfeet,代碼行數:84,代碼來源:RequirementController.php


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