mah.tab
سه شنبه 13 خرداد 1393, 15:17 عصر
سلام
من میخام فرم ایجاد پست رو در صفحه نمایش پستها (views/post/index.php) نمایش بدم ولی
وقتی در صفحه index.php عبارت
<?php $this->renderPartial('create', array('model'=>$model)); ?>
مینویسم کار نمیکنه
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Post;
// Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model);
if(isset($_POST['Post'])) { $model->attributes=$_POST['Post']; // $model->date = new CDbExpression('NOW()'); $model->id_user = Yii::app()->user->id; if($model->save()) $this->redirect(array('view','id'=>$model->post_id)); }
$this->render('create',array( 'model'=>$model, )); }
/** * Lists all models. */ public function actionIndex() { $dataProvider=new CActiveDataProvider('Post');
$criteria = new CDbCriteria; $criteria->order ='post_id DESC';
$total = Post::model()->count(); $pages = new CPagination($total); $pages->pageSize = 5; $pages->applyLimit($criteria); $posts = Post::model()->findAll($criteria); $this->render('index', array( 'posts' => $posts, 'pages' => $pages, 'dataProvider'=>$dataProvider, )); }
create.php
<?php/* @var $this PostController *//* @var $model Post */
$this->breadcrumbs=array( 'Posts'=>array('index'), 'Create',);
$this->menu=array( array('label'=>'List Post', 'url'=>array('index')), array('label'=>'Manage Post', 'url'=>array('admin')),);?>
<h1>Create Post</h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>x`
من میخام فرم ایجاد پست رو در صفحه نمایش پستها (views/post/index.php) نمایش بدم ولی
وقتی در صفحه index.php عبارت
<?php $this->renderPartial('create', array('model'=>$model)); ?>
مینویسم کار نمیکنه
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Post;
// Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model);
if(isset($_POST['Post'])) { $model->attributes=$_POST['Post']; // $model->date = new CDbExpression('NOW()'); $model->id_user = Yii::app()->user->id; if($model->save()) $this->redirect(array('view','id'=>$model->post_id)); }
$this->render('create',array( 'model'=>$model, )); }
/** * Lists all models. */ public function actionIndex() { $dataProvider=new CActiveDataProvider('Post');
$criteria = new CDbCriteria; $criteria->order ='post_id DESC';
$total = Post::model()->count(); $pages = new CPagination($total); $pages->pageSize = 5; $pages->applyLimit($criteria); $posts = Post::model()->findAll($criteria); $this->render('index', array( 'posts' => $posts, 'pages' => $pages, 'dataProvider'=>$dataProvider, )); }
create.php
<?php/* @var $this PostController *//* @var $model Post */
$this->breadcrumbs=array( 'Posts'=>array('index'), 'Create',);
$this->menu=array( array('label'=>'List Post', 'url'=>array('index')), array('label'=>'Manage Post', 'url'=>array('admin')),);?>
<h1>Create Post</h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>x`