


How to use Yii to insert a comment form into the article details page of a single-user blog system
This article mainly introduces Yii's method of inserting a comment form into the article details page of a single-user blog system. It analyzes the specific skills of Yii to implement the comment form function on the article details page with examples. Friends who need it can refer to it
The example of this article describes Yii's method of inserting a comment form into the article details page of a single-user blog system. Share it with everyone for your reference, the details are as follows:
action part:
<?php function test($objs) { $objs->var=10; } class one { public $var=1; } $obj=new one(); echo $obj->var.'<p>'; test($obj); echo $obj->var; exit;
PostController.php page:
... /** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $post=$this->loadModel($id); $comment=$this->newComment($post); $this->render('view',array( 'model'=>$post, 'comment'=>$comment, )); } protected function newComment($post) { $comment=new Comment(); if(isset($_POST['Comment'])) { $comment->attributes=$_POST['Comment']; if($post->addComment($comment))//============================== { if($comment->status==Comment::STATUS_PENDING) Yii::app()->user->setFlash('commentSubmitted','Thank you...'); $this->refresh(); } } return $comment; } ...
models/Post.php page:
... public function addComment($comment) { if(Yii::app()->params['commentNeedApproval']) $comment->status=Comment::STATUS_PENDING; else $comment->status=Comment::STATUS_APPROVED; $comment->post_id=$this->id; return $comment->save(); } ...
post/view.php page:
... <p id="comments"> <h3>Leave a Comment</h3> <?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?> <p class="flash-success"> <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?> </p> <?php else: ?> <?php $this->renderPartial('/comment/_form',array( 'model'=>$comment, )); ?> <?php endif; ?> </p><!-- comments --> ...
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Usage analysis of the front-end resource package that comes with the Yii framework in PHP
About Yii Implementation of methods for handling front and back logins
The above is the detailed content of How to use Yii to insert a comment form into the article details page of a single-user blog system. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Usage of MINUS in SQL and specific code examples In SQL, MINUS is an operator used to perform a difference operation between two result sets. It is used to delete the same rows from the first result set as in the second result set. The result set returned by the MINUS operator will contain rows that exist only in the first result set. The following uses specific code examples to demonstrate the usage of MINUS: Assume there are two tables - "table1" and "table2", their structures are as follows: Table name: table1 field

SolutionYes,Wecaninsertnullvaluestoalisteasilyusingitsadd()method.IncaseofListimplementationdoesnotsupportnullthenitwillthrowNullPointerException.Syntaxbooleanadd(Ee) Appends the specified element to the end of this list. Type parameter E − The runtime type of the element. Parameter e − element to be appended to this list

1. Open the wps software and enter the wps text operation interface. 2. Find the insert option in this interface. 3. Click the Insert option and find the Shape option in its editing area. 4. Click the shape option and find the recommended option in its sub-menu. 5. Find the China map option in the recommended options. 6. Click on the China map option and drag it with the left mouse button in the editing input area to get the China map we need.

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

In the current information age, big data, artificial intelligence, cloud computing and other technologies have become the focus of major enterprises. Among these technologies, graphics card rendering technology, as a high-performance graphics processing technology, has received more and more attention. Graphics card rendering technology is widely used in game development, film and television special effects, engineering modeling and other fields. For developers, choosing a framework that suits their projects is a very important decision. Among current languages, PHP is a very dynamic language. Some excellent PHP frameworks such as Yii2, Ph

As the Internet continues to develop, the demand for web application development is also getting higher and higher. For developers, developing applications requires a stable, efficient, and powerful framework, which can improve development efficiency. Yii is a leading high-performance PHP framework that provides rich features and good performance. Yii3 is the next generation version of the Yii framework, which further optimizes performance and code quality based on Yii2. In this article, we will introduce how to use Yii3 framework to develop PHP applications.

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on
