I am new to webmaster world, but I am really impressed by MVC framework. I decided to use cakePHP for my PHP development. But I found the learning curve of cakePHP quite steep. And then the hassle of getting a shared host with cakePHP support. I decided to not use cakePHP or any other framework. But I really liked the MVC approach. Soon i found out that one can use MVC approach even without using any of these available frameowrks. This gives me ease of development of MVC and flexibility and there is almost no learning curve. It seems to be an ideal situation. The Idea is this, its simple but I found it effective.
The Model Part
1. Create a forder and name is "db", "mydb" or anything else..
2. This folder will contain all the classes that interact with database.
3. Create a separate file for each of the database tables.
4. Each of these file will contain a class that will encapsulate code that gets mainly data for that table in database, this is a bit tricky as u may not always extract data from a single table only. But mostly data is from a single table , and data from other tables is use to either supplement it. For example, if you are displaying profile of a user and you have a separate table for profiles. Then you may want data from users table also, but actually because you are diplaying the profile, the file created for profiles table should contain this code. These files will represent the Model part of your app.
The Controller part
5. Create a separate folder for each of the tables in your data base
6. In each of these folder create again a seaparate folder for each of the action u will perform, for example, if you are to edit a post , and you have a posts table in your database , you should create a posts folder in that folder you create a 'edit' folder. The index file of this folder will contain the code for the editing of post.
The View Part
7. In the folder you creates for each of the actions to perform, create a PHP file that contains the Veiw , i.e. that contains HTML, JS, or forms, everything else that describes the view of your page. This file will be included by the index file in the same folder when required.
Example:-
1. Three tables/entities in the application "Post" "User" "Profile"
Actions on user
1. Login
2. Logout
3. Register
Actions on Post
1. Add
2. Edit
3. View
4. Delete
Actions on Profile
1. Create
2. Edit
3. View
the file structure would be like this
/|+-----DB
| | // --- Models ----//
| |--posts.php
| |--users.php
| |--profiles.php
|
|
|+-----POSTS
| |
| |+-----ADD
| | |
| | |--index.php
| | | --posts_add_view.php
| |
| |+-----EDIT
| | |
| | |--index.php
| | | --posts_edit_view.php
| |
| |+-----VIEW
| | |
| | |--index.php
| | | --posts_view_view.php
| |
| |+-----DELETE
| |
| |--index.php
| | --posts_delete_view.php
|
|
|
+-----USERS
| |
| |+-----LOGIN
| | |
| | |--index.php
| | | --users_login_view.php
| |
| |+-----LOGOUT
| | |
| | |--index.php
| | | --users_logout_view.php
| |
| |+-----REGISTER
| |
| |--index.php
| | --users_register_view.php
|
|
+-----PROFILES
|
|+-----CREATE
| |
| |--index.php
| | --profiles_create_view.php
|
|+-----EDIT
| |
| |--index.php
| | --profiles_edit_view.php
|
|+-----VIEW
|
|--index.php
| --profiles_view_view.php
No comments:
Post a Comment