The confusion on the frame
This post was last edited by Muyuruhai on 2013-07-15 10:54:01
Hello everyone
The younger brother once wrote a website, uses the way as follows
index.php Home
Background logic has a PHP file that logic.php
I wrote it in logic.php.
$action =_$post[action]
Switch $action
Case Check_userlogin
Login (_$post[username],_$post[pwd]);
Case Put_comment
Put_comment (_$post[comment]);
...
End Switch
By invoking a different action in this way, the logic.php is like a common entry for all operations.
Since I recently looked at the MVC framework, although I understand the principle, it is still a bit difficult to get into it.
If you do a small project, so that switch is not suitable for the structure?
Front desk if using AJAX, generally I will call url:logic.php
Data:{action:update_commnet,commnet: "Hellow"} is similar to this
Because time is more tense, if reproduce a mvc I'm afraid it will be too late, please give some advice
Thank you, guys.
structure
Share to:
------Solution--------------------
Your way of writing is the same as the MVC route.
The difference is that you are dealing with a finite (known) method, and the MVC route can handle an infinite number of methods (increasing the method without changing the routing code)
------Solution--------------------
If the action is small, no problem, but the action is too much, it is recommended to make the choice of configuration type.
For example:
$actions = Array (
' Check_userlogin ' = ' login ',
.....
);
$action =_$post[action];
if (Isset ($actions [$action]) && function_exists ($actions [$action])) {
$actions [$action] ();
}