Web Application Structure Design in MVC

I am a beginner for Yii framework. The MVC design pattern sounds very impressive for people who don’t know much about web programming, like me.

While learning Yii, I am trying to figure how MVC can apply to other famous website I’ve seen, such as www.delicious.com.

Obviously, there is a gap between knowing MVC,Yii and capable of programming www.delicious.com.

Can you tell me how www.delicious.com is done in Yii MVC model? If Yii MVC model is capable of doing that. e.g.: Should each button be some kind of action of certain controller? what should be the controller?

Thank you very much!

Nicolas

Most of the time you just build your controller for a model (e.g. Post,Comment etc). And every action you can do is a action :)

So when you add a comment you have an create action in your comment controller.

Basicly every Webpage can be build as an MVC designed project. The MVC just help to organize the code better and makes it easier for other people to understand your code.

Hi Nicolas,

I would strongly advice you to take a look at basic Yii documents and resources like “Building a Blog System using Yii”, “The Definitive Guide to Yii” and “Take the Tour”. There you’ll find not only answers to most of your questions about MVC, but also concepts of how Yii is organized and works as good as basics to start developing your own application using this framework. Maybe not as big as delicious.com at the very beginning, but in the future… who knows, who knows… :]

Cheers,

Trejder

Thanks. Your feedback. I think the same way. But it’s the how part I couldn’t figure out.

I read the Guide and went through the tutorial already, but still feel a little bit short. Cheers!

Then continue to the next step, which is reading guide / watching screen cast of building blog application from scratch.

The first thing that you must do for every new product is: think about what you need(what the tool/site should do).

So for a site like delicious.

You want to save urls and they should have a relation with users.

So your project will need at least 3 tables(models) lets call them user, url and user_has_url.

what User and Url will do is simple save the necessary informations!

user_has_url is a MANY to MANY (in yii MANY_MANY) relation which allow the users to have multiple urls and a url can be assigned to many users.

next step is to create the webapp with the command line.

then you use gii to generate the CRUD(Create Read Update Delete) actions for you (only for Users and Url, because user_has_url has only 2 columns for each primary key of user and url).

then you "just" have to design your views an edit the actions (and you should add some awsome features like authentication for your usermanagment)

I hope you that wasnt to basic for you (dont know your experience with programming etc :))

and sorry for the bad english, im from germany ;)

Thanks a lot, Command! I’ll think this way and I’ll read your reply again in several weeks to see if it makes better sense to me:)

btw, nothing wrong with your German English.

Hi,

I’ve read this thread and felt same as its author: I’m an advanced PHP developer with good (possibly even better) OO skills/understanding but never programmed in MVC. I’ve programmed custom PHP5 OO projects and did a lot of Drupal development which is far from OO/MVC development.

There’s a big difference between reading all the manuals on Yii documentation, which are there and they are quite good, I must note, understanding and assimilating their ideas, principals, etc, then to having the ability to actually start programming in Yii.

Well, I guess that after reading the elementary tutorials one just needs to jump to the deep water and “just do it”. Over time, things will fall into the right place in one’s mind as not only his knowledge of Yii/MVC will grow, but he’ll gain new thinking ways to web site design in MVC. He’ll just start to think in MVC (he or she, of course :slight_smile: .

I’m on the same spot now - I’ve read much of the documentation (blog tutorial, some of the “definitive guide”, Larry Ulman’s tutorials and others…) and still can’t say I know how to start implementing all this. As always - I need to jump to deep water, utilize MVC-experienced colleagues, and realize that the first project will inevitably appear lacking or even badly implemented in some aspects in the future. That’s just the way things go.

Cheers!

Well… I don’t know like you or others, but I had even deeper jump into water. I had not much time for reading all the good stuff, you mentioned. For me ideal solution was to follow demo application generated by yiic, try to understand it’s logic and only follow to the guide / forum with questions. It was a hard time though. What I’m trying to say is that I used demo application as a main source of information for me, while using guide (except very basic content) as a support one.

And I even had less experience that you, when starting with Yii as I wouldn’t count myself among experienced PHP/OO developers! ;]

sounds like a “tough experience”. luckily for me, I had the little time for reading the mentioned docs. I know this is not always possible, which is sad since I consider this the minimum, more or less (maybe a bit more than minimum, not much more than that). I never understood work places that didn’t understand that there are minimum resources that are needed for a developer to get acquainted with a technology to be able to start working with it.

And, OO is nice. For me, its a blessing upgrade from procedural programming (Drupal, for instance), for my weary mind, keeping it stimulated enough to provide some pleasure during work.

A little bit off topic, but…

I agree. The only problem – private notice – is that PHP creators seems to be loving procedural way so deeply (words like “maniac” aren’t enough here) that even now, every new introduced class is always surrounded by that procedural bullsh*t. Can’t understand this. This is madness, if we assume that OO is de facto standard of professional programming like for a ten years or so?

I heard that DateTime class could be a good example here. Released not so long ago (in not to old version of PHP), when OO programming was actually the only reasonable way for doing projects bigger than "Hello World! This is my first webpage". And immediately surrounded by stuff like datetime_create. Madness, really madness! :]

I love PHP and I find this language able of easy programming nearly anything. With Yii programming in it becomes state of art. But I can’t disagree with developers of other languages saying that PHP is one whole big pile of garbage and thousands of not needed, not required functions. That is painful true. From this point of view, PHP is nothing else then just a big pile of garbage.

What we have to remember is that OOP never really come into PHP until version 5. Until then, it was half heartedly implemented. OOP has been introduced as a progression through developers requesting its features and functionality. I think a lot of ignorance exists in developers of other languages as they do not know the capabilities a modern PHP application can posses.

The success of PHP initially was its low barrier of entry, you didn’t need to know OOP, type hinting wasn’t enforced and getting up and running was just so easy. I find newcomers to PHP and MVC frameworks are struggling to learn it all at once. There is now a need to understand design patterns and proper development practices (unit testing, code profiling and analysis).

My advice is to practice, practice, practice. There is no substitute for hands on learning. Listen to what other professional PHP programmers are saying and try and understand them. View webinars on topics, attend conferences or just get involved with an Open Source project.

Sorry, for late reply…

I agree with you, but then again comes this DateTime example. OK - maybe PHP is still learning true OOP… Maybe we’ll see true OOP in PHP 6 (will we?). But, then again… what is the reason for publishing rather new library, written purely in OOP mood and “support” it with a bunch of procedures doing exactly the same, but in procedural-approach, as it can be achieved in OOP one.

For me this is just a nonsense. Ether PHP creator fears pure-OOP or are still supporting procedural style of coding. I don’t see third reason, and both mentioned are terrifying. Doing so, as they did with DateTime brings nothing to PHP than just a new arguments for it’s antagonists, that it is really a pile of garbage code.

Practising? Watching webminars? Well… OK, but isn’t that a little bit off topic? ;] I’m not disputing here if PHP is an easy or hard language (it is fairly easy). I’m trying to get answer here (or finally understand), why PHP creators are still making it as a huge pile of sh*t-code?

I kind of like that it’s a pile of s-code. That’s actually the part about it I like the most.:lol:

I am coming from C++ and find it really refreshing that you can do everything in PHP: procedural style and OOP style.

You can write messy code in both styles, mind you. ;)

I like the freedom you’re given, and I find it to be an expressive language.

Of course it has it’s quirks, but that’s the price you pay when you are using an evolutionary language like PHP.

I think they’re doing a great job.

I’m not saying they’re not doing a great job and never ment to say this!

I just wanted to say that I would be much more satisfied, if evolutionary would become revolutionary. And revolution means – dropping all the shit that comes in the back and focusing on what is best.

I love PHP for everything you mentioned and for many more. But this doesn’t change that it the same time a hate it for every mess that is still there (and is still being added) in favor of ease of development, instead of professionalism. And I won’t forget that my love to PHP burned with a new flame, when I met Yii for the first time - mostly because for cleaning and organising most of the shit that comes when codding in a pure PHP.

Now, that is a good one: love and hate in the very same time! :]