本文整理汇总了PHP中Entry::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Entry::validate方法的具体用法?PHP Entry::validate怎么用?PHP Entry::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entry
的用法示例。
在下文中一共展示了Entry::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionEntry
public function actionEntry()
{
//关闭页面布局
$this->layout = false;
//创建表单模型
$entry = new Entry();
//如果是Post请求提交
if (Yii::$app->request->getIsPost()) {
//表单模型设置属性为post值
$entry->setAttributes(Yii::$app->request->post());
//表单模型数据验证
if ($entry->validate()) {
//正确即保存数据
$result = $entry->save();
//返回保存后的信息
if ($result) {
var_dump($entry->attributes);
} else {
var_dump($entry->getErrors());
}
} else {
//返回错误提示
var_dump($entry->getErrors());
}
} else {
//如果不是Post请求,正常显示模板
return $this->render('entry', ['model' => $entry]);
}
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store($logbook_id)
{
$logbook = Logbook::findOrFail($logbook_id);
if ($logbook->user_id == Auth::user()->id or $logbook->user_id == 0) {
$entry = new Entry(Input::only('title', 'body', 'started_at', 'finished_at', 'evidence_id', 'who', 'what', 'where', 'which', 'way', 'when', 'why'));
$entry->logbook_id = $logbook->id;
if ($entry->validate()) {
$entry->save();
} else {
return View::make('entries.create', ['entry' => $entry, 'logbook' => $logbook])->withErrors($entry->validator());
}
return Redirect::to(route('logbooks.show', [$logbook->id]))->with('message', ['content' => 'Entry met succes aangemaakt!', 'class' => 'success']);
} else {
return Redirect::to(route('logbooks.show', [$logbook->id]))->with('message', ['content' => 'Geen rechten om entry weg te schrijven!', 'class' => 'danger']);
}
}
示例3: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Entry();
$model->owner_by = Yii::app()->user->getId();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Entry'])) {
$model->attributes = $_POST['Entry'];
if ($model->validate()) {
$fileName = $this->getAndSaveUploadedFile($model);
if ($fileName) {
$model->imagepath = $fileName;
}
if ($model->save(false)) {
$this->redirect(array('view', 'id' => $model->id));
}
}
}
$this->render('create', array('model' => $model));
}