topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday March 19, 2024, 5:16 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: The Yii PHP Framework  (Read 23543 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
The Yii PHP Framework
« on: April 20, 2011, 04:53 AM »
Just wanted to post some quick thoughts after spending a few days with the yii PHP Framework.

I have been looking for the "perfect" web development framework for a number of years.  I've had quite a bit of experience with a relatively lightweight PHP framework called CodeIgniter, which i quite like, and I have spent quite a bit of time trying to use the Drupal CMS system as a framework for custom web application coding, which i have vocally warned people to avoid.

You could sum up my current thinking about frameworks as highly dubious of anything fancy.  My experience is that the more minimalist the better -- less to go wrong, and less exotic code that does some stuff in super-clever ways but makes other stuff insanely convoluted.  The more a framework tries to do stuff in some clever automatic way, or enforces some elaborate structure, the more painful it is to use when you inevitably need to do real-world stuff.

I spent quite a bit of time this year looking at Python frameworks -- hoping to switch from php web development to python web development -- but concluded that at the current time, deploying python web applications is a total joke and a catastrophe for anything other than a scenario where you are running a single python web application on a server.  I also didn't fall in love with Django, Pylons, or the other major python web frameworks.

So anyway, I decided to experiment a bit with yii.  It's much newer than CodeIgniter but shares much of the same focus on being minimalist and fast.

However, it is substantially "heavier" than CodeIgniter in many areas -- providing some very cool form and data handling classes.  I'm still unsure about how much of a cost these features will inflict when it comes time to do some non-standard stuff, and i would prefer that it didn't do quite so much "magic" stuff behind the scenes.  In this respect I think i still prefer CodeIgniter.

However there is one area in which yii would seem to me to be a really clear win -- and that's what inspired me to post -- the quick construction of scaffolding code (controllers, models, views) automatically from existing database tables.

That is, if you have a legacy database that you want to build a web application around, yii has some absolutely fantastic tools for automatically creating controllers/models/views that will let users browse, view, create, edit entries in the database.  Normally I would avoid such features, but there is no denying that for some projects this might represent a huge time savings.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #1 on: April 20, 2011, 05:30 AM »
Did you ever take a look at CakePHP?
- carpe noctem

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #2 on: April 20, 2011, 05:35 AM »
I took a very long look at CakePHP a couple of years ago.. It was a toss up between that and CodeIgniter for a big project.  I went with CodeIgniter because I wanted something leaner and more lightweight.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #3 on: April 20, 2011, 05:47 AM »
OK, just popped into mind because you mentioned Yii does model/view/controller.
- carpe noctem

bscott

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 21
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #4 on: April 20, 2011, 06:06 AM »
We have been down the same road. I looked at CakePHP but went with CodeIgniter because I preferred less magic. I have spent some time with Drupal and am not quite as averse to it as you - but then I haven't tried to use the Forum module.

Recently I have looked at Python frameworks starting with Django which I initially quite liked but then felt it was too heavyweight for me but it does have a good admin feature for rapid CRUD. I then took a brief look at Pylons and Turbogears neither of which were to my taste: Pylons has gone into maintenance mode and Turbogears makes too many decisions for me.

I am currently looking at Pyramid which I am quite taken with - it strikes me as the Codeigniter of the Python world.

I will now add Yii to my list (which never gets any shorter).
« Last Edit: April 20, 2011, 06:10 AM by bscott »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #5 on: April 22, 2011, 11:53 AM »
Btw if you want something minimal Lemonade looks interesting:
require_once 'vendors/limonade.php';
dispatch('/', 'hello');
  function hello()
  {
      return 'Hello world!';
  }
run();
But its a micro framework, CodeIgniter looks like Zend Framework in comparison.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #6 on: July 04, 2011, 06:39 AM »
I've been using Yii more lately and I have to say that there are some areas where it is absolutely a joy to use.  It's Active Record and Form classes make it very clean and easy to present forms, do error checking/reporting, and save/modify model data.  This is the bread and butter work of these frameworks and Yii just excels at this this kind of stuff.  It also seems to be very flexibly in terms of how you organize your code and how you handle flow of program execution.

To be sure it's not perfect, but I continue to be impressed with how smooth it is to code for, in a way that i've not been with any of the other frameworks i've looked at. 

Rover

  • Master of Smilies
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 632
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #7 on: July 04, 2011, 11:31 PM »
Hey Mouser --  I don't want to alter the thread direction, BUT have you looked at Drupal?   :-[

I have faithfully ignored it for many years.  Someone at work asked me to consider it and much to my surprise, I can drop only slightly modified php directly into a new page. (node, or whatever they call them.)  Given the steep learning curve of most php frameworks, I'm considering that I might be just as far ahead to learn the Drupal  way and simply use the CMS as a framework.

I  think you and I struggle with similar goals for perfection in tools.  It'd be really cool to not have to re-invent the wheel for normal requests like, Authentication, Intrusion prevention, DB connectivity, forms creation, processing and reporting, etc. all of that WITHOUT having to conform to the design constraints of the rabid Framework designers.  Or at least without having to spend 6 months of in-depth study, plus 3-4 projects with false starts and failures to learn the entirety of the framework design and functions.

Why can't I just have it all, right now?!!

Look at me getting all "developer-y" and serious in a post, without smileys even... can't have that.  :P

 :read: :two:
Insert Brilliant Sig line here

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #8 on: July 04, 2011, 11:34 PM »
Have i looked at drupal?  

https://www.donation...dex.php?topic=8030.0

I've used drupal on several projects now, and found it consistently unintuitive, confusing, and unpleasant.

It is powerful and extremely flexible, and has a nice modular design, and has a library of books about it (which i love), but it is big and alien.

If you are a coder who needs to develop a custom project that is first and foremost a CMS, Drupal may still be the right choice.  It does a good job of supporting modular non-invasive extensions.

But I was very unhappy with trying to use Drupal as the base of a project which was not really a CMS.  It *looks* like it might be a good foundation for generic projects that have user accounts, etc -- but i found it deeply frustrating.

And especially after having gone back to basics with a lightweight framework like yii, I can say it is immeasurably more enjoyable to build code on top of a more lean and minimalist foundation, rather than trying to find your way through the convolutions of something like Drupal.

It's really an age-old problem for programmers, whether it's better to rewrite your own version of some code or use an existing codebase.  Drupal has a ton of code that can be appealing in terms of letting you start off with most of the code you need already in place.  But as someone who has often leaned in that direction, I'm remembering now nice it is to write it yourself and really understand the code well, and not have so much stuff in there that has nothing to do with your needs.
« Last Edit: July 05, 2011, 01:11 AM by mouser »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #9 on: July 05, 2011, 04:24 AM »
Sometimes what you need is a framework that makes it quicker to get to that point where you have a custom solution. I couldn't imagine starting a new PHP project from scratch without frameworks (CodeIgniter in my case)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #10 on: July 05, 2011, 04:27 AM »
CodeIgniter and Yii are similar PHP frameworks, and they are both excellent starting points for custom projects.

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #11 on: July 05, 2011, 08:03 AM »
Hey mouser if you define the database in Yii, that makes it possible to version control your database schema right? Can you define database migrations with it like rake on RoR? Is it right you need commandline access to start a project?
« Last Edit: July 05, 2011, 08:22 AM by justice »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #12 on: July 05, 2011, 09:25 AM »
Is it right you need commandline access to start a project?
you would only need commandline access to use the feature that builds a new project directory for you, but this is 100% optional and not very important. you can easily make your own new application directory structure manually.

as far as version controlling database schema.. yii wont create database tables for you automatically, so in as much as their is a database schema it is all in your class code.  though take my comments on this with a grain of salt because this is an area i don't know much about.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #13 on: July 15, 2011, 02:31 PM »
Quick update:
I've spent the last couple of weeks now coding a large project in Yii, and have had a real opportunity to put it through its paces doing some slightly unusual stuff.  My initial positive reactions have only intensified, which is rare for me.  Yii epitomizes the notion of making it everywhere easy to do the common things, and possible to do the uncommon things.  Definitely two big thumbs up from me.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #14 on: July 17, 2011, 08:10 AM »
One important caution to add about yii:

It has a very powerful and elegant ActiveRecord class that makes it convenient to grab database records in an object oriented way, and work with them in a very convenient high-level fashion.

However it's very hard to know how badly this will impact performance (memory and cpu) when dealing with large amounts of data.

Now there is nothing to stop you from doing low level efficient manual database querying, so you can always drop down to that when you need it.. Yii does use some fancy lazy-loading functionality which an be helpful -- but again it makes it hard to know how many queries are happening behind the scenes, etc.

In short -- if you are not working with large datasets, you are really going to benefit from these features.. But if you are, you may have to be careful about relying upon them.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #15 on: July 17, 2011, 05:36 PM »
Now there is nothing to stop you from doing low level efficient manual database querying, so you can always drop down to that when you need it.. Yii does use some fancy lazy-loading functionality which an be helpful -- but again it makes it hard to know how many queries are happening behind the scenes, etc.
Does it have any diagnostics (like RoR) that shows generated SQL sentences and time spent executing queries?

And what's it's ActiveRecord querying like? Fluent OOP PHP calls, limited functions, or something string-based?
- carpe noctem

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #16 on: July 17, 2011, 05:40 PM »
You can read more about Yii's active record stuff here:

Some of this stuff is definitely inspired by Ruby-on-rails stuff, but i don't know enough to speak intelligently about that.  Php and mysql do have their own tools for checking expensive queries etc., i don't think yii has anything extra for that.  But it does have function to help you see exactly what it IS doing behind the scenes.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #17 on: July 17, 2011, 07:51 PM »
Thanks for those two URLs - it looks mostly sane, but...
'joinType'=>'INNER JOIN',
...
'order'=>'posts.create_time DESC'
(which looks a lot like RoR AR) hints that it's probably a very thin layer above SQL... There's two reasons this makes me go 'meh':

1) magic constants are bad, especially strings. And it {w,sh}ouldn't have been hard incorporating ascending/descending in the fluent API (LINQ does it).
2) a thin layer above SQL is likely to not add optimizations that a proper expression tree API can do... which leads to fine performance for toy applications, but having to resort to hand-written (and vendor-specific) SQL when you hit medium-sized sites, rather than being able to use a fluent API well into the medium-size sites.

Note that the performance comment is just an educated guesstimate - Yii's AR implementation could easily be better, haven't looked at it :)
- carpe noctem

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #18 on: July 17, 2011, 08:10 PM »
Well like i said it has some interesting stuff about lazy loading/saving -- especially for relations.  Which is quite appealing but i tend to view stuff like that with some suspicion in terms of performance.

My assumptions generally work like this: Don't trust such high-level abstractions when performance is really an issue (large databases, etc.), and so make sure you are using something that will let you go to low-level database access when you need it.  I think yii strikes a pretty good balance there.

jpprater

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 90
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #19 on: July 18, 2011, 11:48 AM »
I spent quite a bit of time this year looking at Python frameworks -- hoping to switch from php web development to python web development -- but concluded that at the current time, deploying python web applications is a total joke and a catastrophe for anything other than a scenario where you are running a single python web application on a server.  I also didn't fall in love with Django, Pylons, or the other major python web frameworks.
I personally would recommend the web2py framework for the Python side.  It's simple and easy to set up, and I've deployed both the framework and actual apps written for web2py in real-life situations.  It's painless, if you use the framework's packaging features.

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,085
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #20 on: July 22, 2011, 07:52 PM »
Aside from this thread, everything I have come across is dated (but I'll keep looking), so I'll ask if given the 3, Yii, CodeIgnighter, CakePHP are all equally good for someone brand new if this galaxy?

My target project is not real complicated, but since it is my first, I don't mind a framework which will enforce good habits.  Any comments?
« Last Edit: July 22, 2011, 07:56 PM by CodeTRUCKER »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: The Yii PHP Framework
« Reply #21 on: July 22, 2011, 10:43 PM »
Given the 3, Yii, CodeIgnighter, CakePHP are all equally good for someone brand new if this galaxy?

Well i'm hot on yii these days, so that's what I would recommend.  CakePHP is a bit bigger and heavier and more featurefull if that's what you need.  CodeIgniter has a bigger community if that's what you need.

Note that none of these are suitable unless you are quite comfortable doing substantial coding in PHP.

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,085
    • View Profile
    • Donate to Member
Re: The Yii PHP Framework
« Reply #22 on: July 23, 2011, 01:30 AM »
If there was a push-button WYSIWYG turnkey solution for my aviation business project, I'd use it. anyone know if there is such a thing?  Unless there is such a thing and I can find it, I guess I'll take my best shot.