0

have planned to write my own light weight MVC for PHP, that will be used as base for my sites I develop. I have no problem with PHP, OOP, et al. I have trouble on how to actually load Models In controllers and use them amd loading Controller values into Views. In short, I don't know how M-V-C interact behind the scenes. Any tutorial (concentrating on that) or any contribution is welcomed! Thanks!

3
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo
0

My first question would be, why are you writing your own MVC framework? Why do you think you can do it better than any of the other people who have already released frameworks?

I'm not asking to be mean, it's a genuine question you need to ask yourself. Could your time not be better spent learning an existing framework?

I wanted a lightweight framework for building websites, and considered writing my own. I then considered the benefits to myself and others if I use an open source framework.

I have recently started working with Kohana. It's lightweight (~3mb) and offers lots of extensions and helpers.

R.

0

My first question would be, why are you writing your own MVC framework? Why do you think you can do it better than any of the other people who have already released frameworks?

I'm not asking to be mean, it's a genuine question you need to ask yourself. Could your time not be better spent learning an existing framework?

I wanted a lightweight framework for building websites, and considered writing my own. I then considered the benefits to myself and others if I use an open source framework.

I have recently started working with Kohana. It's lightweight (~3mb) and offers lots of extensions and helpers.

R.

I have two purposes:
1. Learning
2. Make framework for commercial websites I can easily maintain.
And yes, I'm fan of CodeIgniter. But it is sometimes too heavy for even simple sites!

BTW, I was watching one youtube video and it gives me little light on MVC. There is fourth component, the bootstrap that isn't mentioned :)
How they really interact though is still a puzzle to me!

0

Are you asking about a PHP related question? Like how you can make use of PHP to interact between several layers?

Or are you asking about a more general MVC related question like how each layer should interact?

Sorry I didn't get your question.

BTW there should be many light weight MVC framework anyway. I would suggest to download free one and start reading the code. Best way to learn lot of things in relatively short period of time.

cakePhp is quite light weight.

But my PHP knowledge is tends to zero. If you are asking about more generic MVC then I could explain little bit.

Edited by alwaysLearning0: n/a

0

Are you asking about a PHP related question? Like how you can make use of PHP to interact between several layers?

Or are you asking about a more general MVC related question like how each layer should interact?

Sorry I didn't get your question.

BTW there should be many light weight MVC framework anyway. I would suggest to download free one and start reading the code. Best way to learn lot of things in relatively short period of time.

cakePhp is quite light weight.

But my PHP knowledge is tends to zero. If you are asking about more generic MVC then I could explain little bit.

I'm puzzled on how PHP M-V-C layers interact in real world!
Anyway, explaining how the M-V-C interact in general does not hurt and will add to knowledge base :)

0

While writing I realized it could be so big!!!!!!! but

Ok, so here it goes:

Model: A collection of classes which actually represent your data, in more plain words: A simple POJO class which actually will represent a table in database. Lets say database has a STUDENT table, with column Name and ID, then your Student class should also have member variable name and id.
A model should be persistent with the table.

Now the way you can make a model persistent is a huge thing and can be implemented in so many different ways and most of the time this is actually one of the deciding factor of a framework being light or heavy.

Controller:
A set of classes which actually controls the behavioral of the application: again in plain words, when you submit a request, a controller class should pick it up and call the business logic. business logic can be a part of the controller layer or can be separate layer as well. When a controller receives a request, it knows the business logic class which will handle this (a controller can be a business component itself, it depends how you design your framework ) and after processing the request it knows which data to show (keep reading view to understand this)

View: View is the pure PHP/JSP/ASP pages which actually will show the data, in plain words: whatever we see on browser is the view. So view has to show data and we represent data by the Model, so basically view will show the data of the model class.

so you need to propagate this model class between view and controller. usually in one page/view you need to show several kind of model classes (like Teacher, Student, Course), so some framework use another class to hold all these model class, but again its a design question.

So from developers point of view, you need to implement Contexts:
A view context: which will hold all the model data which view needs to show.
A Controller Context: when a controller receives a request from view, it can access the context of view and retrieve the models and use them in business logic.
A persistence context: Your model is synchronized with the database table.

Best of luck.
I hope it helps.

Edited by alwaysLearning0: minor changes.

0

While writing I realized it could be so big!!!!!!! but

Ok, so here it goes:

Model: A collection of classes which actually represent your data, in more plain words: A simple POJO class which actually will represent a table in database. Lets say database has a STUDENT table, with column Name and ID, then your Student class should also have member variable name and id.
A model should be persistent with the table.

Now the way you can make a model persistent is a huge thing and can be implemented in so many different ways and most of the time this is actually one of the deciding factor of a framework being light or heavy.

Controller:
A set of classes which actually controls the behavioral of the application: again in plain words, when you submit a request, a controller class should pick it up and call the business logic. business logic can be a part of the controller layer or can be separate layer as well. When a controller receives a request, it knows the business logic class which will handle this (a controller can be a business component itself, it depends how you design your framework ) and after processing the request it knows which data to show (keep reading view to understand this)

View: View is the pure PHP/JSP/ASP pages which actually will show the data, in plain words: whatever we see on browser is the view. So view has to show data and we represent data by the Model, so basically view will show the data of the model class.

so you need to propagate this model class between view and controller. usually in one page/view you need to show several kind of model classes (like Teacher, Student, Course), so some framework use another class to hold all these model class, but again its a design question.

So from developers point of view, you need to implement Contexts:
A view context: which will hold all the model data which view needs to show.
A Controller Context: when a controller receives a request from view, it can access the context of view and retrieve the models and use them in business logic.
A persistence context: Your model is synchronized with the database table.

Best of luck.
I hope it helps.

good food for thought....thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.