国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial 【Yii】剛接觸Yii談一下對Yii框架的看法和感受 (Yii 1.1.x),該怎么處理

【Yii】剛接觸Yii談一下對Yii框架的看法和感受 (Yii 1.1.x),該怎么處理

Jun 13, 2016 am 11:59 AM
action nbsp php yii

【Yii】剛接觸Yii談一下對Yii框架的看法和感受 (Yii 1.1.x)

本帖最后由 default7 于 2014-06-10 00:57:13 編輯 之所以想到去弄Yii,因為看到很多招聘PHP都要求必須精通Yii框架。
首先的印象這個框架是中國人創(chuàng)始的,但是卻全都是英文的為主。這幾天看了一下Yii權(quán)威指南。
說一下自己的初步感受(Yii?1.x):




1)文件結(jié)構(gòu)凌亂。
既然是框架,卻可以將action獨立出來/protected/controllers/post/CreateAction.php。這樣極容易讓action與controller混亂。




2)對視圖的控制欲太強烈,模板使用的是純PHP。難道你做程序員也非得去寫前端?
一個網(wǎng)站項目,讓美工切出了HTML?DIV?CSS模板之后,又讓PHP程序員再把里面的HTML標(biāo)簽換成PHP標(biāo)簽再搞一趟?
Yii的CHtml讓很多人特別贊不絕口,但是他們似乎忽略了一個最核心的關(guān)鍵,網(wǎng)站網(wǎng)頁有功能沒賣相根本就會很慘,你不要指望訪客都會像程序員那種只喜歡方方框框沒有一張圖全都是表格一樣、對得工工整整的頁面。


要注意:網(wǎng)站網(wǎng)頁他不像軟件,軟件可能幾年十幾年都是做的功能改進(jìn),但網(wǎng)頁,訪客喜歡新鮮感,界面視覺,所以需要不斷的改界面,改UI。

是定期修改,三天一小改,一個月一大改,三個月重新改。界面需要經(jīng)常改。這樣的情況下,如果直接使用html原型來做模板,美工做好DIV之后就可以直接用,根本都不需要程序插手。可是如果用了CHtml這樣高度耦合的視圖(模板)寫法,那么必須得多出一道工序,那就是還需要一個懂得Yii的程序員將美工已經(jīng)做好的DIV?HTML再轉(zhuǎn)成Yii視圖模板中的標(biāo)簽,這樣不是浪費嗎?人力、時間、財力。與PHP的高效快速?背道而行?
實際上Yii的官網(wǎng)也是極其簡陋的,蘋果為什么會成功,賣相是關(guān)鍵,現(xiàn)在這個時代,UI界面真的太重要了。





3)感覺各個之間耦合度太高了,猶如一門新的語言。
Yii入門門檻比其他的框架高很多。各個之間都是高度耦合,都是些配置一樣的設(shè)置,越是耦合越緊密,配置文件越是分散各個角落其實維護(hù)起來成本更高、時間更長、維護(hù)效率更低(當(dāng)然,他可能運行效率很快)。



Yii對我的吸引:
1)51job、智聯(lián)招聘上很多招PHP程序員的都要求需要精通Yii(其實看到那些要求我覺得很奇怪,描述上又要能夠獨立完成一整個項目又要精通Yii又要端精通DIV?CSS?UI,想讓別人一個人搞,有點不合實際,Yii適合大型項目,如果一個大型項目中又要讓程序員干Yii又要讓他去寫DIV這樣不可笑嗎?)

2)網(wǎng)上很多次方充滿著對Yii的贊美、推薦,比如知乎上、搜索引擎中搜索MVC框架排名看到各大轉(zhuǎn)載的文章、PHP?MVC框架排名上,Yii都排名得很前,且很多神贊。



以上是我對Yii初步接觸的一些感受,寫出來希望能夠一起探討,目的是能夠更快的掌握、領(lǐng)悟。by?default7#zbphp.com







------解決方案--------------------
歡迎了解?Yii2.0,你說的絕大多數(shù)問題在Yii?2.0?時代都有更好的實現(xiàn)了。
至于用PHP做模版,這個屬于仁者見仁智者見智的問題。學(xué)會模版引擎跟學(xué)會PHP差不了多少。2.0原生支持smarty和twig
至于耦合度的問題,只要你想,解耦根本不是問題,Yii提供的是一站式解決方案,一個字,就是快,之后你想替換組件,改模版,加緩存,隨你便。2.0原生支持多種解耦,比如DI。
至于像新語言的問題,因為Yii大量使用了DSL的模式。這個模式是微軟發(fā)明的。為什么用,因為好用。
至于混亂的問題,你沒有學(xué)到ActiveRecord,沒用用到ActiveForm。這些東西的彼此搭配才是現(xiàn)代PHP框架的核心啊。這些特色的點你都沒有說到,用好了效率灰常灰常高。Yii2.0新增了全新的查詢與表現(xiàn)分離的ActiveQuery以及更吊的多關(guān)系查詢,有空了解下。
除此之外的功能還有安全性設(shè)計,GII代碼生成器,開發(fā)者工具條,調(diào)試模式,Codeception調(diào)試器,F(xiàn)ixture數(shù)據(jù)定制器,Bootstrap擴(kuò)展等等等等不勝枚舉的特性,學(xué)習(xí)曲線本身不是問題,這些特性你不用也沒關(guān)系,當(dāng)原生PHP一樣用也好用,但是學(xué)習(xí)曲線是和收益成正比的,用過你就放不下了。
功夫要下到,你不會不代表它不能,這么多企業(yè)用Yii,難道他們的CTO傻?
------解決方案--------------------
你這是只看到y(tǒng)ii的缺點,沒看到y(tǒng)ii2的優(yōu)點。任何框架都會有缺點。
1、yii最主要的精華是OOP。
???????這個是yii框架的整個功能的所在,也是是公司招聘的主要原因
2、就像樓上所說的yii提供了各種便捷的功能,所以開發(fā)速度快。
3、文件結(jié)構(gòu)凌亂
???????這個完全是按照個人習(xí)慣來組織,你可以這樣寫
protected
??????????actions
?????????????????post
?????????????????????????CreateAction.php
??????????????????????????ReadAction.php
???????????controllers
??????????????????PostController.php
4、至于表單問題
???????這個要看個人需要,如果做的表單頁面是中規(guī)中矩的,可以使用ActiveForm。
???????當(dāng)然,你可以完全不用ActiveForm,自己寫html來實現(xiàn),ActiveForm只是給你提供了一種方便。
?????????????????????????
------解決方案--------------------
沒用過?Yii,也沒打算用。表示沒有就業(yè)壓力
據(jù)說?Yii2.0?這能工作于?php?5.4?及以上了
所以模板中的?
樓主對?Yii?模板的批評,也就是對?Smarty?的批評,也就是對所有使用模板引擎將業(yè)務(wù)邏輯與視圖分離的框架的批評,也就是對?MVC?這種設(shè)計模式的批評
姑且言之,姑妄聽之

如果要在模板中引入控制流,那么與其象?Smarty?自創(chuàng)一套模板語言,還真不如象?Yii?這樣直接使用?php?代碼
至少是學(xué)習(xí)難度下降了,何況學(xué)會了?php?,吃飯也總算有著落了

我倒是期望有這樣一個框架:他能將在?html?聲明為客戶端運行的php代碼翻譯成?js?代碼。從而免去學(xué)?php?還要學(xué)習(xí)?js?的煩惱
------解決方案--------------------


個人認(rèn)為說的沒任何道理,你說的幾點只是框架提供的一個功能而已

1)文件結(jié)構(gòu)凌亂:框架有強制你把action單獨寫出來么?完全可以寫到?Controller
2)對視圖的控制欲太強烈:和第一條一樣,沒人強制你用上這個功能,我自己做表單看情況是否啟用ActiveForm,哪個方便用哪個

事實證明,正規(guī)的公司都是分工明確不會讓美工去干前端人員切片的活,甚至讓美工或前端去套程序,只有那些比較坑的網(wǎng)建公司、非正規(guī)公司才會這樣去做,出一個人的薪水干幾個工種的工作


框架只是一個提升工作效率的工具,看你怎么去用,不是讓你把所有內(nèi)置功能全部用上,不要被框架框住!



------解決方案--------------------
至于Chtml做表單ActiveForm,可用可不用。但是個人覺得yii最優(yōu)秀的莫過于OOP和MVC,還有它的靈魂:隨用隨取,而并不是運行就把所有的類加載進(jìn)來,這也是其效率所在了!也是很多企業(yè)要求YII的原因了。
------解決方案--------------------
用Yii完成了2個項目了,正在做第三個,這次這個項目相對比較大,功能也較多。
前兩個項目一次和別人合作,一次完全自己做的,自己做的一次是做一個票務(wù)系統(tǒng),因為整體界面要求不高,我就沒有找前端,全部自己寫了。
現(xiàn)在感覺Yii的整體設(shè)計用起來真是舒服,本身基于組件的框架使其具有極高的定制性,就像樓上所說的,有很多功能你覺得不好納尼完全可以不用,有很多替代方案,Yii只是給你多了一個選擇,如果你覺得好像沒什么替代方案只能說明對框架不夠熟悉,個人感覺Yii還是值得鉆研一下的
------解決方案--------------------
yii對初學(xué)者來說確實有點復(fù)雜,不過用時間久了就能體會到好處了,它確實是個極優(yōu)秀的框架。剛開始可能感覺不出來,等到后期維護(hù)的時候就能發(fā)覺,它真的是很方便,非常靈活,想怎么改就怎么改,哪怕需求變了,用它也可以快速完成。當(dāng)然,前提是你得保證設(shè)計應(yīng)該合理
------解決方案--------------------
1)文件結(jié)構(gòu)凌亂。
既然是框架,卻可以將action獨立出來/protected/controllers/post/CreateAction.php。這樣極容易讓action與controller混亂。
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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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

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)

How Do Generators Work in PHP? How Do Generators Work in PHP? Jul 11, 2025 am 03:12 AM

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

How to access a character in a string by index in PHP How to access a character in a string by index in PHP Jul 12, 2025 am 03:15 AM

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

How to prevent session hijacking in PHP? How to prevent session hijacking in PHP? Jul 11, 2025 am 03:15 AM

To prevent session hijacking in PHP, the following measures need to be taken: 1. Use HTTPS to encrypt the transmission and set session.cookie_secure=1 in php.ini; 2. Set the security cookie attributes, including httponly, secure and samesite; 3. Call session_regenerate_id(true) when the user logs in or permissions change to change to change the SessionID; 4. Limit the Session life cycle, reasonably configure gc_maxlifetime and record the user's activity time; 5. Prohibit exposing the SessionID to the URL, and set session.use_only

How to URL encode a string in PHP with urlencode How to URL encode a string in PHP with urlencode Jul 11, 2025 am 03:22 AM

The urlencode() function is used to encode strings into URL-safe formats, where non-alphanumeric characters (except -, _, and .) are replaced with a percent sign followed by a two-digit hexadecimal number. For example, spaces are converted to signs, exclamation marks are converted to!, and Chinese characters are converted to their UTF-8 encoding form. When using, only the parameter values ??should be encoded, not the entire URL, to avoid damaging the URL structure. For other parts of the URL, such as path segments, the rawurlencode() function should be used, which converts the space to . When processing array parameters, you can use http_build_query() to automatically encode, or manually call urlencode() on each value to ensure safe transfer of data. just

PHP get the first N characters of a string PHP get the first N characters of a string Jul 11, 2025 am 03:17 AM

You can use substr() or mb_substr() to get the first N characters in PHP. The specific steps are as follows: 1. Use substr($string,0,N) to intercept the first N characters, which is suitable for ASCII characters and is simple and efficient; 2. When processing multi-byte characters (such as Chinese), mb_substr($string,0,N,'UTF-8'), and ensure that mbstring extension is enabled; 3. If the string contains HTML or whitespace characters, you should first use strip_tags() to remove the tags and trim() to clean the spaces, and then intercept them to ensure the results are clean.

PHP get the last N characters of a string PHP get the last N characters of a string Jul 11, 2025 am 03:17 AM

There are two main ways to get the last N characters of a string in PHP: 1. Use the substr() function to intercept through the negative starting position, which is suitable for single-byte characters; 2. Use the mb_substr() function to support multilingual and UTF-8 encoding to avoid truncating non-English characters; 3. Optionally determine whether the string length is sufficient to handle boundary situations; 4. It is not recommended to use strrev() substr() combination method because it is not safe and inefficient for multi-byte characters.

How to set and get session variables in PHP? How to set and get session variables in PHP? Jul 12, 2025 am 03:10 AM

To set and get session variables in PHP, you must first always call session_start() at the top of the script to start the session. 1. When setting session variables, use $_SESSION hyperglobal array to assign values ??to specific keys, such as $_SESSION['username']='john_doe'; it can store strings, numbers, arrays and even objects, but avoid storing too much data to avoid affecting performance. 2. When obtaining session variables, you need to call session_start() first, and then access the $_SESSION array through the key, such as echo$_SESSION['username']; it is recommended to use isset() to check whether the variable exists to avoid errors

How to prevent SQL injection in PHP How to prevent SQL injection in PHP Jul 12, 2025 am 03:02 AM

Key methods to prevent SQL injection in PHP include: 1. Use preprocessing statements (such as PDO or MySQLi) to separate SQL code and data; 2. Turn off simulated preprocessing mode to ensure true preprocessing; 3. Filter and verify user input, such as using is_numeric() and filter_var(); 4. Avoid directly splicing SQL strings and use parameter binding instead; 5. Turn off error display in the production environment and record error logs. These measures comprehensively prevent the risk of SQL injection from mechanisms and details.

See all articles