Jump to content

Recommended Posts

Hello i have read a lot about mvc model - view - controller but in the end i didn't quite get the things you can do. i`m referring i didn't understand how it is implemented using php and what each thing should contain and should do...

My request is if someone can help me with an example and stuff like that i would appreciate alot

Model sand for data/database abstraction layer. Simply put you can create a php file mysql_model.php with a list of function that get/set data, all the SQL is handled in the model. Function like get_user_name() or set_user_name(). One day if you want to use Oracle instead of MySQL you only have to rewrite the mysql_model.php and make a oracle_model.php instead. No other change in the others part of the application will change. Only some data handling are autorised in this part like datatype cast or escape string.

 

View is everything the user see and do, the graphical user interface. All the html/css and image. You can easly change it later to use xhtml instead of html or use XML, RSS feed or even a .exe to display the data. It shouldn't containt any actual code else that some foreach to display table (or some similar). You can make the controller save all the data into a array and call the view with it, the view put the data into a html code.

 

Controller is everything else. It receive the data from the view part, process it, save it with the model, retrieve it with model and sent it to view to be displayed. You can make a index.php get the full URL, ask the model for the data you need for that page, process the data as needed and call the view  for that page with data.

 

While it can be a good thing to build a MVC yourself to learn from it, it may not be a good idea to use it in a live production system. Many good frameworks exist for that. They have the MVC built-in.

yes i know that i could use a framework like zend or code igniter or symphony but i want to build my own framework from scratch and use it and maybe with time release it an try to create a community around with people who would love to help on developing the code.

 

 

P.S can you add an example of code for each to see the implementation ? :D because from all the tutorials and diagrams i have seen and read i didn't understand anything. just that we have a base controller that extends the controller or controllers for our website where we write the logical part like getting stuff from mysql and deploy in the viewer

Example of code ? sure...download some frameworks that are made in php and look at the code.

 

If you have hard time understanding MVC i don't think it's a good idea to create another frameworks yourself. The only exception that if you are very, very specific job to do and you aren't able to do it with all actual frameworks (which i very doubt) AND you think there enough people with the same need to create a framework for it instead of a custom software.

No offense, but if you don't understand the theory, how do you plan on creating a framework? It'll probably not end up being of very high quality and probably not be that usable for other people. You're better off using a good framework like ZF so you can learn how well-designed code looks and works while you're learning about the theory yourself too. When you have developed a solid understanding of application design and object oriented design you can perhaps make a framework yourself.

the theory i`ve understand it how it works between controller viewer and model  the data from the user(view) goes to the controller(like a backend of the site the engine) - and the model is equal with a class that helps the controller to do different stuff like a mysql class or a validation class for forms..

I have read different tutorials about creating a mvc based framework but all of them had a different aproach and just became a mess in my head... that's why i asked here for an example of implementation in pseudo code or direct code because i don't get it what should controller do..

Daniel0 as for ZF i`ve played a little and looked over tutorials and his code it is brilliant i makes you wonder why should you build your own framework when ZF has everything a coder would need but it`s pretty nice to learn how things work and stuff like that.

I posted a simple a while back. Its riddled with syntax errors but might give you an idea of the basic pattern.

 

As has been mentioned however, learning and using a good framework will give you a much clearer picture in the long run.

i have read your example there and i have searched the forum for other related problemes about implementing the mvc pattern i have found some nice things that helped me alot in better understanding of the implementation.

 

probably after i will finish the basic implementation and stuff like that i will post here the code with comments and other stuff maybe someone will need it to and for taking grades from the "gods" in php ;;)

If you understand the theory in object oriented design, then you would know that no design pattern is set in stone. There can be many different implementations of a particular pattern and a specific implementation is not necessarily better or more "correct" than another.

If you understand the theory in object oriented design, then you would know that no design pattern is set in stone. There can be many different implementations of a particular pattern and a specific implementation is not necessarily better or more "correct" than another.

 

hmm. i was thinking like that but i wasn't sure that i`m correct because of my mess in the head after reading so much code written by others as someone said it doesn`t matter how you do it the final product it`s important.

As has been mentioned however, learning and using a good framework will give you a much clearer picture in the long run.

 

I would have to disagree with this statement.  I think that 95% of the time you are going to learn a lot more form building something on your own that using an existing framework, library, whatever.  If someone wants to truly learn about the MVC pattern and how it is implemented, I would always recommend building a MVC framework from scratch.  That is want I did and so happy I did it that way.  By coding it yourself you are not only going to learn what works but also what doesn't and I think that is even more important.  You are also going to learn different way of doing things where f you using a implemented framework, you are going to learn how 1 project did it.

 

Now don't except that your first attempt (or first few attempts) are going to work great because chances are they won't but if you keep at it you should be able to build a small MVC framework.  Also, the core code for a MVC framework it also not that bigger so don't look at something like the Zend framework and think you have to create that amount of code for a MVC framework, a lot of it it just bells and whistle that are optional.

Developing your own framework will not give you a very knowledgeable understanding or insight on how the MVC Pattern works, if you don't understand it in the first place how would developing a MVC Pattern application help? It would be like saying your going to design and build a Formula 1 Racer with absolutely no knowledge of mechanical engineering and physics to learn how to ... it will turn out very poor-quality and not near capable of being able to perform the task it is intended to do, and you will most likely be in the relatively same place you started 

well fantomel said he (or she) understood the thoery behind how the MVC pattern works.  If that is true then I recommend building your own (and you should know a bit about OOP too).  If not then yes, you will not be able to build a good MVC framework.

well fantomel said he (or she) understood the thoery behind how the MVC pattern works.  If that is true then I recommend building your own (and you should know a bit about OOP too).  If not then yes, you will not be able to build a good MVC framework.

 

There's a significant difference between understanding the theory of the MVC pattern and actually creating/coding your own.  There's a lot more then just the theory you will have to know.  This kind of reminds me of a boss at my previous job, he knew minimal programming but was more so into business/marketing aspect.  He understood exactly what to do and how things worked, just not how to turn his ideas and concepts into actual code.  I would definitely recommend becoming familiar with a popular framework first. 

well fantomel said he (or she) understood the thoery behind how the MVC pattern works.  If that is true then I recommend building your own (and you should know a bit about OOP too).  If not then yes, you will not be able to build a good MVC framework.

 

There's a significant difference between understanding the theory of the MVC pattern and actually creating/coding your own.  There's a lot more then just the theory you will have to know.  This kind of reminds me of a boss at my previous job, he knew minimal programming but was more so into business/marketing aspect.  He understood exactly what to do and how things worked, just not how to turn his ideas and concepts into actual code.  I would definitely recommend becoming familiar with a popular framework first. 

 

2 days in a row without internet.. puff.. stayed all day around .. and did nothing... in the mean time i started and thinked about what you said guys.. and .. :-? i`ve build a pretty nice simple skeleton .. probably tomorrow i will post it here.. :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.