The confusion on the frame

Source: Internet
Author: User
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.



Reply to discussion (solution)

No one replied, is it my wrong way of asking questions?

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)

No one replied, is it my wrong way of asking questions?

That's the way it is, I'm using this pattern, too.
Does the landlord have any doubts about this way?

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] ();
}

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)

So, no wonder I want to define a lot of action every time need a case more one, really gave away, thank you, but small project routing is not a lot of things.
And I'm writing my own template frame in the background. A template file EoT inside, without using a templating engine

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] ();
}

Well, it's interesting, but small project action should not be too much, but it seems to be very good, the action will correspond to each function name is good, thank you for pointing
Because the hatacees is not very familiar with, see CI and yii swap used to call to feel a bit messy, so there is this problem

Agreed to answer the upstairs few.

Since rails has been successful, all frameworks follow one idea: Conventions are larger than configurations.

Try to use the agreed rules instead of the active configuration. This will make the code more extensible and will further reduce the subsequent maintenance effort.

I'm using the If ElseIf.

  • 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.