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