CommentController::actionCreate PHP Method

actionCreate() public method

If creation is successful, the browser will be redirected to the 'view' page.
public actionCreate ( )
    public function actionCreate()
    {
        $model = new Comment();
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);
        if (isset($_POST['Comment'])) {
            $model->attributes = $_POST['Comment'];
            if ($model->save()) {
                $this->redirect(array('view', 'id' => $model->id));
            }
        }
        $this->render('create', array('model' => $model));
    }

Usage Example

Beispiel #1
0
<div class="comment-box-title">
    <?php 
echo Yii::t('comment', 'Reader\'s comments');
?>
</div>
<?php 
Yii::import('application.modules.frontend.controllers.CommentController');
$commentObj = new CommentController('comment_create');
$commentObj->actionCreate();
?>
<div class="my-comments-field">
    <?php 
if (!empty($comments)) {
    $arr = array('created_date' => Yii::t('comment', 'According to created date'), 'famous' => Yii::t('comment', 'According to the famous'));
    ?>
        <div class="According"><?php 
    echo CHtml::dropdownlist('order', $order, $arr);
    ?>
</div><img src="<?php 
    echo Yii::app()->request->baseUrl;
    ?>
/themes/backend/img/loading_balls.gif" id="loading_balls_2" style="display: none; width: 20px; height: 20px; vertical-align: middle" />
        <?php 
}
$this->render('_commentChildren', array('comments' => $comments, 'allComments' => $allComments, 't' => 0, 'y' => 0, 'maxTreeLevel' => $maxTreeLevel, 'pageSize' => $pageSize));
?>
    <div class="comment-Cpagination">
        <?php 
$this->widget('application.components.myComment.MyLinkPager', array('pages' => $pages));
?>
    </div>