Changes
Recommended: " Chuanzhi Podcast Yii Development Large Mall Project Video Tutorial 》
Just like when the Yii2.0 era came, Yii1.0 will eventually be gloomy. The launch of Yii3.0 version is bound to set off waves in the Yii framework. So what is the difference between Yii3.0 and Yii2.0? What changes have been made?
Yii3.0 Framework Introduction
The Yii3.0 framework is a skeleton application best suited for quick project creation.
#The framework contains basic functionality including user login/logout and contact pages. It includes all common configurations, allowing you to focus on adding new features to your application.
Directory structure
config/ 包含应用配置public/ 包含入口脚本,已发布的资源和其他公开可用的文件,例如favicon.ico和robots.txt runtime/ 包含运行时生成的文件 vendor/ 包含依赖的第三方包 .env .env.dist composer.json docker-compose.yml
Requirements
The web server supports PHP 7.1 which is the minimum requirement for the Yii3.0 framework .
Installation
If you don’t have Composer, you can install it by following the instructions on getcomposer.org.
You can then install this project template using the following command:
composer create-project --prefer-dist --stability = dev yiisoft / yii-project-template myappcd myapp
This gives you an empty project to which you can add the application template, see below on how to add these projects part.
Depending on your system, you may need to provide write permissions for ./runtime and ./public/assets
CLI application
If you want to install and run your own console The console application required for the command can be implemented by loading the yiisoft/yii-base-cli package.
composer require yiisoft/yii-base-cli
You can now run yii help to see the available commands.
API Application
If you want to create an API, you can load it by loading [yiisoft/yii-base-api](https://github.com/yiisoft/yii- base-api) package to implement
composer require yiisoft/yii-base-api vendor/bin/yii serve -p 8081
You can access the API through http://localhost:8081/.
Web Application
Since web applications use client-side resources (such as CSS and Javascript), the resource allocation system is first selected
Option a: Asset-packagist and composer-merge-plugin (requires PHP only)
composer require "wikimedia/composer-merge-plugin" composer config repositories.ap '{"type": "composer", "url": "https://asset-packagist.org"}' composer config extra.merge-plugin.include "vendor/*/*/composer.assets.json"
Option b: Foxy (requires npm or yarn)
composer require "foxy/foxy:^1.0.0"
Now you can install the web application library and its dependencies Item
composer require yiisoft/yii-base-web vendor/bin/yii serve
You should now be able to access the application at http://localhost:8080/.
You can find more available application libraries on GitHub.
Docker
Clone the repository and create an environment configuration file
cp .env.dist .env
To run the installation, create bash from the PHP image
docker-compose run --rm php bash
And run the composer command above.
Start the application stack
docker-compose up -d
Access via browser
http://docker.host:30080
Configuration
##Database
return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2basic', 'username' => 'root', 'password' => '1234', 'charset' => 'utf8', ];Tips: - Yii will not create it for you Database, this must be done manually before you can access it. - Inspect and edit other files in the config/ directory to customize the application as needed. - For information on basic application testing, see the README in the tests directory.
Tests
The tests are located in the tests directory. Run directly from Docker image
docker run -it -v $PWD/yii-project:/app -w /app yiisoftware/yii2-php:7.2-apache bash
The above is the detailed content of The Yii3.0 era is coming, why not take a sneak peek?. For more information, please follow other related articles on the PHP Chinese website!

To add new validation rules in Yii, you only need to modify the rules() method of the model. 1. Open the model file such as User.php; 2. Add a new rule in the return array of the rules() method, in the format [Properties, Verifier, Options], such as ['age','integer','min'=>1,'max'=>120]; 3. You can use built-in validators such as 'required', 'email' or custom inline validators; 4. You can specify the scene or 'when' to set the conditions; 5. Finally, by calling validate() and checking getErrors() to test whether the rule takes effect. This process is complete and easy to implement.

Install Yii2: Use Composer to run composercreate-projectyiisoft/yii2-app-basicmyapp to create a project; 2. Set up the web server: enter the project directory and run phpyiiserve to start the development server; 3. Understand the directory structure: master the core directory uses config/, controllers/, models/, views/, web/ and other core directories; 4. Configure the database: Modify the DSN, username and password in config/db.php to connect to the database; 5. Use Gii to generate code: Enable the Gii module in config/web.php, and use

Create a search model (such as PostSearch) that inherits the autonomous model, define verification rules and implement search methods, and use ActiveDataProvider to manage query results; 2. Instantiate the search model in the controller and pass in request parameters to perform searches; 3. Use ActiveForm to build a search form in the view, display the results through GridView, set filterModel to enable column filtering; 4. Add public attributes to the associated fields (such as author_name) in the search model, and associate query through joinWith; 5. Optionally expand the filter logic, support date range, pull-down filtering, etc. This method uses Yii2 components to achieve high

To optimize database query performance, you must first ensure that the database design is reasonable, add indexes for columns involved in WHERE, JOIN, ORDERBY and GROUPBY, use composite indexes and avoid excessive indexing; 2. Use Yii's query caching function to cache frequently read and have fewer changes through the cache() method to reduce database access; 3. Optimize the use of ActiveRecord, avoid SELECT*, select only necessary fields, use asArray() to reduce memory overhead, and avoid N 1 query problems through with(); 4. Use joinWith() for complex queries or directly use createCommand() to execute native SQL for higher performance; 5.

Install and configure Codeception, use composerrequire--devcodeception/codeception and run bootstrap initialization; 2. Generate acceptancesuite and configure PhpBrowser or WebDriver through tests/acceptance.suite.yml; 3. Write a Cest test class to simulate user behavior, such as accessing pages, filling in forms, clicking buttons and verifying results; 4. Run vendor/bin/codeceptrunaccep after starting the local server and Selenium (such as using WebDriver)

DisabledebugmodeandsetYII_DEBUGtofalse,2.UploadcodeviaGit,SFTP,orCI/CDandruncomposerinstall--no-devonserver,3.InstallPHP7.4 withrequiredextensionsandconfigureApacheorNginxwithproperrewriterules,4.Setfilepermissionswithchmod755andchownforruntimeandweb

Common errors when using the Yii framework include configuration errors, database connection errors, and verification errors. 1. Configuration error: Check the config/web.php or config/main.php file to ensure there are no spelling errors or path errors. 2. Database connection error: Make sure the db.php file is configured correctly and the database server is running normally. 3. Verification error: Check the model rules to ensure that the verification settings meet application requirements.

Yii's QueryBuilder supports efficient and secure construction of complex database queries by providing smooth interfaces. 1. Use leftJoin() and other methods to achieve multi-table association and avoid field ambiguity; 2. Nesting subqueries in WHERE or SELECT to handle dynamic filtering or aggregated data; 3. Dynamically add where, orderBy and other conditions according to runtime conditions; 4. Combine groupBy() and having() to filter the aggregate results; 5. Use union() to merge query results compatible with multiple structures; 6. Securely insert SQL expressions through yii\db\Expression; 7. Combine limit and offset to realize pagination and use c


Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

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),

WebStorm Mac version
Useful JavaScript development tools