Phpcms (1) phpcmsV9MVC mode and URL access parsing), phpcmsmvc_PHP tutorial-php Tutorial

Source: Internet
Author: User
Phpcms (1) phpcmsV9MVC mode and URL access parsing (forwarding), phpcmsmvc. Phpcms (1) phpcmsV9MVC pattern and URL access parsing (forwarding), phpcmsmvc [1] URL access analysis to observe the URL when accessing the webpage, you can obtain the module access method, as shown in the following example: phpcms (1) phpcms V9 MVC mode and URL access parsing (forwarding), phpcmsmvc

[1] URL access parsing

Observe the website address when accessing the webpage and obtain the module access method, as shown in the following example:

Http://www.abcd.com.cn/phpcms/index.php? M = content & c = index & a = show & id = 1

The URL is parsed as follows:

M = content: The module/model name is located in phpcms/modules/content (Required)

C = index: the controller name is in phpcms/modules/content/index. php (Required)

A = show indicates that the event name is located in the show method in phpcms/modules/content/index. php.

Id = 1 is the same as the normal get parameter.

So, the problem is coming! We often visit the home site: http://www.abcd.com.cn/phpcms/index.php why there is no m and c value?

Here, we will explain that the system will execute default modules and operations when no modules and controllers are specified. In the preceding URL, the default PHPCMS route locates the init operation in the index controller of the content module. Therefore, it is the same as the following URL results:

Http://www.abcd.com.cn/phpcms/index.php? M = content & c = index & a = init

The system also supports URL routing, which can bring other url access effects.

The route file is in phpcms \ caches \ configs \ route. php and the content is organized as follows:

1
 Array (6 * 'M' => 'phpcms ', 7 * 'C' => 'index', 8 * 'a' => 'init ', 9 * 'data' => array (10 * 'post' => array (11 * 'catid' => 112 *), 13 * 'get' => array (14 * 'contentid' => 115 *) 16 *) 17 *) 18 * where "m" is the model and "c" is the controller, "a" is an event, and "data" is another additional parameter. 19 * data is a two-dimensional array. you can set the default parameters of POST and GET. 20 * POST and GET correspond to the hyper-global variables $ _ POST and $ _ GET in PHP respectively. 21 * in the program, you can use $ _ POST ['catid'] to obtain the value of the array in POST under data. 22 * the parameter levels set in data are relatively low. If an external program submits a variable with the same name, it overwrites the value set in the configuration file. 23 * for example, if the external program POST a variable catid = 2, the value you get using $ _ POST in the program is 2, instead of 1 set in the configuration file. 24 */25 return array (26 'default' => array ('M' => 'content', 'C' => 'index ', 'A' => 'init '), 27 );

For a more specific understanding, a simple example is as follows:

1. in the phpcms/modules Directory, create a new folder named demo, that is, the module named demo.

2. in the demo folder, create a text file named test and change the file type to php. Open the test file with Notepad ++ and edit the content as follows:

1 
 

Note: the content in test. php must be written in the class format. Otherwise, the system will prompt that control cannot be found, that is, c in mvc cannot be found. If a is not specified, the init method is called. if the init method is not implemented, Action does not exist is displayed.

3. enter http: // localhost/phpcms/index. php in the URL bar of the browser? M = demo & c = test & a = show press Enter. The result is as follows:

[2] module

The module in the phpcms V9 framework is located in the phpcms/modules Directory. Each directory is called a module. M in the URL above.

To create a module, you only need to create a folder in the phpcms/modules Directory and put it in your controller class.

[3] controller

For more information about the controller class, see phpcms V9 add module.

Good Study, Day Up.

Sequential selection cycle summary

Http://www.bkjia.com/PHPjc/1137259.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1137259.htmlTechArticlephpcms (1) phpcms V9 MVC mode and URL access parsing (to), phpcmsmvc [1] URL access analysis to observe the Web site when accessing the page, you can obtain the module access method, the following example: http ://...

Related Article

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.