Learn Yii - 1 Code Examples & CST Typing Practice Test
Yii is a high-performance, component-based PHP framework for rapidly developing modern web applications. It emphasizes performance, security, and extensibility, following the MVC pattern and providing tools for both small and large-scale applications.
View all 1 Yii code examples →
Learn YII with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
Yii Simple Counter App
<?php
// controllers/CounterController.php
namespace app\controllers;
use Yii;
use yii\web\Controller;
class CounterController extends Controller {
public function actionIndex() {
$session = Yii::$app->session;
if (!$session->has('count')) { $session->set('count', 0); }
$count = $session->get('count');
return $this->render('index', ['count' => $count]);
}
public function actionIncrement() {
$session = Yii::$app->session;
$session->set('count', $session->get('count', 0) + 1);
return $this->redirect(['index']);
}
public function actionDecrement() {
$session = Yii::$app->session;
$session->set('count', $session->get('count', 0) - 1);
return $this->redirect(['index']);
}
public function actionReset() {
Yii::$app->session->set('count', 0);
return $this->redirect(['index']);
}
}
// views/counter/index.php
<h2>Counter: <?= $count ?></h2>
<form method='post' action='increment'><button type='submit'>+</button></form>
<form method='post' action='decrement'><button type='submit'>-</button></form>
<form method='post' action='reset'><button type='submit'>Reset</button></form>
Demonstrates a simple Yii controller and view for a counter using session for state persistence.
Frequently Asked Questions about Yii
What is Yii?
Yii is a high-performance, component-based PHP framework for rapidly developing modern web applications. It emphasizes performance, security, and extensibility, following the MVC pattern and providing tools for both small and large-scale applications.
What are the primary use cases for Yii?
Building modern web applications. Creating RESTful APIs. Developing enterprise-grade platforms. Implementing authentication and RBAC. Rapid prototyping with Gii code generator
What are the strengths of Yii?
High-performance and fast execution. Strong security features (CSRF, XSS, SQL injection prevention). Powerful code generation via Gii. Flexible, extensible, and component-based. Good for both small projects and enterprise solutions
What are the limitations of Yii?
Smaller community compared to Laravel or Symfony. Steeper learning curve for beginners. Less modern syntax than Laravel in some areas. Requires careful configuration for very large projects. Dependent on PHP environment and extensions
How can I practice Yii typing speed?
CodeSpeedTest offers 1+ real Yii code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.