I have written articles about Yii on the Sina blog before. After coming to the blog park, I have not written any articles about Yii. It happened that I had nothing to do during the Dragon Boat Festival holiday, so I combined the previous blog and the official documentation of Yii. Add a summary of the recent gains about Yii and write a series~~
Yii is a high-performance component-based PHP framework for developing large-scale web applications. Yii is written in strict OOP and has complete library references and comprehensive tutorials. From MVC, DAO/ActiveRecord, widgets, caching, hierarchical RBAC, web services, to theming, I18N and L10N, Yii provides almost everything needed for today's Web 2.0 application development. In fact, Yii is one of the most efficient PHP frameworks. Yii is a high-performance PHP5 web application development framework. A simple command line tool yiic can quickly create a web application code framework. Developers can add business logic based on the generated code framework to quickly complete application development.
Install Yii
Before installing Yii, you must configure your development environment, such as a web server that supports PHP5.1.0 or above. Yii has been tested on the Apache web server on Windows and Linux operating systems. It may also run on web servers that support PHP5 on other platforms. There are many free resources published on the Internet, and you may get a web server environment configured with PHP5. Here we will leave aside the web server and PHP5 installation. The installation of Yii is actually very simple. It only requires two steps:- Download Yii framework from http://www.yiiframework.com/ Unzip the downloaded file to a directory accessible to the web server.
- After the installation is completed, it is recommended that you check whether the current server meets all the requirements of Yii.
Create a new application
- You already know the installation location of Yii
- WebRoot is the root directory of your web server configuration
- From your command line, go to the framework directory and execute the following:
%<span> cd Webroot/testdrive/framework </span>% <span>yiic webapp ../../testdrive Create a Web application under </span><span>'</span><span>/WebRoot/testdrive</span><span>'</span>? [Yes|<span>No] Yes </span><span>mkdir</span> /WebRoot/<span>testdrive </span><span>mkdir</span> /WebRoot/testdrive/<span>assets </span><span>mkdir</span> /WebRoot/testdrive/<span>css generate css</span>/<span>bg.gif generate css</span>/<span>form.css generate css</span>/main.css
Your application has been successfully created under /WebRoot/demo. The purpose of this webapp command is to create a brand new Yii application. It only requires specifying a parameter, whether it is an absolute or relative path and the application will be created. The directories and files it generates are just a skeleton of the application.
testdrive/<span> index.php Web 应用入口脚本文件 index</span>-<span>test.php 功能测试使用的入口脚本文件 assets</span>/<span> 包含公开的资源文件 css</span>/<span> 包含 CSS 文件 images</span>/<span> 包含图片文件 themes</span>/<span> 包含应用主题 protected</span>/<span> 包含受保护的应用文件 yiic yiic 命令行脚本 yiic.bat Windows 下的 yiic 命令行脚本 yiic.php yiic 命令行 PHP 脚本 commands</span>/ 包含自定义的 <span>'</span><span>yiic</span><span>'</span><span> 命令 shell</span>/ 包含自定义的 <span>'</span><span>yiic shell</span><span>'</span><span> 命令 components</span>/<span> 包含可重用的用户组件 Controller.php 所有控制器类的基础类 Identity.php 用来认证的 </span><span>'</span><span>Identity</span><span>'</span><span> 类 config</span>/<span> 包含配置文件 console.php 控制台应用配置 main.php Web 应用配置 test.php 功能测试使用的配置 controllers</span>/<span> 包含控制器的类文件 SiteController.php 默认控制器的类文件 data</span>/<span> 包含示例数据库 schema.mysql.sql 示例 MySQL 数据库 schema.sqlite.sql 示例 SQLite 数据库 testdrive.db 示例 SQLite 数据库文件 extensions</span>/<span> 包含第三方扩展 messages</span>/<span> 包含翻译过的消息 models</span>/<span> 包含模型的类文件 LoginForm.php </span><span>'</span><span>login</span><span>'</span><span> 动作的表单模型 ContactForm.php </span><span>'</span><span>contact</span><span>'</span><span> 动作的表单模型 runtime</span>/<span> 包含临时生成的文件 tests</span>/<span> 包含测试脚本 views</span>/<span> 包含控制器的视图和布局文件 layouts</span>/<span> 包含布局视图文件 main.php 所有视图的默认布局 column1.php 使用单列页面使用的布局 column2.php 使用双列的页面使用的布局 site</span>/ 包含 <span>'</span><span>site</span><span>'</span><span> 控制器的视图文件 pages</span>/ 包含 <span>"</span><span>静态</span><span>"</span><span> 页面 about.php </span><span>"</span><span>about</span><span>"</span><span> 页面的视图 contact.php </span><span>'</span><span>contact</span><span>'</span><span> 动作的视图 error.php </span><span>'</span><span>error</span><span>'</span><span> 动作的视图(显示外部错误) index.php </span><span>'</span><span>index</span><span>'</span><span> 动作的视图 </span><span>login</span>.php <span>'</span><span>login</span><span>'</span><span> 动作的视图 system</span>/ 包含系统视图文件
Without writing a line of code at this time, we can access the following URL in the browser to see our first Yii application:
http:<span>//</span><span>hostname/testdrive/index.php</span>
As we will see, this application contains three pages: home page, contact page, and login page. The homepage displays some information about the application and the user's login status, the contact page displays a contact form for users to fill out and submit their inquiries, and the login page allows users to first authenticate and then access authorized content.
Configuration
In this application, no matter which page URL you go to, index.php is included. What should I do if I want to remove it?
1. Open apache's mod_rewrite module, remove the "#" symbol in front of LoadModule rewrite_module modules/mod_rewrite.so, and make sure there is "AllowOverride All" in'components'=><span>array</span><span>( </span>... 'urlManager'=><span>array</span><span>( </span>'urlFormat'=>'path', 'showScriptName'=><span>false</span>,<span>//</span><span>注意false不要用引号括上</span> 'rules'=><span>array</span><span>( </span>'sites'=>'site/index',<span> )</span>,<span> )</span>, ...<span> )</span>,
3. Configure the server, Yii can be configured under Apache and Nginx
1) Apache
Under the Apache server, Yii needs to configure the .htaccess file. The configuration is as follows
<span>RewriteEngine on # prevent httpd from serving dotfiles (.htaccess, .svn, .git, etc.) RedirectMatch </span><span>403</span> /\..*<span>$ # </span><span>if</span> a directory or a <span>file</span><span> exists, use it directly RewriteCond </span>%{REQUEST_FILENAME} !-<span>f RewriteCond </span>%{REQUEST_FILENAME} !-<span>d # otherwise forward it to index.php RewriteRule . index.php</span>
2) Nginx
Yii can use Nginx and PHP's FPM SAPI. The configuration is as follows
<span>server { set $host_path </span><span>"</span><span>/www/mysite</span><span>"</span><span>; access_log </span>/www/mysite/log/<span>access.log main; server_name mysite; root $host_path</span>/<span>htdocs; set $yii_bootstrap </span><span>"</span><span>index.php</span><span>"</span><span>; charset utf</span>-<span>8</span><span>; location </span>/<span> { index index.html $yii_bootstrap; try_files $uri $uri</span>/ /$yii_bootstrap?<span>$args; } location </span>~ ^/(protected|framework|themes/\<span>w</span>+/<span>views) { deny all; } #avoid processing of calls to unexisting static files by yii location </span>~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|<span>zip</span>|<span>rar)$ { try_files $uri </span>=<span>404</span><span>; } # pass the PHP scripts to FastCGI server listening on </span><span>127.0</span>.<span>0.1</span>:<span>9000</span><span> # location </span>~<span> \.php { fastcgi_split_path_info </span>^(.+\.php)(.*<span>)$; #let yii catch the calls to unexising PHP files set $fsn </span>/<span>$yii_bootstrap; </span><span>if</span> (-<span>f $document_root$fastcgi_script_name){ set $fsn $fastcgi_script_name; } fastcgi_pass </span><span>127.0</span>.<span>0.1</span>:<span>9000</span><span>; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fsn; #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC </span><span>3875</span> specifies them <span>for</span><span> CGI fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fsn; } # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.) location </span>~ /<span>\. { deny all; access_log off; log_not_found off; } }</span>
Using the above configuration, you can set cgi.fix_pathinfo=0 in php.ini, which can avoid many unnecessary system's stat( ) call.
Basic installation and configuration ends here~~

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

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

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

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

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor