FATFREE-F3 Small PHP Framework (2)

Source: Internet
Author: User
Tags php framework
FATFREE-F3 Small PHP Framework (ii)

Our first example is not too difficult to understand, but if you want to do more functions and requirements, we need to add some other routes before $F3-a run ():

$f 3->route (' get/about ',    function () {        echo ' donations go to a local charity ... us! ';    });
If you don't want to make the global naming mess, Fatfree has different ways of mapping routes to manage object-oriented classes and methods:

Class Webpage {    function display () {        echo ' I cannot object to an object ';    }} $f 3->route (' get/about ', ' webpage->display ');


The requirements for HTTP can also be routed to static class functions:

$f 3->route (' Get/login ', ' auth::login ');



Routes and Symbols:

As a powerful special domain language such as fatfree, you can specify a single routing area to control different situations:

$f 3->route (' GET [email protected] ',    function ($f 3) {        echo $f 3->get (' Params.count '). ' Bottles of beer on The wall ';    });
[Email protected],[email protected]rew/98 ([email protected] value is 98) or/brew/99, then this 98 will be assigned value [email protected], Call funtion to output "98 bottles of beer on the wall".

In addition to the numbers, [email protected], such as/brew/unbreakable, then output "unbreakable bottles of beer on the wall".

There's another trick:

$f 3->route (' GET [email protected] ',    function ($f 3, $params) {        echo $params [' count ']. ' Cars. ';    });

There is also a way to replace any unimportant information with "*", for example:
$f 3->route (' get/car/* ',    function () {        echo ' We have enough cars. ';    });
is whatever you enter in/car/#$#%#@$#@[email protected]


If you want to change the method to go to other pages, we can use this trick:

$f 3->route (' get| Head/go_google ',    function ($f 3) {        $f 3->reroute (' http://www.google.com ');    });

This means you can jump to the page by typing Http://localhost/go_google. (Note that these are defined in the index.php, after entering the folder will automatically search for the route in index, will automatically identify whether the route or folder, do not worry)

Reroute method is to jump page use, and the front colleague used to get and head requirements, in addition to a post, this can understand their differences.


To name a route:

When you define a route, you can give the route a name. You can replace the type of the URL with the name and template in the middle of the code. If you want to do this, define the name of the route in the same way you define the route, for example

$f3->route('GET @beer_list: /beer', 'Beer->list');
Also note that the name of the route must be in PHP's naming convention. This example shows [email protected]??。

Then call the time to use the name of the exclusive array alisases, see an example of a call

 href="[email protected]_list}}">view beer list>

(a href is the meaning of hyperlinks, you can see the use of HTML)

Of course, this usage can also be used to jump pages, such as the reroute function that you just learned:

$f3->reroute([email protected]_list'); // note the single quotes

Instead of jumping to Google this time, jump to the "/beer" page.

At the same time, the overloaded functions we use are also suitable for this case, for example:

$f 3 -Route(' GET @beer_list: [email protected] ', ' Beer->bycountry ');$f 3 -Route(' GET @beer_list: [email protected][email protected] ', ' Beer->byvillage ');//A set of key-value pairs is passed as argument to named Route$f 3 -Reroute([Email protected]_list (@country =germany) ');//If more than one token needed$f 3 -Reroute([Email protected]_list (@country =germany, @village =rhine) ');

[Email protected]_list This variable overload, of course, the call is Bycountry and byvillage two different functions, and then according to the difference between the two methods to give the parameters, [email protected][email Protected],[email protected] The fruit to two, nature is to call the following one.








1 floor Modiziri yesterday 10:19
nn
  • 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.