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

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

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

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

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

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




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




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


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

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





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



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

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



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







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

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

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


個(gè)人認(rèn)為說(shuō)的沒(méi)任何道理,你說(shuō)的幾點(diǎn)只是框架提供的一個(gè)功能而已

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

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


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



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

TopreventCSRFattacksinPHP,implementanti-CSRFtokens.1)Generateandstoresecuretokensusingrandom_bytes()orbin2hex(random_bytes(32)),savethemin$_SESSION,andincludetheminformsashiddeninputs.2)ValidatetokensonsubmissionbystrictlycomparingthePOSTtokenwiththe

How to combine two php arrays unique values? How to combine two php arrays unique values? Jul 02, 2025 pm 05:18 PM

To merge two PHP arrays and keep unique values, there are two main methods. 1. For index arrays or only deduplication, use array_merge and array_unique combinations: first merge array_merge($array1,$array2) and then use array_unique() to deduplicate them to finally get a new array containing all unique values; 2. For associative arrays and want to retain key-value pairs in the first array, use the operator: $result=$array1 $array2, which will ensure that the keys in the first array will not be overwritten by the second array. These two methods are applicable to different scenarios, depending on whether the key name is retained or only the focus is on

How to use php exit function? How to use php exit function? Jul 03, 2025 am 02:15 AM

exit() is a function in PHP that is used to terminate script execution immediately. Common uses include: 1. Terminate the script in advance when an exception is detected, such as the file does not exist or verification fails; 2. Output intermediate results during debugging and stop execution; 3. Call exit() after redirecting in conjunction with header() to prevent subsequent code execution; In addition, exit() can accept string parameters as output content or integers as status code, and its alias is die().

Applying Semantic Structure with article, section, and aside in HTML Applying Semantic Structure with article, section, and aside in HTML Jul 05, 2025 am 02:03 AM

The rational use of semantic tags in HTML can improve page structure clarity, accessibility and SEO effects. 1. Used for independent content blocks, such as blog posts or comments, it must be self-contained; 2. Used for classification related content, usually including titles, and is suitable for different modules of the page; 3. Used for auxiliary information related to the main content but not core, such as sidebar recommendations or author profiles. In actual development, labels should be combined and other, avoid excessive nesting, keep the structure simple, and verify the rationality of the structure through developer tools.

How do I access session data in PHP? How do I access session data in PHP? Jun 30, 2025 am 01:33 AM

To access session data in PHP, you must first start the session and then operate through the $_SESSION hyperglobal array. 1. The session must be started using session_start(), and the function must be called before any output; 2. When accessing session data, check whether the key exists. You can use isset($_SESSION['key']) or array_key_exists('key',$_SESSION); 3. Set or update session variables only need to assign values ??to the $_SESSION array without manually saving; 4. Clear specific data with unset($_SESSION['key']), clear all data and set $_SESSION to an empty array.

What are recursive functions in PHP? What are recursive functions in PHP? Jun 29, 2025 am 02:02 AM

Recursive functions refer to self-call functions in PHP. The core elements are 1. Defining the termination conditions (base examples), 2. Decomposing the problem and calling itself recursively (recursive examples). It is suitable for dealing with hierarchical structures, disassembling duplicate subproblems, or improving code readability, such as calculating factorials, traversing directories, etc. However, it is necessary to pay attention to the risks of memory consumption and stack overflow. When writing, the exit conditions should be clarified, the basic examples should be gradually approached, the redundant parameters should be avoided, and small inputs should be tested. For example, when scanning a directory, the function encounters a subdirectory and calls itself recursively until all levels are traversed.

How to create an array in php? How to create an array in php? Jul 02, 2025 pm 05:01 PM

There are two ways to create an array in PHP: use the array() function or use brackets []. 1. Using the array() function is a traditional way, with good compatibility. Define index arrays such as $fruits=array("apple","banana","orange"), and associative arrays such as $user=array("name"=>"John","age"=>25); 2. Using [] is a simpler way to support since PHP5.4, such as $color

php raw post data php php raw post data php Jul 02, 2025 pm 04:51 PM

The way to process raw POST data in PHP is to use $rawData=file_get_contents('php://input'), which is suitable for receiving JSON, XML, or other custom format data. 1.php://input is a read-only stream, which is only valid in POST requests; 2. Common problems include server configuration or middleware reading input streams, which makes it impossible to obtain data; 3. Application scenarios include receiving front-end fetch requests, third-party service callbacks, and building RESTfulAPIs; 4. The difference from $_POST is that $_POST automatically parses standard form data, while the original data is suitable for non-standard formats and allows manual parsing; 5. Ordinary HTM

See all articles