Provides various official and user-released code examples and code reference. You are welcome to exchange and learn how to dynamically reference the File include to support variable parsing.
Today, the instance uses a method that requires dynamic include files, but thinkPHP does not support dynamic parsing.
.
Use Cases: After a user logs on, different display pages are called based on different levels. Therefore, files need to be dynamically introduced. thinkPHP does not support dynamic introduction, so you have to find a solution.
How should I use it?
:
The above is the file corresponding to the database.
The next step is to call different levels and different menu files after the user successfully logs on, such as menu1.tpl or menu2.tpl.
But thinkPHP does not support dynamic reference. What should I do?
My personal solution:
Figure:
Now, where does the level come from? Is injected in controller
See the figure below:
In order to give you a better understanding, I posted the data stored in the session for you to see: It is not clear what is going on
You need to modify \ ThinkPHP \ Library \ Think \ Template. class. php to correspond to the parseInclude () method: specific modification:
Edit: \ ThinkPHP \ Library \ Think \ Template. class. php Code as follows:
Protected function parseInclude ($ content, $ extend = true ){
// Resolution inheritance
If ($ extend)
$ Content = $ this-> parseExtend ($ content );
// Parse the Layout
$ Content = $ this-> parseLayout ($ content );
$ Begin = $ this-> config ['taglib _ in in'];
$ End = $ this-> config ['taglib _ end'];
// Read the include tag in the template
$ Find = preg_match_all ('/'. $ begin. 'include \ s (. + ?) \ S *? \/'. $ End.'/is ', $ content, $ matches );
If ($ find ){
For ($ I = 0; $ I <$ find; $ I ++ ){
$ Include = $ matches [1] [$ I];
$ Array = $ this-> parseXmlAttrs ($ include );
$ File = $ array ['file'];
// $ View = Think: instance ('Think \ view ');
/*
* Explanation
* ThinkPHP cannot dynamically include files.
* Here we need to make some adjustments.
* Check whether append exists.
***/
If (isset ($ array ['append']) {
If (isset ($ array [isvar]) & $ array [isvar] = "true "){
$ Append = $ this-> get ($ array ['append']);
Unset ($ array ['isvar']);
} Else {
$ Append = $ array ['append'];
}
$ File = $ file. $ append;
Unset ($ array ['append']);
}
If (isset ($ array ['replace ']) {
If (isset ($ array [isVar]) & $ array [isVar] = "true "){
$ File = $ this-> get ($ array ['replace ']);
Unset ($ array ['isvar']);
} Else {
$ File = $ array ['replace '];
}
Unset ($ array ['replace ']);
}
Unset ($ array ['file']);
$ Content = str_replace ($ matches [0] [$ I], $ this-> parseIncludeItem ($ file, $ array, $ extend), $ content );
}
}
Return $ content;
}
A friend who needs to take it away !!!!!!!!!!!
Another approach: http://www.thinkphp1.cn/code/1261.html
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB