本文整理汇总了PHP中Brand::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Brand::validate方法的具体用法?PHP Brand::validate怎么用?PHP Brand::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Brand
的用法示例。
在下文中一共展示了Brand::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doValidate
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aBrand !== null) {
if (!$this->aBrand->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aBrand->getValidationFailures());
}
}
if (($retval = SeriesPeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
if ($this->collModels !== null) {
foreach ($this->collModels as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
$this->alreadyInValidation = false;
}
return !empty($failureMap) ? $failureMap : true;
}
示例2: actionAjax
public function actionAjax()
{
if (Yii::app()->request->isAjaxRequest) {
if (isset($_POST['Brand']['id']) && !empty($_POST['Brand']['id'])) {
$model = $this->loadModel($_POST['Brand']['id']);
$model->attributes = $_POST['Brand'];
if ($model->validate()) {
if (Yii::app()->params['server'] == CAlexHelper::DEVELOPMENT || $_POST['Brand']['id'] > 60) {
if ($model->save()) {
$this->setNotice('Запись успешно обновлена');
$model = new Brand();
} else {
$this->setNotice('Fail');
}
} else {
$this->setNotice('You cant edit data on this site');
}
}
} else {
$model = new Brand();
$model->attributes = $_POST['Brand'];
if ($model->validate()) {
if ($model->save()) {
$this->setNotice('Запись успешно добавлена');
$model = new Brand();
} else {
$this->setNotice('Fail');
}
}
}
$this->renderPartial('ajaxForm', array('model' => $model));
} else {
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
}
示例3: postBrandAddNew
//.........这里部分代码省略.........
//as well as creates new image from given file
switch ($image_type) {
case 'image/png':
$image_res = imagecreatefrompng($image_temp);
break;
case 'image/gif':
$image_res = imagecreatefromgif($image_temp);
break;
case 'image/jpeg':
case 'image/pjpeg':
$image_res = imagecreatefromjpeg($image_temp);
break;
default:
$image_res = false;
}
if ($image_res) {
//Get file extension and name to construct new file name
$image_info = pathinfo($image_name);
$image_extension = strtolower($image_info["extension"]);
//image extension
$image_name_only = strtolower($image_info["filename"]);
//file name only, no extension
//create a random name for new image (Eg: fileName_293749.jpg) ;
$new_file_name = $image_name_only . '_' . rand(0, 9999999999.0) . '.' . $image_extension;
//folder path to save resized images and thumbnails
$thumb_save_folder = $destination_folder . $thumb_prefix . $new_file_name;
$image_save_folder = $destination_folder . $new_file_name;
//call normal_resize_image() function to proportionally resize image
if (normal_resize_image($image_res, $image_save_folder, $image_type, $max_image_size, $image_width, $image_height, $jpeg_quality)) {
//call crop_image_square() function to create square thumbnails
// if(!crop_image_square($image_res, $thumb_save_folder, $image_type, $thumb_square_size, $image_width, $image_height, $jpeg_quality))
//{
// die('Error Creating thumbnail');
// }
/* We have succesfully resized and created thumbnail image
We can now output image to user's browser or store information in the database*/
echo '<div align="center">';
// echo '<img src="/melkay/public/uploads/images/'.$thumb_prefix . $new_file_name.'" alt="Thumbnail">';
echo '<br />';
echo '<img src="/melkay/public/uploads/images/' . $new_file_name . '" alt="Resized Image">';
echo '</div>@@' . $new_file_name;
}
imagedestroy($image_res);
//freeup memory
}
}
exit;
}
$validation = \Brand::validate(\Input::all());
$input = \Input::all();
//print_r($input);
if ($validation->fails()) {
return \Redirect::back()->withErrors($validation)->withInput();
} else {
array_forget($input, "_token");
try {
if ($id == "") {
$brand = new \Brand();
foreach ($input as $key => $value) {
$brand->{$key} = $value;
}
if ($brand->save()) {
\Session::put("success_message", "Record Saved");
return \Redirect::back();
} else {
\Session::put("error_message", "Sorry, Unexpected Error! Record Could Not Be Saved");
return \Redirect::back();
}
} else {
$brand = \Brand::find($id);
array_forget($input, "_token");
foreach ($input as $key => $value) {
$brand->{$key} = $value;
}
if ($brand->update()) {
\Session::put("success_message", "Record Updated");
return \Redirect::back();
} else {
\Session::put("error_message", "Sorry, Unexpected Error! Record Could Not Be Saved");
return \Redirect::back();
}
}
} catch (ValidationException $e) {
\Session::put("error_message", $e->getMessage());
return \Redirect::back()->withInput()->withErrors($e->getErrors());
} catch (\Illuminate\Database\QueryException $e) {
\Session::put("error_message", $e->getMessage());
return \Redirect::back();
exit;
} catch (\PDOException $e) {
\Session::put("error_message", $e->getMessage());
return \Redirect::back();
//exit;
} catch (\Exception $e) {
\Session::put("error_message", $e->getMessage());
return \Redirect::back();
//exit;
}
}
}