本文整理汇总了PHP中Pages::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Pages::validate方法的具体用法?PHP Pages::validate怎么用?PHP Pages::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pages
的用法示例。
在下文中一共展示了Pages::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
public function actionCreate()
{
//echo realpath(Yii::app()->baseUrl); return;
$model = new Pages();
$this->layout = 'layout_user';
// uncomment the following code to enable ajax-based validation
/*
if(isset($_POST['ajax']) && $_POST['ajax']==='pages-create-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
*/
if (isset($_POST['Pages'])) {
$model->attributes = $_POST['Pages'];
if ($model->validate()) {
$page = Pages::model()->find('id=:p_id', array(':p_id' => Yii::app()->session['pageId']));
$page->company_name = $_POST['Pages']['company_name'];
$page->type = $_POST['Pages']['type'];
$page->address = $_POST['Pages']['address'];
$page->description = $_POST['Pages']['description'];
$page->save();
// form inputs are valid, do something here
return;
}
}
$this->render('create', array('model' => $model));
}
示例2: actionCreate
public function actionCreate()
{
$this->breadcrumbs = array_merge($this->breadcrumbs, array('Создание страницы'));
$this->pageTitle = Yii::t('app', 'Создание страницы');
$model = new Pages();
$modelLang = new PagesLang();
if (Yii::app()->request->getPost('Pages')) {
$model->attributes = Yii::app()->request->getPost('Pages');
$modelLang->attributes = Yii::app()->request->getPost('PagesLang');
$transaction = Yii::app()->db->beginTransaction();
try {
$model->validate();
if (!$model->save()) {
throw new Exception('Ошибка при сохранении данных.');
}
$modelLang->page_id = $model->id;
$modelLang->lang = Yii::app()->sourceLanguage;
$modelLang->langs = "|" . Yii::app()->sourceLanguage . "|";
if (!$modelLang->save()) {
throw new Exception('Ошибка при сохранении данных.');
}
$transaction->commit();
Yii::app()->user->setFlash('success', Yii::t('app', 'Страница успешно создана'));
Yii::app()->request->redirect($this->createUrl('index'));
} catch (Exception $e) {
$transaction->rollBack();
$error = $e->getMessage();
}
}
$this->render('create', array('model' => $model, 'modelLang' => $modelLang));
}