本文整理汇总了PHP中News::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP News::validate方法的具体用法?PHP News::validate怎么用?PHP News::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类News
的用法示例。
在下文中一共展示了News::validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreates
public function actionCreates()
{
$model = new News();
$file = new File();
$model->member_id = Yii::app()->user->id;
$model->create_at = date('Y-m-d H:i:s');
$model->update_at = date('Y-m-d H:i:s');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['News']) && isset($_POST['File'])) {
$model->attributes = $_POST['News'];
$file->attributes = $_POST['File'];
$model->pic = 'noimage.jpg';
$model->validate();
$file->validate();
if ($model->getErrors() == null && $file->getErrors() == null) {
$file->file = CUploadedFile::getInstance($file, 'file');
if ($file->file != null) {
$filename = time() . '.' . $file->file->getExtensionName();
$file->file->saveAs(Yii::app()->params['pathUpload'] . $filename);
$model->pic = $filename;
} else {
$model->pic = 'noimage.jpg';
}
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->news_id));
}
}
}
$this->render('create', array('model' => $model, 'file' => $file));
}
示例2: actionCreate
public function actionCreate()
{
$this->breadcrumbs = array_merge($this->breadcrumbs, array('Создание новости'));
$this->pageTitle = Yii::t('app', 'Создание новости');
$model = new News();
if (Yii::app()->request->getPost('News')) {
$model->attributes = Yii::app()->request->getPost('News');
if ($model->validate()) {
if ($model->save()) {
Yii::app()->user->setFlash('success', Yii::t('app', 'Новость успешно добавлена'));
Yii::app()->request->redirect($this->createUrl('index'));
}
}
}
$this->render('create', array('model' => $model));
}
示例3: actionCreate
public function actionCreate()
{
if (Yii::app()->user->checkAccess('createNews') == false) {
throw new CHttpException(403);
}
$cases = new News();
if (isset($_POST['News'])) {
$cases->attributes = Yii::app()->request->getPost('News');
if ($cases->validate() && $cases->save()) {
$this->setFlashMessage(strtr('<strong>{link}</strong> 成功案例添加成功', array('{link}' => CHtml::link($cases->title, array('view', 'id' => $cases->primaryKey)))));
$this->redirect($this->getReturnUrl());
}
} else {
$cases->release_date = date('Y-m-d');
$cases->is_released = 1;
}
$this->breadcrumbs = array('成功案例' => array('index'), '添加');
$this->render('create', array('cases' => $cases, 'returnUrl' => $this->getReturnUrl()));
}
示例4: actionIndex
public function actionIndex()
{
$model = new News();
// uncomment the following code to enable ajax-based validation
/*
if(isset($_POST['ajax']) && $_POST['ajax']==='news-index-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
*/
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
if ($model->validate()) {
// form inputs are valid, do something here
return;
}
}
$this->render('index', array('model' => $model));
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$data = Input::all();
$validation = News::validate($data);
$news = new News();
if ($validation->fails()) {
return Redirect::to('news/create')->withErrors($validation)->withInput();
}
$file = Input::file('image');
$destinatonPath = 'public/storage/news';
$originalName = $file->getClientOriginalName();
$filename = rand(1, 10000) . $originalName;
$file->move($destinatonPath, $filename);
$news->title = $data['title'];
$news->content = $data['content'];
$news->image = $filename;
$news->date_added = date('Y-m-d H:i:s');
$news->save();
return Redirect::route('news.index')->with('message', 'Succesfull added news');
}