Admin. php variable

Source: Internet
Author: User
Admin. php variables have been known by phpcms developers. phpcms provides a large number of built-in variables for us to call in templates, for example, {$ position} {$ title} represents the current position and the title of the article respectively. At the same time, we can't help but ask, why can we use these variables? Under what circumstances do these variables make sense?

In fact, we can attribute these issues to the html file generation process in phpcms. Everything starts with admin. php. different operations (such as file generation and image generation) in the background will lead to different files included in admin. php. The included object will contain different files based on the parameters passed to it, so that it can be included all the way until it is called to our template. The files passed through this road and admin. php constitute the final admin. php. The variables that we can call are the variables that have appeared in these files, which is also the criteria for determining whether the variables are available. This is not hard to understand, because our template file is eventually included in admin. php, and the variable it calls may not be in admin. php, but it is included at the moment.

The following describes how to translate custom tags in a template to explain the above content. This tag implements the "previous next article" function. the tag name is {tag _ previous article }. Click the link after generating the article: http: // 127.0.0.1/phpcms2007_sp6_gbk/phpcms/admin. php? Mod = article & file = createhtml & action = create_show & channelid = 1 & referer = *** the tag code is as follows:

1 2 defined ('in_phpcms ') or exit ('Access Denied ');
3?>
4 5 global $ articleid, $ db;
6 $ sqlpre = "SELECT * FROM phpcms_article_1 where articleid <'$ articleid' order by articleid desc ";
7 $ sqlaft = "SELECT * FROM phpcms_article_1 where articleid> '$ articleid' order by articleid asc ";
8 $ preart = $ db-> get_one ($ sqlpre );
9 $ afart = $ db-> get_one ($ sqlaft );
10 if (! $ Preart ['title'])
11 $ preart = $ db-> get_one ("select * from phpcms_article_1 order by articleid desc ");
12 if (! $ Afart ['title'])
13 $ afart = $ db-> get_one ("SELECT * FROM phpcms_article_1 where articleid = 1 ");
14 $ preurl = $ preart ['linkurl'];
15 $ afurl = $ afart ['linkurl'];
16 $ pretitle = $ preart ['title'];
17 $ aftitle = $ afart ['title'];
18 $ url = $ PHP_SCHEME. $ PHP_DOMAIN. PHPCMS_PATH;
19 echo"

  • Previous: $ pretitle
  • ";
    20 echo"
  • Next Article: $ aftitle
  • ";
    21?>

    The principle is very simple. based on the index ($ articleid) of the current page, you can use the database ($ db) to query its previous and next articles, and finally print the results on the page through echo. But how do we know the existence of $ articleid and $ db? This requires us to understand what we have done in the background after clicking "Generate article? After the command is executed, the message routing is as follows:

    Admin. php-> phpcms "module" article "admin. inc. php-> phpcms "module" article "admin" createhtml. inc. php (case 'create _ Show' :)-> golbal. func. php (createhtml)-> phpcms "module" article "include" createhtm "show. php

    The message is routed to this file through:

    Ob_start ();
    Include template ($ mod, $ templateid );
    $ Data = ob_get_contents ();
    Ob_clean ();

    File_put_contents ($ filename, $ data); creates and writes html files. If you go deeper, you can find that template () calls template_refresh (), while template_refresh () calls template_parse () to explain the phpcms tag and translate it to PHP only.

    Then the template () function is returned and is output to the browser buffer (opened by ob_start (). It is the same as being output to the screen, in this case, the embedded PHP in the file will be translated into html format. For a custom tag, it is translated Therefore, the phpcms_mytag () function is called during output. This function is used to include the final custom tag file. In this way, the custom tag file is combined with the file containing $ articleid and $ db. Therefore, you can use these two variables in the custom tag file.

    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.