2023年7月11日 星期二

該選 CodeIgniter 還是 Yii 好呢?

 2012-03-07 20:20

使用 CodeIgniter 開發了一些程式之後,仍不斷的尋找比較相關各類 framework。
其中 YII 是一個讓我心動的,在純技術面來講,YII 是佔上風。但看到學習曲線較陡,還是不太敢隨意投入。等有空再找機會試試看 YII 吧。一點意見,謹供參考。

下面是從某個網站找到的大陸網友的看法 ,第二個意見,讓我目前安分的留在CI上。

    最近要自己一個人做一個網站,於是在 CI 和 YII 中選擇。
    由於 Ci 之前看過,所以簡單的看了下號稱速度最快的 Yii 的官方文檔,也下載了一個官方例子運行。
    發現 Yii 功能挺強大的,在功能方面和我以前看過的 Python 的 django 框架很相似。
    但是 Yii 的缺點也很明顯,所以如果有在兩者之間猶豫的同學可以藉鑑一下的思路。
    第一、Yii 的 OO 很純粹
    裡面各種接口、類、繼承、擴展,顯得很龐大,所以不適合對 OO 不是太理解的同學。當然如果你想以學習 OO 為目的,可以使用 Yii;如果是實際生產,注重開發效率還是 CI 好。加之我之前一直使用的 asp.net,所以我個人對 OO 不怎麼感冒。
    第二、Yii 的功能很强大
    功能強大是好事,也是壞事。我一直認為,框架雖然幫你做了很多,但是沒有萬能的框架,框架功能越多,符合實際需求預期效果的功能相對就越少,花費時間學習的成本就越高。這一點我在 ASP.net 上是深有體會。
    總結:Yii 自我標榜 easy,其實完整的學下來並不簡單,至少他需要你掌握 OO 的知識。所以我認為,Yii 適合業務邏輯相對複雜​​的業務系統開發,比如項目管理,OA 之類的,因為很多組件已經集成,不用你自己東拼西湊再花時間去找;CI 更適合做業務邏輯相對簡單的互聯網應用,簡單高效,自己動手。
    所以最後還是決定使用 CI,一點愚見,歡迎拍磚。

下面是英文的 http://firmy007.blogspot.com/2011/06/codeigniter-versus-yii-my-thoughts.html

Codeigniter versus Yii, now this may open a real can of worms, as most comparisons do, but I have used both and have to come to the conclusion that whilst Yii is probably that slightly more polished, Codeigniter is going to be my framework of choice for next few years to come when developing websites in PHP.

Let's take a look at Codeigniter, it's easy to learn, easy to grasp and now that it has been upgraded to version PHP5 only from version 2 onwards, much more future proof. I also really like the way that you can really, really customise it to do your bidding. No need to use the command line to get it up and running and it will run with a very small footprint. You can also cache the hell the out of it at multiple levels to squeeze every little bit of performance out of it, take a look here for a detailed look at this.

Now let's look at Yii, completely object oriented and its major, major advantage - The CRUD generator. My goodness, this saves you time, lots of time. You create your database, design your schema and bang the Gii tool produces (as if by magic :)) your create, read, update and delete pages. No mucking around no writing SQL, it's all done through the (Rails inspired) Active Record Pattern - it's fair to say I fell in love with this almost straight away, I couldn't believe how easy it was to create this code. And this is what got me thinking...

I like Codeigniter for its flexibility, the way you could use both an active record pattern or traditional SQL, You could keep your database results in arrays or as standards objects, they leave it up to you. But I wanted, no, no... I needed a CRUD generator after experiencing the wonders of the Gii tool. As a freelance web developer in Lancashire (I know this sounds cheesy) time is money, so I scoured the web for one and I found a couple out there and none really lived up to my expectations, one was particularly good, but didn't really suit my needs. Like I said, I liked Codeigniter because of its flexibility, so I decided to bite the built and create my own CRUD generator for Codeigniter. Yeah, sure it was going to take a little bit of development time, but the time saved will definitely outweigh the initial outlay and it does, plus as my CRUD tool was my own, I could tweak and make changes very easily. Now, when creating large projects, creating new sections is not the chore it once was and now leaves me more time to make the other, more unique features, just right.

The main point that many people raise when they compare the two frameworks is the way that Codeigniter is not truly object oriented, whilst Yii is much more pure in its implementation. I suppose this is true, but when I create applications that are large, I need to know that I can hack away at them very easily and tune them to my specific needs and it is for this reason above all else that Codeigniter remains my PHP framework of choice.

When I first set out developing websites using PHP, I thought this was the language I would use forever when it came developing websites. I also felt like I would never, ever use a framework as how could using some else's ideas and code be of any benefit to me, when I have wrote my own application. Not only is the code battle ready as it has been through countless improvements through being used in the community, it also opens up your mind to new ways of thinking. I learnt to use Codeigniter first and Yii second, but there are things used in Yii, that I will and have ported over in to Codeigniter, the way Yii authenticates users for example, is a great way of accomplishing this task.

It's like I have mentioned before in other posts, do not do what other people tell you should do. Sure take on board what other people have, but stick to what you are comfortable with using as it is you that is creating the application and not them.

總的來說 Yii 很炫,會選 CodeIgniter 的主要理由就是彈性。沒有十項全能的東西,功能再怎麼完備,總是不夠的。那彈性呢,為了彈性,就是要多付出一些努力。

我想最好的例子就是 ASP.NET,剛推出來時,的確很吸引人,但我曾維護過一陣子,那真是痛苦,層層包裹,雜亂的 code,每頁都要重複的東西。所以,微軟才會推出 ASP MVC。可是看起來,那複雜度也是挺嚇人的。

CodeIgniter,真是輕薄短小,又兼具彈性。至少,因為它的彈性,我才能很快的把用 Smarty 開發的程式轉成 MVC。


201201301141選擇 CodeIgniter 還是 Yii 好呢

CodeIgniter 是我正在使用中的 MVC 框架,但看到 Yii 號稱具有模組化、OO... 等諸多優點,頗為心動,該不該換跑道呢???!!

首先,這是四平八穩的介紹。

CodeIgniter 是一个简单快速的PHP MVC 框架。EllisLab 的工作人员发布了 CodeIgniter。许多企业尝试体验过所有 PHP MVC 框架之后,CodeIgniter 都成为赢家,主要是由于它为组织提供了足够的自由支持,允许开发人员更迅速地工作。

自由意味着使用 CodeIgniter 时,您不必以某种方式命名数据库表,也不必根据表命名模型。这使 CodeIgniter 成为重构遗留 PHP 应用程序的理想选择,在此类遗留应用程序中,可能存在需要移植的所有奇怪的结构。

CodeIgniter 不需要大量代码(1.6.2 版本仅为 2.8 MB,其中的 1.3 MB 是可以删除的用户文档),也不会要求您插入类似于 PEAR 的庞大的库。它在 PHP 4 和 PHP 5 中表现同样良好,允许您创建可移植的应用程序。最后,您不必使用模板引擎来创建视图 — 只需沿用旧式的 HTML 和 PHP 即可。


以下是某位大陸網友的想法,應該頗符合我的想法。

http://codeigniter.org.cn/forums/thread-7104-1-7.html

CI和YII的對比

最近要自己一個人做一個網站,於是在CI和YII中選擇。
由於Ci之前看過,所以簡單的看了下號稱速度最快的Yii的官方文檔,也下載了一個官方例子運行。
發現Yii功能挺強大的,在功能方面和我以前看過的Python的 django 框架很相似。
但是Yii的缺點也很明顯,所以如果有在兩者之間猶豫的同學可以藉鑑一下的思路。
第一、Yii的OO很純粹
裡面各種接口、類、繼承、擴展,顯得很龐大,所以不適合對OO不是太理解的同學。當然如果你想以學習OO為目的,可以使用Yii;如果是實際生產,注重開發效率還是CI好。加之我之前一直使用的asp.net,所以我個人對OO不怎麼感冒
第二、Yii的功能很强大
功能強大是好事,也是壞事。我一直認為,框架雖然幫你做了很多,但是沒有萬能的框架,框架功能越多,符合實際需求預期效果的功能相對就越少,花費時間學習的成本就越高。這一點我在ASP.net上是深有體會。
總結:Yii自我標榜easy,其實完整的學下來並不簡單,至少他需要你掌握OO的知識。所以我認為,Yii適合業務邏輯相對複雜​​的業務系統開發,比如項目管理,OA之類的,因為很多組件已經集成,不用你自己東拼西湊再花時間去找;CI更適合做業務邏輯相對簡單的互聯網應用,簡單高效,自己動手。
所以最後還是決定使用CI,一點愚見,歡迎拍磚。



2012.10.13 記
還是必須說一下自己的想法。使用CI也超過一年了,下面這段話也許可以做個註解。
「Having said all of these. I believe Yii is more suitable for the enterprise like project where you need standard functionality and interface first and that gives you a head start. In other words Yii gives you readymade controllers, model, CRUD, breadcrumb, pagination, Layout ; CI lacks these.
     But If I were to build an application like twitter, I would hardly need these standard features, so using Yii would be like using a Truck without enough payload on it.
     Moral of the story : Go with CI for your twitter like project !」

Yii 可以很快的建立一些常用的功能,就像 ASP.NET 吸引人的也是這個。但反觀 CI,除了把 MVC 拆開,幾乎一切都要自己來,可真累。
Yii 我沒用過,ASP.NET 我用過一陣子,但沒喜歡過它。我要表達的是,現實世界沒有所課的standard的東西,不論它們提供的功能多完備,沒有那個需求是可以完全靠著它們所提供的來完成。而要在它們限制的架構下,完成一些特定要求時,就像上文提到的類似twitter的功能,那會是很痛苦的。像我所維護的 ASP.NET 程式,幾乎每一項功能都必須override,那真的不如不用。也許,開此先端的是Java吧,印象中,要寫Java的程式,沒有所謂的簡單這件事。
使用CI,它只是恰如其分的,把MVC拆開,其他的,靠自己。雖然,開發時,要多投入一些精力,但它保持了最大的彈性,也兼具維護性。
咦,寫此後記時,並未看前面的舊文,再回頭瞄了一下,竟然說的還是同一件事。所以,問題,轉一圈回來,還是問題。

此外,開頭說的,「自由意味着使用 CodeIgniter 时,您不必以某种方式命名数据库表,也不必根据表命名模型。这使 CodeIgniter 成为重构遗留 PHP 应用程序的理想选择,在此类遗留应用程序中,可能存在需要移植的所有奇怪的结构。」,真的是沒錯,這尤其是值得強調的一項特點。
要把 asp 和 php 的程式 porting 到 CI 時,只需建一個 Controller,然後建立對應的 method,其中只要有一行,像這樣

 public function index() {
    include('../user/index.php');
 }

就完成初步的 porting 了,很快吧。

沒有留言:

張貼留言

網誌存檔