Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Larry

"The Yii Book" Now Available

Recommended Posts

Let me just emphasize once again, i will be using Yii for my project i am final on that but i want to get better with programming and logical structural thinking that's the reason i will build one for practice while you are finishing of the Yii book.

Share this post


Link to post
Share on other sites

Yii::setApplication($this); In CApplication.php sets the app instance so you can call Yii::app()->db->username = 'this username'.

 

So that's why.

Share this post


Link to post
Share on other sites

Been working through the YiiFramework Blog example, and then switched over to the Yii Definitive guide. It is quite a struggle trying to put things together as there are lack of examples and each topic kind of jumps about and their is a lot to take in. I am figuring it out on my own but it is taking time.

 

So far gii was of little use to me as i could only generate a minimum of one model per time and all of my data input screens require at least 2 models.

 

Its interesting to see Zend framework also have a version 2 now, i was checking out some of their coding style and it looked approachable. But with the time it takes with Yii it seems to be enough for me already.

Share this post


Link to post
Share on other sites

I think the Yii documentation is well written, but part of the problem is that different parts (the blog, the definitive guide, the API docs) discuss different things, so there's no cohesion.

 

Like the picture!

  • Upvote 1

Share this post


Link to post
Share on other sites

I like that word, cohesion is a good way to describe it, yes Larry you are like a chemical binding agent, you create a universal stability.

 

Yes your YiiBook is so good even my Chihuahua took a minute to give it a glimpse.

Share this post


Link to post
Share on other sites

I had a go at the Zend Framework 2 tutorial i thought it might be fun but it just starts to get so horrible and ugly so i stopped i couldn't take it anymore. Code Ignitor looks easy compared to Yii, this is how Yii looks compared to Zend Framework 2 even though you are just trying to get to the same point with more trouble.

 

I have been messing around with Yii forms, i saw some examples on how to add data to multiple models which looks easy. The trouble is the people that are submitting these examples, I don't what credit they have or even if they examples are correct. So it basically means i have to wait for you to do the same things in your Yii book and have your methods confirmed. Like Jonathon i have a large site to build and need to be 100% on these methods before proceeding forward.

Share this post


Link to post
Share on other sites

Hi Larry,

 

I'm new to the Kindle version, how do you update the book. I just went to account and downloaded the latest mobi version to my ipad. It downloaded the whole book again, rather than update the current one. As you know I've never really used Kindle so could you help me with this when you have a moment.

 

Thanks

 

Jonathon

Share this post


Link to post
Share on other sites

Chapter 5 looks good but i have already done that stuff now, i guess this saves people time of trying to figure it out like i did, but in some cases trying to learn the hard way sometimes works out better. At the moment i am trying to figure out how to save two models successfully i used the beforeSave() method but i had a few problems yesterday, hope to resolve the situation today. With Yii i keep having to ask myself, why, when, where and how, but any way when it works its worth it.

 

Edit: Oh, i have learnt something new from this, you can set defaults in the validation rules, rather than adding to beforeSave() method in the model class. Makes me think this, should i sit back be lazy and wait for the cohesion. Lol even the guy who wrote the blog demo could learn a thing or two from this chapter.

Share this post


Link to post
Share on other sites

I can assure you it would generally be an even bigger pain in the butt. I see that YII allows to to define a HAS_MANY relationship in your models "relations()" method. That way, you don't need something like a "UserFile" model you would else need. I'm guessing there's some kind of automagic done to each models (User and File) save method. That's pretty much a straight guess from my side, but I at least hope YII has implemented that. I'm just guessing you need to set the foreign key to a value, call save(), then let YII handle the rest.

 

What I did in codeIgniter, was to define that said "userFile" model. On insert/update, two calls where applied with some transactions involved. On Read, simple joins. On deletes, only the files where affected.

 

Btw: Larry. Don't agree with what you said about the has one relationship. If you want your tables to be boyce-codd/ENF3, those are mandatory. Postal numbers, country codes, favorite movie... One to one is mandatory in all these situation. I know you are completely aware of this. (as you've written about Normalization before) I'm wondering how I'm misinterpreting you here, or how I'm missing parts of the full picture.

Share this post


Link to post
Share on other sites

Hey Antonio, when you store countries do you store them in an indexed array or do you store them all in the database with id's as such? I used to put my countries in the database but i thought it was messy so i pulled them all into an array now, but used the country code in the address column which can later be referenced.

Share this post


Link to post
Share on other sites

Jonathon, did you lose all your notes and highlights? If so, I apologize. I tested in using my Kindle application on my Mac and it retained my notes. I'm doing more research on this now, but I'm not exactly sure how Amazon handles this.

 

Thomas, you're certainly welcome to disagree, but not everyone normalizes to 3NF every time. Nor, do I believe, you always should. In my experience, I see lots of one-to-many relationships and very few of any other (between tables).

  • Upvote 1

Share this post


Link to post
Share on other sites

Hi Larry,

 

No I didn't lose my notes, all that happened was I went to my yii.larryullman.com account and clicked the mobi download and opened it in Kindle. It downloaded the whole book to date, so i have the first version, with my notes and also a second version with the extra chapters in it. So two copies of the same book. I just don't know how to update the first version of the book so I have just one copy?

 

Sorry if this seems a silly question.

 

Jonathon

Share this post


Link to post
Share on other sites

Hey Jonathon. No need to apologize. I'm still trying to figure this stuff out myself. I'm glad you didn't lose your notes. I'm surprised by the result of having two versions of the same book, though. Let me do some research and see what I can figure out.

  • Upvote 2

Share this post


Link to post
Share on other sites
Thomas, you're certainly welcome to disagree, but not everyone normalizes to 3NF every time. Nor, do I believe, you always should. In my experience, I see lots of one-to-many relationships and very few of any other (between tables).

 

This is why I ask. You have five times my experience, so maybe I'm missing something here. I might be confused by the two terms "belongs to" and "has one". Having some experience with normalization, I would rather stick to the term "one-to-one relationship" instead. I'll instead give you some examples, so you can judge my reasoning.

 

1) Person and Country: The Person has one nationality, and in this situation, dual citizenships are ignored.

Person ( id, firstname, lastname, country_iso*, .... )

Country ( iso, country, .... )

 

2) Customer, Postal and Province: Customer has an address located at a postal code, located in a province.

Customer ( id, name, postal_id*, address, ... )

Postal ( postal_id, postal_name, province_id* )

Province ( province_id, province_name )

 

Bold : Primary key

Astrix: Foreign key

 

---------------------------------------

 

Would you agree with such structures, or would you normalize them differently? Hope you can clear up some confusion here. Long explanations not needed though. I know you are a busy man.

Share this post


Link to post
Share on other sites

Hey Jonathon. No need to apologize. I'm still trying to figure this stuff out myself. I'm glad you didn't lose your notes. I'm surprised by the result of having two versions of the same book, though. Let me do some research and see what I can figure out.

 

Thanks Larry, no rush. I can manage with it, but in the long run it won't be that convenient.

 

thanks for getting back to me

 

Jonathon

Share this post


Link to post
Share on other sites

Thomas, "belongs to" and "has one" are the labels Yii gives to the two sides of a one-to-one relationship between two models. In the database, I would still call it "one-to-one". As for your example, that is a perfect case where you could use your setup to achieve true 3NF compliance. I, however, would not normally. It adds too many more joins just to get the user's address and the values involved don't change that often. But, again, you could do it that way if you wanted to be strict.

  • Upvote 2

Share this post


Link to post
Share on other sites

Thanks for a great answer. I tend to be rather strict about normalization, mainly because I have little experience breaking the normalization rules. I can definitely see the benefit in doing so, but I guess rules for when to break the rules is hard to determine. Figuring out when to apply it is rather tricky. Do you have a rule for that yourself?

 

As an simple example, could you identify when it would be ok to denormalize the table Postal and when it would not? Again. This is mainly curiosity on my part.

Share this post


Link to post
Share on other sites

Antonio do you have the actual resources for the full list of postal info for each country? I also think trying to determine database structure's now is pretty much impossible that is depending on the size of your website. Once there is more data and once you know exactly what queries you need and then how to limit stress on particular tables then you would really know how to set everything up correctly. That's why again done is better than perfect for the time being.

Share this post


Link to post
Share on other sites

No, sorry. Only for Norway.

 

You have a point, but there are strict but simple rules for normalization. Figuring out when to denormalize is much more tricky, but should also be possible to set general rules for. As Larry has done this for a while, I'm guessing he can identify cases where both practices would make sense.

 

You also need to remember I'm a student. What's good enough for my personal projects might not be good enough for large systems developed by a company. Having some general ideas on when to denormalize could therefor be important. You should never stop learning new things. I'm not asking this to go denormalize projects that already work.

Share this post


Link to post
Share on other sites

Well, the first rule of thumb is always err on the side of normalization. Especially when you're learning. I will not normalize in situations where the data isn't likely to change, won't be expanded, and will be frequently used in JOINS. One example would be a gender identifier or any other Boolean-like value. Maybe even small sets, such as user types. 3NF would suggest user type should go in a separate table, but in my experience, it can work okay in the users table, too.

 

Addresses are tied to users and frequently needed, so joining a zip code to a city to a state (for example) and joining all that in gets to be too expensive. And that information doesn't change that often.

  • Upvote 1

Share this post


Link to post
Share on other sites

Larry what's your time plan per getting one chapter done up to the putting it all together examples which i would suspect will take longer?

Share this post


Link to post
Share on other sites

I'm not sure that I understand what you're asking, exactly. Reasonably, I think I can get a chapter a week done, although I'd like to be a bit faster. The next update will be within two weeks, I expect, and have 2-3 chapters.

  • Upvote 1

Share this post


Link to post
Share on other sites

I'm not sure that I understand what you're asking, exactly. Reasonably, I think I can get a chapter a week done, although I'd like to be a bit faster. The next update will be within two weeks, I expect, and have 2-3 chapters.

 

I would say that sums my question up. It was just looking so that you may finish the book in June 2013 or something like that. But if you can make it by March or April even better. I have been doing some stuff myself taking a few steps forward but then later having to come back two steps to make three steps forward. The sooner your stuff is done the sooner we know what is right and what is wrong. Only you can confirm this with the owner of Yii.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...