PHP question [urgent] [urgent] [urgent] [urgent] Please help me with template assignment
The final page code is as follows:
Assign ("show", 'success '); $ show = '000000'; include ('Templates/index.html '); ==================================== if you write this code in this way, $ show can be assigned a value // include ('F: /AppServ/www/temp/tpl/com_index.html.php '); // $ tpl-> compile('index.html '); ================================ in this case, $ show cannot be assigned a value?>
Index.html brief code: output a variable as follows
The problem is as follows:
Include (the first code block above) include ('Templates/index.html ') directly on this page. if a value is assigned successfully, the $ show value can be output.
A simple template core function $ tpl-> compile('index.html ') is written. the following statements cannot be used to assign values to relative absolute paths. [the following code changes compile to absolute ], in addition, the two referenced paths are exactly the same [not absolutely], so it is difficult to make it happen !!! I don't know if GLOBAL is involved. please explain it online!
Function compile ($ fileName) {$ ducument_root = $ _ SERVER ['document _ root']; $ tplFile = $ ducument_root. $ this-> template_dir. $ fileName; // find the template file if (! File_exists ($ tplFile) {return false;} $ comFile = $ ducument_root. $ this-> compile_dir. 'com _'. basename ($ tplFile ). '. php '; // Construct the compiled file if (! File_exists ($ comFile) | filemtime ($ comFile)
Tpl_replace (file_get_contents ($ tplFile); // Obtain the source file content and replace it with the php source format $ handle = fopen ($ comFile, 'W + '); fwrite ($ handle, $ repContent); fclose ($ handle);} include ($ comFile );}
Reply to discussion (solution)
How did you write your KSeeing: assign method?
Generally
$ Tpl-> assign ("show", 'success ');
Is to assign 'success' to the show attribute of $ tpl, usually there is a carrier
So it may be like this $ tpl-> data ['show'] = 'success ';
In your template
Therefore, the compile method should be
extract($this->data);include($comFile);
How did you write your KSeeing: assign method?
Generally
$ Tpl-> assign ("show", 'success ');
Is to assign 'success' to the show attribute of $ tpl, usually there is a carrier
So it may be like this $ tpl-> data ['show'] = 'success ';
In your template
Therefore, the compile method should be
extract($this->data);include($comFile);
Moderator, compile, has a regular expression here, so I wrote a variable $ show = '000000' on The Ultimate page '; check whether the output is normal. it should be $ tpl-> assign ("show", 'success ');
Function assign ($ tpl_var, $ value = null ){
If ($ tpl_var! = ''){
$ This-> vars [$ tpl_var] = $ value;
}
}
The problem is very difficult. the specific situation is as follows:
This is the ultimate page
assign("show",'success'); //$show = '111'; include('templates/index.html'); //include('F:/AppServ/www/temp/tpl/com_index.html.php'); $tpl->compile('index.html');?>
The current Ultimate page can output success normally. this is okay, and I will make some modifications.
compile('index.html');?>
In this example, $ show in index.html has no value. The problem is coming !!! If I change $ tpl-> compile('index.html ');
Include ('Templates/index.html !! $ Tpl-> compile('index.html '); the result is include ('Templates/index.html'); or the absolute path. why is it difficult to make it look like a page problem?
How did you write your KSeeing: assign method?
Generally
$ Tpl-> assign ("show", 'success ');
Is to assign 'success' to the show attribute of $ tpl, usually there is a carrier
So it may be like this $ tpl-> data ['show'] = 'success ';
In your template
Therefore, the compile method should be
extract($this->data);include($comFile);
========================================================== ========
The Ultimate page on the second floor has not been commented and modified.
assign("show",'success'); //$show = '111'; //include('templates/index.html'); //include('F:/AppServ/www/temp/tpl/com_index.html.php'); $tpl->compile('index.html');?>
So I want you to give the code of the assign method so that you can be targeted.
The metadata you cannot include in compile is that there is no variable $ show in compile.