本文整理汇总了PHP中Projects::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Projects::validate方法的具体用法?PHP Projects::validate怎么用?PHP Projects::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Projects
的用法示例。
在下文中一共展示了Projects::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionStart
public function actionStart()
{
$model = new Projects();
// uncomment the following code to enable ajax-based validation
/*
if(isset($_POST['ajax']) && $_POST['ajax']==='projects-start-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
*/
if (isset($_POST['Projects'])) {
$model->attributes = $_POST['Projects'];
$model->creationDateTime = date('Y-m-d H:i:s');
if ($model->validate()) {
$model->save();
$this->redirect('industry/index');
}
}
$this->render('start', array('model' => $model));
}
示例2: actionPost
public function actionPost()
{
Yii::beginProfile('project_post');
$model = new Projects();
$modelCity = new GeoCity();
$modelState = new GeoState();
$modelAmenities = new ProjectAmenities();
$modelImages = new ProjectImages();
$amenities = null;
if (isset($_POST['submit'])) {
$model->attributes = $_POST['Projects'];
$modelImages->attributes = $_POST['ProjectImages'];
$amenities = isset($_POST['amenity_id']) ? $_POST['amenity_id'] : null;
/*if($amenities){
$amenity_data = null;
foreach($amenities as $i=>$amenity){
if($i!=0)
$amenity_data.=',';
$amenity_data.=$amenity;
}
$amenities = $amenity_data;
}*/
$valid = true;
$model->user_id = Yii::app()->user->id;
$valid = $valid && $model->validate();
if ($amenities == null) {
$modelAmenities->addError('amenity_id', 'Amenities cannot be blank.');
$valid = false;
}
$modelImages->image = CUploadedFile::getInstance($modelImages, 'image');
if ($modelImages->image == "") {
$modelImages->addError('image', 'Image cannot be blank.');
$valid = false;
}
if ($valid) {
$data = $_POST['Projects'];
$project = ProjectApi::createProject('1', $data);
if (!$project->hasErrors()) {
$amenities = ProjectAmenitiesApi::addAmenitiesForProject($project->id, $_POST['amenity_id']);
$imagePath = ImageUtils::uploadImage($modelImages, 'image');
if ($amenities && $imagePath) {
$image = ProjectImagesApi::addImage($project->id, $imagePath);
if (!$image) {
ProjectApi::deleteProjectById($project->id);
ProjectAmenitiesApi::deleteAllAmenitiesForProject($project->id);
}
if (file_exists($imagePath)) {
unlink($imagePath);
}
$data = array();
$user = UserApi::getUserById($project->user_id);
$user ? $data["user"] = $user->id : null;
$data["project"] = $project->id;
EmailApi::sendEmail($user->email_id, "ACTIVITY.PROJECT.NEW", $data);
$this->redirect('/project/' . $project->id);
} else {
ProjectApi::deleteProjectById($project->id);
ProjectAmenitiesApi::deleteAllAmenitiesForProject($project->id);
}
} else {
if (isset($property->id)) {
ProjectApi::deleteProjectById($property->id);
}
}
}
}
$this->render('post', array('model' => $model, 'modelState' => $modelState, 'modelCity' => $modelCity, 'modelAmenities' => $modelAmenities, 'modelImages' => $modelImages, 'amenities' => $amenities));
Yii::endProfile('project_post');
}