search
HomePHP FrameworkYIIGet started using the yii framework

Get started using the yii framework

Nov 01, 2019 pm 03:47 PM
yiigoodframe

Get started using the yii framework

Yii installation and basic configuration

Yii is a high-performance PHP framework suitable for developing WEB 2.0 applications. You can check the features of Yii on the Yii Chinese official website (see foreign websites as well). The installation of Yii is very simple. The official provides direct download. After downloading, you can use it as long as you have a local PHP environment. You can click here to download the official Yii. In China, there may be problems with slow downloads or download failures. I have uploaded a yii-basic version. If you need it, you can click on the corresponding version to download.

Recommended study: "chuanzhipod Yii development large mall project video tutorial"

After downloading, unzip to the php environment path, I am Wampserver is installed locally, so put it directly in the site path corresponding to wampserver. After decompressing, first check whether the local PHP environment is suitable for running this version of YII. You can view the requirements.php file in the basic directory in the browser:

Get started using the yii framework

See the above prompts , indicating that the local php version supports the operation of this Yii version.

Then visit: http://localhost/basic/web/index.php. If you install it for the first time, the following error will appear

yii\web\Request::cookieValidationKey must be configured with a secret key.

We also need to perform relevant configuration before it can be used. Find the cookieValidationKey configured in the basic/config/web.php file (to prevent cookie attacks.):

Get started using the yii framework

Enter a random string and revisit the following http://localhost/ basic/web/index.php, get it done:

Get started using the yii framework

Usage of controller

controller is written uniformly in the controllers directory, and the first letter of the file name is capitalized, starting with controller At the end, and need to inherit the controller, I created a new HelloController.php file below:

Get started using the yii framework

For testing, we create a new action in HelloController.php

<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
/**
* 
*/
class HelloController extends Controller
{
    public function actionIndex()
    {
        echo "hello world";
    }
}
?>

Then open http://localhost/basic/web/index.php?r=hello/index in the browser, and the browser can display hello world

where: hello represents which controller, index represents the control Specific operations in the server

Simple processing and storage location of session

We first modify the actionIndex above, add a session

  public function actionIndex()
    {
        $session = Yii::$app->session;
        $session->open();
        $session[&#39;id&#39;]="123456";
        echo $session[&#39;id&#39;];
        echo &#39;<br/>&#39;;       
        echo "hello world";
    }

, and then enter: http in the browser ://localhost/basic/web/index.php?r=hello/index, press F12 to open the debugging window to view:

Get started using the yii framework

There is one more PHPSESSID in the cookie, PHPSESSID What is its function? We know that the session can be used to temporarily store some data information, which is valid until the browser is closed. But how does the server distinguish between different sessions? It is through sessionID, which is PHPSESSID here. The browser will send a cookie (including PHPSESSID) to the server every time it sends a request. PHP uses PHPSESSID to distinguish each session.

So where is this PHPSESSID stored? We can open the php->php.ini file and search for session.save_path:

Get started using the yii framework

According to the above path, open D:\wamp\tmp,

Get started using the yii framework

There happens to be a file, and the file name is exactly the same as the value corresponding to the PHPSESSID above

Yii stores session data as a file on the server by default. Of course, we can also Set to save the session to the data table.

The above is the detailed content of Get started using the yii framework. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Yii and PHP: Developing Dynamic WebsitesYii and PHP: Developing Dynamic WebsitesApr 28, 2025 am 12:09 AM

Yii and PHP can create dynamic websites. 1) Yii is a high-performance PHP framework that simplifies web application development. 2) Yii provides MVC architecture, ORM, cache and other functions, which are suitable for large-scale application development. 3) Use Yii's basic and advanced features to quickly build a website. 4) Pay attention to configuration, namespace and database connection issues, and use logs and debugging tools for debugging. 5) Improve performance through caching and optimization queries, and follow best practices to improve code quality.

Yii's Features: Examining Its AdvantagesYii's Features: Examining Its AdvantagesApr 27, 2025 am 12:03 AM

The Yii framework stands out in the PHP framework, and its advantages include: 1. MVC architecture and component design to improve code organization and reusability; 2. Gii code generator and ActiveRecord to improve development efficiency; 3. Multiple caching mechanisms to optimize performance; 4. Flexible RBAC system to simplify permission management.

Beyond the Hype: Assessing Yii's Role TodayBeyond the Hype: Assessing Yii's Role TodayApr 25, 2025 am 12:27 AM

Yii remains a powerful choice for developers. 1) Yii is a high-performance PHP framework based on the MVC architecture and provides tools such as ActiveRecord, Gii and cache systems. 2) Its advantages include efficiency and flexibility, but the learning curve is steep and community support is relatively limited. 3) Suitable for projects that require high performance and flexibility, but consider the team technology stack and learning costs.

Yii in Action: Current Applications and ProjectsYii in Action: Current Applications and ProjectsApr 24, 2025 am 12:03 AM

Yii framework is suitable for enterprise-level applications, small and medium-sized projects and individual projects. 1) In enterprise-level applications, Yii's high performance and scalability make it outstanding in large-scale projects such as e-commerce platforms. 2) In small and medium-sized projects, Yii's Gii tool helps quickly build prototypes and MVPs. 3) In personal and open source projects, Yii's lightweight features make it suitable for small websites and blogs.

Using Yii: Creating Robust and Scalable Web SolutionsUsing Yii: Creating Robust and Scalable Web SolutionsApr 23, 2025 am 12:16 AM

The Yii framework is suitable for building efficient, secure and scalable web applications. 1) Yii is based on the MVC architecture and provides component design and security features. 2) It supports basic CRUD operations and advanced RESTfulAPI development. 3) Provide debugging skills such as logging and debugging toolbar. 4) It is recommended to use cache and lazy loading for performance optimization.

Yii's Purpose: Building Web Applications Quickly and EfficientlyYii's Purpose: Building Web Applications Quickly and EfficientlyApr 22, 2025 am 12:07 AM

Yii's purpose is to enable developers to quickly and efficiently build web applications. Its implementation is implemented through the following methods: 1) Component-based design and MVC architecture to improve code maintainability and reusability; 2) Gii tools automatically generate code to improve development speed; 3) Lazy loading and caching mechanism optimization performance; 4) Flexible scalability to facilitate integration of third-party libraries; 5) Provide RBAC functions to handle complex business logic.

Yii's Versatility: From Simple Sites to Complex ProjectsYii's Versatility: From Simple Sites to Complex ProjectsApr 21, 2025 am 12:08 AM

Yiiisversatileavssuitable Projectsofallsizes.1) Simple Sites, YiiOofferseassetupandrapiddevelopment.2) ForcomplexProjects, ITModularityandrbacSystemManagescalabilityandSecurity effective.

Yii and the Future of PHP FrameworksYii and the Future of PHP FrameworksApr 20, 2025 am 12:11 AM

The Yii framework will continue to play an important role in the future development of PHP frameworks. 1) Yii provides efficient MVC architecture, powerful ORM system, built-in caching mechanism and rich extension libraries. 2) Its componentized design and flexibility make it suitable for complex business logic and RESTful API development. 3) Yii is constantly updated to adapt to modern PHP features and technical trends, such as microservices and containerization.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software