The doubts on the frame

Source: Internet
Author: User
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] ();
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.