F3-fatfree Small PHP Framework Course (III)

Source: Internet
Author: User
F3-fatfree Small PHP Framework Tutorial (III)

Before saying a lot of routing settings and use, here first of all to say how to set the root directory (so-called root directory is localhost directory)

In general when installing Apache will have a default directory, if you want to change can use this command:

php -S localhost:80 -t /var/www/
and then you'll automatically go inside the index.php and find something. (Automatically identify whether it is a route or a folder)


Then go back to the reroute function, this function is a jump page for use, and there is a special purpose, will not show the source page! Other words:

$f 3 -Route(' get| Head/obsoletepage ',    function($f 3) {        $f 3 -Reroute('http://www.anotherexample.org/');    });
in the browser address bar is displayed "/obsoletepage" instead of the real address "http://www.anotherexample.org/", that is, can play the role of hidden address. Can not let the user know that they are actually access to the real address, can be used to rob the amount of traffic and so on. There are some bad ideas oh ~ this to think about it ~


Also note that if I want to pass a parameter GET [email protected],[email protected]?, but the system will also default parameters are empty, then

We need to write some error mechanisms ourselves.

$f3->error(404);

F3 has a good automatic reading mechanism that will help you read classes when you need them, and you don't have to write a bunch of include or required to read different folders and different files of PHP. The party will help you out with this problem. You just have to save the file in the folder and once you want to invoke the method in the object, you just tell the frame to automatically read the appropriate file:

$f3->set('AUTOLOAD','autoload/');
This set function has two parameters, the previous one is the definition of ' AUTOLOAD ' stating that what I am going to do is to automatically read (the Set function is very hanging, will continue to explain the other functions), and then automatically read the directory is ' autoload/' equivalent to this time you have entered this directory.

You can also set multiple automatic paths.

 $f 3  ->  set  ( ' AUTOLOAD ' ,  admin/autoload/; user/autoload/; default/' );   
here again, the name and file name of the class must be the same so that autoload can read from the file to the class. And F3 is not case-sensitive, so it is best not to use folders and files of the same name.


Let's talk about how to read a path file:

Join me to read is the /var/www/html/autoload/gadgets/ipad.php

First we define the root directory to be/var/www/html/, and then

$f3->set('AUTOLOAD','autoload/');$obj=new Gadgets\iPad;

And the definition in the file is:

namespace Gadgets;class iPad {}

Inside the gadgets nature is the same as the path, mainly to facilitate autoload to identify, after all, the framework is not case-sensitive. Also note that these paths have to be slash/end:

$f3->set('AUTOLOAD','main/;aux/');
before I talk about this concept, I want to talk about static and dynamic functions:

static function: The end of the program will disappear, always occupy memory waiting for the call, do not need to instantiate the class can be used.

Dynamic functions: Dynamically loaded into memory, automatically free when not needed, but must first be new to be called in a class.

The literal understanding is that if you just use this function and are often used, with static, if you want the entire class of functions to involve calls, the dynamic


Continue to say:

How are static and dynamic methods in the F3 called?

Static:

 $f 3  ->  set  ( ' AUTOLOAD ' ,  ' classes/' );    $f 3  ->  route  ( "get| POST/' ,  ' main\home::show ' );  
Dynamic:

 $f 3  ->  route  (" get| POST/' ,  ' main\home->show ' ) ;
classes/main/home.php are inside there is a namespace called Main, this is not detailed said. This is the dynamic static call to the show function.

























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