fleaphp Development Guide-3. Application Portal

Source: Internet
Author: User
Tags implement php file php and
Program | Development Guide

Like many development frameworks, fleaphp typically uses a portal file to start the framework and run application code. Although fleaphp does not require the application to use a single portal file, I spend most of my time using a single entry file in this series of articles.


Single entry Application

When the fleaphp application uses the MVC pattern, all the functionality of the application is invoked through a single file. This application, which performs all functions through a single file, is called a single entry application. For information about a single entry application, refer to a post on Chinaunix.

Many well-known PHP applications are a single entry, such as Drupal, WordPress, XOOPS, Mambo, and so on. There are, of course, phpmyadmin applications like this one.


Create a portal file

Now, let's create one of the simplest entry files. Open a text editor and create a htdocs\index.php file that reads as follows:

<?phprequire('FLEA/FLEA.php');run();?>

Now start the browser, enter the address: http://localhost/index.php, you should be able to see the following screen:

This screen shows an error message, but it also indicates that two lines of code in index.php have successfully started the fleaphp framework.


To implement our first controller

In an fleaphp application, the application contains more than one controller. Each controller also provides a set of controller actions (hereafter and in this series of articles are referred to as "actions"). Each browser sends a request to the fleaphp application, which is handled by an action. A controller is formed by centralizing a set of related actions together.

Now we're going to implement the first controller:

Create the Htdocs\app\controller directory and create the file htdocs\app\controller\default.php (note that strictly matches the case of the directory name and filename), as follows:

<?phpclass Controller_Default{    function actionIndex() {        echo "My first controller.";    }}?>

At the same time modify the index.php entry file to read:

<?phprequire('FLEA/FLEA.php');import(dirname(__FILE__) . '/APP');run();?>

Now switch to the browser, click the "Refresh" button, you can see the default.php file in the Actionindex method correctly executed.

As you can see from just this example, each controller is actually a class, and an action is a method of that class.


Add more actions

Now let's add more Action methods for this controller:

<?phpclass Controller_Default{    function actionIndex() {        echo "My first controller.";    }    function actionSay() {        echo "Oh, FleaPHP great!";    }}?>

Switch to the browser, change the browse address from http://localhost/index.php to Http://localhost/index.php?action=say and press ENTER. You can see that the output has changed.

Thus, the value of the action parameter determines which action method to invoke in the controller. In the above example, when Action=say, the action method invoked is Actionsay. Because the fleaphp default requires that each action method must prefix the action. If you do not supply an action parameter, the action method named Index Actionindex () is invoked.


To implement more controllers

Create a new file htdocs\app\controller\book.php and enter the content:

<?phpclass Controller_Book{    function actionIndex() {        echo "Book controller default action.";    }    function actionSayTitle() {        echo h("<< Boost up with FleaPHP >>");    }}?>

Now switch to the browser, enter the address Http://localhost/index.php?controller=Book&action=sayTitle, and press ENTER. You can see that we have successfully invoked another controller's action method.

similar to the action that you specify to invoke with the action parameter, you can specify the controller to invoke with the controller parameter. The action parameter specifies the actions of the controller.



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.