Code in the controller:
Public Function Testt () {
$title = "Practice book";
$content = '
'. $_get[' name '];
$this->assign (' title ', $title);
$User = M (' name ');
$list = $User->select ();
$this->assign (' list ', $list);
$this->assign ("title", "Smarty Test");
$this->display ();
}
Code in the template:
{$title}
{$vo. Age} {$vo. Name}
Important to remove the foreach part is normal, otherwise it will appear like this
Syntax error, unexpected ') ', expecting t_variable or ' $ ' D:\AppServ\www\App\admin\Runtime\Cache\ 6e178638460c8ba2282739c247c2ce14.php Line 10th.
The code in the cache file is:
$): Echo ($vo ["age"]); Echo ($vo ["name"]);?>
It seems a long time no clue, how to do ah?
Reply to discussion (solution)
The list is empty, you're checking it yourself.
List is empty, in the controller can find data, but to the template, through the foreach tag function after processing becomes empty. Do not know where the error?????????????????????????????????????????????????????
Public Function _foreach ($attr, $content) { static $_iterateparsecache = Array (); If it has already been parsed, return the variable value directly $cacheIterateId = MD5 ($attr. $content); if (Isset ($_iterateparsecache[$cacheIterateId])) return $_iterateparsecache[$cacheIterateId]; $tag = $this->parsexmlattr ($attr, ' foreach '); $name = $tag [' name ']; $item = $tag [' item ']; $key = !empty ($tag [' key '])? $tag [' Key ']: ' key '; $name = $this->autobuildvar ($name); $parseStr = '
$ '. $item. '):?> '; $parseStr . = $this->tpl->parse ($content); $parseStr . = '
; $_iterateparsecache[$cacheIterateId] = $parseStr; if (!empty ($PARSESTR)) { return $parseStr; } return; }
Slightly check the source of the parsing foreach tag, this is not a list variable is empty, in fact, is not taken to the label name and item value, the specific reason landlord can check the source of their own exclusion, of course, the simplest solution is to use volist tags.
Should the foreach in your template be written as {foreach name= ' item= '}?
Public Function _foreach ($attr, $content) { static $_iterateparsecache = Array (); If it has already been parsed, return the variable value directly $cacheIterateId = MD5 ($attr. $content); if (Isset ($_iterateparsecache[$cacheIterateId])) return $_iterateparsecache[$cacheIterateId]; $tag = $this->parsexmlattr ($attr, ' foreach '); $name = $tag [' name ']; $item = $tag [' item ']; $key = !empty ($tag [' key '])? $tag [' Key ']: ' key '; $name = $this->autobuildvar ($name); $parseStr = '
$ '. $item. '):?> '; $parseStr . = $this->tpl->parse ($content); $parseStr . = '
; $_iterateparsecache[$cacheIterateId] = $parseStr; if (!empty ($PARSESTR)) { return $parseStr; } return; }
Slightly check the source of the parsing foreach tag, this is not a list variable is empty, in fact, is not taken to the label name and item value, the specific reason landlord can check the source of their own exclusion, of course, the simplest solution is to use volist tags.
I saw is $this->parsexmlattr ($attr, ' foreach ') after the execution $tag no value???????????????????????????
What to do, I wrote the simplest of a few lines of code,
Results in the source code is the PARSEXMLATTR function inside the problem. But will it be the source of the problem?
What to do, I wrote the simplest of a few lines of code,
Results in the source code is the PARSEXMLATTR function inside the problem. But will it be the source of the problem?
Public Function parsexmlattr ($attr, $tag) {//xml resolves security filtering $attr = Str_replace (' & ', ' ___ ', $attr); $xml = '
'; $xml = simplexml_load_string ($xml); if (! $xml) {throw_exception (L (' _xml_tag_error_ '). ': '. $attr); } $xml = (array) ($xml->tag->attributes ()); $array = Array_change_key_case ($xml [' @attributes ']); if ($array) {$attrs = explode (', ', $this->tags[strtolower ($tag)] [' attr ']); if (Isset ($this->tags[strtolower ($tag) [' must '])) {$must = explode (', ', $this->tags[strtolower ($tag ) [' must ']); }else{$must = Array (); } foreach ($attrs as $name) {if (Isset ($array [$name])) {$array [$name] = Str_ Replace (' ___ ', ' & ', $array [$name]); }elseif (False!== Array_search ($name, $must)) {throw_exception (L (' _param_error_ '). ': '. $name); }} return $array; } }
Then look at the source code is not good, not clear variables on the printing, it is easy to find out the problem, the source code has errors is not a strange thing, it may be written in a wrong format.
What to do, I wrote the simplest of a few lines of code,
Results in the source code is the PARSEXMLATTR function inside the problem. But will it be the source of the problem?
Public Function parsexmlattr ($attr, $tag) {//xml resolves security filtering $attr = Str_replace (' & ', ' ___ ', $attr); $xml = '
'; $xml = simplexml_load_string ($xml); if (! $xml) {throw_exception (L (' _xml_tag_error_ '). ': '. $attr); } $xml = (array) ($xml->tag->attributes ()); $array = Array_change_key_case ($xml [' @attributes ']); if ($array) {$attrs = explode (', ', $this->tags[strtolower ($tag)] [' attr ']); if (Isset ($this->tags[strtolower ($tag) [' must '])) {$must = explode (', ', $this->tags[strtolower ($tag ) [' must ']); }else{$must = Array (); } foreach ($attrs as $name) {if (Isset ($array [$name])) {$array [$name] = Str_ Replace (' ___ ', ' & ', $array [$name]); }elseif (False!== Array_search ($name, $must)) {throw_exception (L (' _param_error_ '). ': '. $name); }} return $array; } }
Then look at the source code is not good, not clear variables on the printing, it is easy to find out the problem, the source code has errors is not a strange thing, it may be written in a wrong format.
The array passed to the template within the controller is $select=array (' id ' =>1, ' name ' = ' Yan ');
In the foreach tag processing is the function inside it parsexmlattr ($attr, $tag) This sentence
$xml = (array) ($xml->tag->attributes ()); The resulting $xml is an array (0) {}
After he has processed it, it becomes an empty array, and the function does not return data.
Is this step. It's a bit of a contrast to your hair. The source code is like this ah, in the end that good ah?????????
Public Function _foreach ($attr, $content) { static $_iterateparsecache = Array (); If it has already been parsed, return the variable value directly $cacheIterateId = MD5 ($attr. $content); if (Isset ($_iterateparsecache[$cacheIterateId])) return $_iterateparsecache[$cacheIterateId]; $tag = $this->parsexmlattr ($attr, ' foreach '); $name = $tag [' name ']; $item = $tag [' item ']; $key = !empty ($tag [' key '])? $tag [' Key ']: ' key '; $name = $this->autobuildvar ($name); $parseStr = '
$ '. $item. '):?> '; $parseStr . = $this->tpl->parse ($content); $parseStr . = '
; $_iterateparsecache[$cacheIterateId] = $parseStr; if (!empty ($PARSESTR)) { return $parseStr; } return; }
Slightly check the source of the parsing foreach tag, this is not a list variable is empty, in fact, is not taken to the label name and item value, the specific reason landlord can check the source of their own exclusion, of course, the simplest solution is to use volist tags.
Volist and foreach also have the same for effect.
Tangled, well array, passed to the source code is processed to empty.
As mentioned above, the list array value does not change, but in the process of the template is not the correct generation of PHP code, I just downloaded a thinkphp, with the code of the landlord tried the next, the result is normal, suggest to thinkphp official online re-the latest version of the look
As mentioned above, the list array value does not change, but in the process of the template is not the correct generation of PHP code, I just downloaded a thinkphp, with the code of the landlord tried the next, the result is normal, suggest to thinkphp official online re-the latest version of the look
I downloaded the official online 3.1.3, will not be the problem of the programming platform I use eclipsephp Studio v1.2.2.
The development environment uses an integrated appserv.
Have made an afternoon, on the internet also some people say there is a bug, is parsexmlattr ($attr, $tag) in the
$xml = (array) ($xml->tag->attributes ());
Using a foreach traversal to $array, I tried to have the output array ok, but the string link in the TAGLIBCX is not the case
There is a problem with the running environment, the former used Appserv for a new one. The problem is solved. But that used to be no problem.
Why is the thinkphp label out of the question???????
PHP Environment preferably above php3.0
There is a problem with the running environment, the former used Appserv for a new one. The problem is solved. But that used to be no problem.
Why is the thinkphp label out of the question???????
Did you solve the problem? Must I change the environment? , my thinkphp is also the 3.1.3,php version is PHP6. Is this going to change again?
Solved, PHP6 not, I changed to PHP5, and then I can