Home Backend Development PHP Tutorial php配备yii框架(转)

php配备yii框架(转)

Jun 13, 2016 pm 12:40 PM
apc php span with

php配置yii框架(转)

yii具有很多当今web2.0开发所需要的特性。下边是一个简短列表。

?

MVC设计模式 :yii在WEB设计中采用经过验证的技术,可以较好的把显示与逻辑分离。

DAO,活动记录:yii充许在对象方面建立数据库模型,保存长而重复语句。

整合jquery:最流行的javascript框架之一,苦于jquery可以定屈非常高效并且多功能的javascript接口

表单输入验证:yii可以很简单啊安全的采集表单输入。具有一整套验证方法确保输入数据的正确,还有辅助的方法与组件,在验证失败时,提示错误信息。

WEB2.0组件:jquery提供的一套web2.0组件,可以自动完成输入域,树形视图等等。

验证与授权:yii内置验证。通过分级的基本角色访问控制提供授权。

主题:可以立即更改yii应用的主题。

WEB服务:yii支持自动复杂的WSDL服务说明的产生和服务请求处理的管理.

国际化和本地化:yii支持信息翻译,日期时间格式化,数字格式化和界面本地化。

分层缓存计划:yii支持数据缓存,页面缓存,片断缓存和动态内容。且缓存的存储介质可以在不改变应用代码下被更改。

错误处理和日志:错误被处理并且很人性化的显示,日志信息可以实现分类,过滤,并可以路由到不同的目的地。

安全:yii提供许多安全措施保证WEB应用阻止网络攻击。包括:防止跨站脚本,防止伪跨站点请求,防止窜改cookie等等。

遵守xhtml:由yiit组件和命令行工具生成的代码遵守xhtml标准。

自动代码生成:yii提供自动生成所需代码的工具,比如:应用框架,CRUD应用等。

完全的面向对象:yii框架遵守严格的面向对象的程序设计模式。不定义任何全局函数或变量。所定义的类层次结构给予最在程度的可用性和可定制性。

支持第三方代码:yii可以很好的支持第三方代码。例如,可以在YII应用中使用PERA或者zend framework。

详细的文档:每一个方法或者属性都有明确的说明。提供综合指导与其他方面的指导。

扩展库:yii提供由使用者撰写的组件构成的扩展库。

?

项目主页是: www.yiiframework.com/

?

?

?

其实安装yii就和安装ZendFramework没什么区别,要么在每个项目中包含yii,要么在服务器用php的include_path来包含。

?

解压缩下载下来的文件夹后,里面有三个子文件夹:demos(演示),framework(框架核心代码),requirements(这个里边儿是检测你的服务器配置是否支持yii框架,主要是php扩展方面)

?

接下来就先进行测试吧,把里面的requirements目录单独复制到你的web目录下,然后运行 xxx.xxx.com/requirements,这样会显示类似如下图所示,

?

image

php_yii_requirements_1

?

PDO MySQL扩展模块 未通过 所有和数据库相关的类 如果使用MySQL数据库,这是必须的。

PDO PostgreSQL扩展模块 未通过 所有和数据库相关的类 如果使用PostgreSQL数据库,这是必须的。

APC扩展模块 未通过 CApcCache

SOAP扩展模块 未通过 CWebService, CWebServiceAction

?

我的服务器目前有着四项没有通过,出去PDO PostgreSQL这项我不需要,打算把其他三项给加上。

?

PDO MySQL的扩展需要在编译php的时候增加 --with-pdo-mysql=/usr/local/mysql

SOAP需要增加 --enable-soap 和 --with-libxml-dir=/usr/local/libxml2

?

然后进行编译安装

?[Copy to clipboard]View Code BASH

?

1

?

?

?

./configure --prefix=/usr/local/php-5.2.9/ --enable-force-cgi-redirect --enable-mbstring=all --enable-mbregex --enable-mbstr-enc-trans --enable-versioning --enable-trans-sid --enable-ftp --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache2/bin/apxs --with-soap=yes --with-curl=/usr/local/curl/ --with-zlib-dir=/usr/local/zlib/ --with-mcrypt=/usr/local/libmcrypt/ --with-gd=/usr/local/gd2 --with-jpeg-dir=/usr --with-freetype-dir=/usr/local/freetype --with-ttf --with-png-dir=/usr --with-mhash=/usr/local/mhash/ --with-dom=/usr/local/libxml2 --with-iconv=/usr/local/libiconv --with-openssl=/usr/local/openssl --with-pdo-mysql=/usr/local/mysql --enable-soap --with-libxml-dir=/usr/local/libxml2 && make && make install

?

由于之前进行过memcached的安装,所以这里再重新来一遍

?[Copy to clipboard]View Code BASH

?

1

2

3

4

?

?

?

/usr/local/php/bin/phpize

./configure --prefix=/usr/local/memcached_phpclient3.0.4 --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir=/usr/local/zlib/

make

make install

?

安装完成后显示:

Installing shared extensions: /usr/local/php-5.2.9//lib/php/extensions/no-debug-non-zts-20060613/

?

下来修改php.ini

首先找到extension_dir,默认的应该是:extension_dir = "./"

现在修改成:extension_dir = "/usr/local/php//lib/php//extensions/no-debug-non-zts-20060613/"

然后再找到Dynamic Extensions,在下面加上:

extension=memcache.so

?

APC扩展模块儿比较麻烦:

它的下载地址是:http://pecl.php.net/package/apc

可以从下面的列表儿选择你需要的来下载。我下载的是3.0.19 stable版本。

解压缩后进入目录,并执行如下命令:

?[Copy to clipboard]View Code BASH

?

1

2

3

4

?

?

?

/usr/local/php/bin/phpize

./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php/bin/php-config

make

make install

?

然后再次修改php.ini文件,

加入:

extension=apc.so

apc.enabled = 1

apc.cache_by_default = on

apc.shm_segments = 1

apc.shm_size = 32

apc.ttl = 600

apc.user_ttl = 600

apc.num_files_hint = 0

apc.write_lock = On

?

apc配置的一些说明:

apc.cache_by_default = On

是否默认对所有文件启用缓冲。 若设为Off并与以加号开头的apc.filters指令一起用,则文件仅在匹配过滤器时才被缓存

?

apc.enabled = On

是否启用APC,如果APC被静态编译进PHP又想禁用它,这是唯一的办法。

?

pc.filters =

一个以逗号分隔的POSIX扩展正则表达式列表。

如果源文件名与任意一个模式匹配,则该文件不被缓存。

注意,用来匹配的文件名是传递给include/require的文件名,而不是绝对路径。

如果正则表达式的第一个字符是"+"则意味着任何匹配表达式的文件会被缓存,如果第一个字符是"-"则任何匹配项都不会被缓存。"-"是默认值,可以省略掉。

?

apc.ttl = 0

缓存条目在缓冲区中允许逗留的秒数。0 表示永不超时。建议值为7200~36000。设为 0 意味着缓冲区有可能被旧的缓存条目填满,从而导致无法缓存新条目。

?

apc.user_ttl = 0

类似于apc.ttl,只是针对每个用户而言,建议值为7200~36000。

?

apc.gc_ttl = 3600

缓存条目在垃圾回收表中能够存在的秒数

此值提供了一个安全措施,即使一个服务器进程在执行缓存的源文件时崩溃, 中.国.站长站

而且该源文件已经被修改,为旧版本分配的内存也不会被回收,直到达到此TTL值为止。设为零将禁用此特性。

?

pc.max_file_size = 1M

禁止大于此尺寸的文件被缓存。

?

apc.num_files_hint = 1000

Web服务器上可能被包含或被请求的不同源文件的大致数量(建议值为1024~4096)。

如果你不能确定,则设为 0 ;此设定主要用于拥有数千个源文件的站点。

?

apc.shm_segments = 1

为编译器缓冲区分配的共享内存块数量(建议值为1)。

如果APC耗尽了共享内存,并且已将apc.shm_size指令设为系统允许的最大值,你可以尝试增大此值。

?

apc.shm_size = 30

每个共享内存块的大小(以MB为单位,建议值为128~256)。

有些系统(包括大多数BSD变种)默认的共享内存块大小非常少。

?

apc.write_lock = On

是否启用写入锁。

?

重启apache服务器

然后在phpinfo中你就会看到apc的设置了。

?

至此,需要的yii的扩展已经配置完毕了,再刷新一下儿刚才的测试网页,就变成了:

?

image

php_yii_requirements_2

?

--------------------------------------------

好了,环境测试通过了,下面接着来测试demo吧。

?

把yii的demos目录和framework目录copy到你的web目录下,并且访问: xxx.xxx.com/demos/helloworld

?

在我这里会显示:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 137963997 bytes) in Unknown on line 0

不知道为什么,但是后来我在php.ini中将上面的apc设置都给注释掉,再重启apache2 就没问题了,会正确的显示出:

Hello World

那就先不用apc扩展吧。

?

现将你的yii的framework目录放到合适的位置,然后修改你的php.ini的include_path,重启apache server

这个时候修改你的helloworld/index.php

?[Copy to clipboard]View Code PHP

?

1

2

3

?

?

[php] view plaincopy

?

? ? require_once(dirname(__FILE__).'/../../framework/yii.php'); ?

? ? #修改成: ?

? ? require_once('yii.php'); ?

?

这个时候儿如果还是可以正确的显示出:Hello World

则代表你配置成功了。

?

好了,配置好了,如何初步的运用yii来写程序。

请看这里:

英文的: www.yiiframework.com/doc/guide/

中文的: www.yiiframework.com/doc/guide/zh_cn/index

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles