為何要選 CodeIgniter -- 一些想法

不像ASP.ET的一言堂,除了一個 ASP.NET MVC 之外,沒得選擇。在PHP的世界中,有各種 MVC Framework 的 project,可說是百花齊放。

使用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。

另一個因素,Stability (you can be assured that API doesn't change much with the release of a new version),API 若是變動,將是一大負擔。好像我就看過有人對於 Kohana 有過如此的批評。

還是不要想太多吧,像 FuelPhp 又是另一個吸引人的產品,它的出現正是因為有一些 CI 的參與開發者對方向有一些歧見。有個比較的說法,好像還蠻傳神的,CI 是手排車,而 FuelPHP 是自排車。

Comparing them to one another is like comparing a manual transmission car to an automatic transmission car. They’re both cars, they both get you from A to B, one just has more parts and technical engineering involved.

不過,要是如此三心二意,又會玩不完的,到最後又會迷失其中。