Look at the following code:

/** Define root directory * /
define ("__ typecho_root_dir__", dirname (__ file__));
/** Define plugin directory (relative path) * /
define ("__ typecho_plugin_dir__", "/usr/plugins");
/** Set include path * /
@set_include_path (get_include_path (). path_separator.
__typecho_root_dir__. "/var". path_separator.
__typecho_root_dir__. __typecho_plugin_dir__);

First of all:

Let's look at this global variable:__file__

It represents the full path of the file (including the file name, of course)

In other words, it depends on the directory where your files are located.Have different values;Of course, when it is used in a package file,Its value is the included path;


We look at this function:

string dirname (string path)

It is a php built-in function,What does it do,Is to return to the directory other than this file name,E.g:

If you use the _file_ variable in your homepage:

(Assuming your web page is in the directory:http://localhost/web/index.php), then:

The value of _file_ is http://localhost/web/index.php (an absolute path). At this time, dirname (_file_) means http://localhost/web /, that is, there is no file name index.php.

And dirname (dirname (_file_)) means the upper-level directory,And so on;

At last:

Take a look at the define () function,In fact, it is a function that defines constants.For example:define ("men", "ooooo");

Then you can use men to represent ooooo this string;

So what's the benefit of writing like this,That is when you need to modify variables,You just need to modify it,Quite convenient,Especially strings like paths!

Let's explain this code:

define ("__ typecho_root_dir__", dirname (__ file__));

Is to define __typecho_root_dir__ as the directory where this file is located,Such a definition is usually placed in config.inc.php, then the directory obtained is the directory where config.inc.php is located;That is the root directory!

define ("__ typecho_plugin_dir__", "/usr/plugins");

Needless to say!

What does set_include_path (get_include_path (). Path_separator. $Path);mean,He just contains the path;

For example, you have a folder:named include, which contains the database connection file:conn.php ...,

You set it like this:

set_include_path ("/include")

Then you can use it directly in other pages

include ("conn.php")

Don't you see this often?It takes a string,Of course you can also set multiple paths,Use in the middle;separate, and the sentence:

set_include_path (get_include_path (). path_separator.
__typecho_root_dir__. "/var". path_separator.
__typecho_root_dir__. __typecho_plugin_dir__);

What does it mean,for example:

One of your pages has this statement:

include ("/inc/sql.php");
include ("/inc/conn.php");

And you suddenly find that it is not safe for me to put the files to be included in the inc directory.What to do is to change it. I want to put it in the include directory. OK, so many pages are not tiring:it's no wonder! Have! !! !! !! !! !! !!

Is it written in config.inc.php:

set_include_path (get_include_path (). "/include")

It's that simple,Yes, it's that simple! Dynamic modification!

Don't look at this:get_include_path (). Path_separator. $Path What is this,He takes a path string,The middle. Is a string connection symbol,Is the combination of those constants just defined,Compose a string,Fortunately, this means that he can dynamically set the include path! If the include path is returned correctly,Incorrectly returns false;

  • Previous EasyUI is displayed after loading HTML content style rendering
  • Next Summary of PHP string comparison function usage (strcmp, strcasecmp, strnatcmp and strnatcasecmp)