Thinkphp cannot read the file imported by using import.

Source: Internet
Author: User
Thinkphp has no way to read the file imported by using import ("Common. logAction ", APP_PATH ,'. php '); introduce logAction. php file, which is a multi-dimensional array with the following structure:
$ _ LANG ['log _ action'] ['add'] = 'add ';
$ _ LANG ['log _ action'] ['delete'] = 'delete ';
$ _ LANG ['log _ action'] ['edit'] = 'edit ';
$ _ LANG ['log _ action'] ['import'] = 'import ';
$ _ LANG ['log _ action'] ['sheng'] = 'generation ';
$ _ LANG ['log _ action'] ['print '] = 'print ';
$ _ LANG ['log _ action'] ['General _ ruku '] = 'regular warehouse receiving ';
$ _ LANG ['log _ action'] ['sale _ chuku '] = 'sale warehouse output ';
$ _ LANG ['log _ action'] ['check'] = 'review ';
$ _ LANG ['log _ action'] ['uncheck'] = 'cancel review ';
$ _ LANG ['log _ action'] ['batch _ check'] = 'batch Review ';

However, I cannot read the variable value of the file introduced in the function.
Function admin_log ($ sn = '', $ action, $ content)
{
// Log operations and actions
Import ("Common. logAction", APP_PATH, '. php ');
Echo $ GLOBALS ['_ LANG'] ['log _ action'] [$ action]; exit;


}

Please give me some suggestions...


Reply to discussion (solution)

Browsed the thinkphp code.
Import is a function, where require_cache is called to load files.
The file is loaded in require_cache: require $ filename;
Therefore, except for the class definition, other data declarations become private variables in the require_cache function.
Unless you declare it a global variable in the loaded file

You seem to be using multi-language support
So why not use the built-in multi-language support for ThinkPHP?

I am not using multi-language support. I am just working on a function to record operation logs. the file mentioned above is the action of some operations.

The introduced file is not a class, but a php file that stores arrays.

You just need to include
However, it is better to abide by other people's rules.
Should this file be a configuration file?

Yes, it is from the configuration file. I just defined global $ _ LANG; in the introduced file.
But I would like to ask, if there are too many global variable definitions, will it affect?

When the TP framework is not used, include is used for introduction, and global variables are not declared.

Yes, it is from the configuration file. I just defined global $ _ LANG; in the introduced file.
But I would like to ask, if there are too many global variable definitions, will it affect? Will there be too many global variable definitions?
No, but do not conflict with each other.

The configuration file should be configured in the way agreed by TP, and it will be automatically loaded

Reference babyface008 008 on the 7th floor: Yes, it is from the configuration file. I just defined global $ _ LANG in the file to be introduced.
But I would like to ask, if there are too many global variable definitions, will it affect? Will there be too many global variable definitions?
No, but do not conflict with each other.

The configuration file should be configured in the way agreed by TP, and it will be automatically loaded

Okay. thank you for reminding me.

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.