Jump to content
Larry Ullman's Book Forums

Porting Example 2 To Yii


Recommended Posts

Hi Larry, I must begin my post the same way I begin every new topic: Thank You. Thank You for making PHP(and web programming in general) palatable for the normal folk.

 

My question is quite simple but the answer may not be. How would I port the second example to the Yii framework? I obviously don't mean the database itself or even the original html template files, as Yii is built to use both. It would seem, in going through your mini-series on the Yii framework that when you create the MVC via Yii, it creates it's own validation and such. How much of that type code would you keep in the current example as is and how much would need to remove and yield to the generated(and edited) code Yii has done.

 

My purpose for this question is pretty straightforward: I know the steps/time taken to create the site as is, 100 percent hand coded from scratch. I just want to know how much time/coding using the Yii framework would save me on a future project of similar size.

 

I know the Yii framework(and frameworks in general) use OOP while Example 2 is Procedural, but any ideas would be most helpful.

 

P.S. The site, as is, has given me a wonderful template and blocks of code that can now be modified for other sites, so that alone has made this book unbelievably valuble. Thank You again.

 

P.P.S. I asked this question because I wanted to know, duh, but also from the following line on the Amazon description section From the Author for this book ,

 

"After much debate, I decided not to use object-oriented programming or frameworks in the book, although I do intend to write up supplemental material showing how some of the examples and code would be translated into an OOP or framework version." If I completely missed these posts, please just point me to them.

Link to comment
Share on other sites

P.S. The site, as is, has given me a wonderful template and blocks of code that can now be modified for other sites, so that alone has made this book unbelievably valuble. Thank You again.

 

"After much debate, I decided not to use object-oriented programming or frameworks in the book, although I do intend to write up supplemental material showing how some of the examples and code would be translated into an OOP or framework version." If I completely missed these posts, please just point me to them.

 

I'll pick those I can answer.

 

The point here is that you should be able to create classes in PHP that are very portable and deployable in new site. When you find yourself copying a lot of classes from your previous projects, you know you are doing something right. (probably) Object oriented code is all about the re-usability. That takes us to the next pseudo-question of yours.

 

Developing solid classes takes time. It's all about the details. You'll polish those classes until they are easy customizable and easy to work with. When you are writing examples to make a point, object-oriented programming isn't always the right choice. There's absolutely nothing wrong about writing procedural code. Sometimes you need a full functional class, sometimes you need a static helper class (sorting, etc) and sometimes the best thing is going procedural. OOP is not the king every time.

 

Without knowing what the discussion is really about, I dare make these general comments, so go easy on me if I missed something. ;)

  • Upvote 1
Link to comment
Share on other sites

Hi Larry, I must begin my post the same way I begin every new topic: Thank You. Thank You for making PHP(and web programming in general) palatable for the normal folk.

 

Thanks for the nice words. Very kind of you.

 

My question is quite simple but the answer may not be. How would I port the second example to the Yii framework? I obviously don't mean the database itself or even the original html template files, as Yii is built to use both. It would seem, in going through your mini-series on the Yii framework that when you create the MVC via Yii, it creates it's own validation and such. How much of that type code would you keep in the current example as is and how much would need to remove and yield to the generated(and edited) code Yii has done.

 

Generally speaking, the goal would be to yield to the Yii-geneated code as much as possible. In fact, I'd start with the same database, then generate all the controllers and models, and then edit what I needed (i.e., I'd scrap the existing code and build it with Yii from scratch). You'd also want to create models for some of the data that's not stored, such as the credit card information and billing. You write the rules into that model, and then Yii handles the validation.

 

My purpose for this question is pretty straightforward: I know the steps/time taken to create the site as is, 100 percent hand coded from scratch. I just want to know how much time/coding using the Yii framework would save me on a future project of similar size.

 

On the first project you created in Yii, it'd probably take 3 times as long, because you'd have to do a lot of learning. On the second project, it'd probably take the same amount of time. On subsequent projects, it'd go much, much faster with Yii.

 

P.S. The site, as is, has given me a wonderful template and blocks of code that can now be modified for other sites, so that alone has made this book unbelievably valuble. Thank You again.

 

Thanks! I'm glad you liked the book.

 

P.P.S. I asked this question because I wanted to know, duh, but also from the following line on the Amazon description section From the Author for this book ,

 

"After much debate, I decided not to use object-oriented programming or frameworks in the book, although I do intend to write up supplemental material showing how some of the examples and code would be translated into an OOP or framework version." If I completely missed these posts, please just point me to them.

 

Yeah...haven't gotten to that yet, mostly because I've been distracted. But the latter half of 2012 is going to be largely Yii-based for me, so maybe I can make that happen then. Sorry about the delay.

 

Let me know if you have any other questions.

Link to comment
Share on other sites

 Share

×
×
  • Create New...