How does smarty call the php class constant member php content: & lt ;? Phprequire (& quot; libsSmarty. class. php & quot;); classmy_class & nbsp; {constPWD & quot; gogo & quot; var $ username & quot; Deep Space & quot ;;} $ class_obj how to call a constant member of a php class
Php content:
Require ("libs/Smarty. class. php ");
Class my_class
{
Const PWD = "gogo ";
Var $ username = "deep space ";
}
$ Class_obj = new my_class;
Echo $ class_obj-> username .'
';
Echo $ class_obj: PWD .'
';
$ Smarty-> assign ('class _ obj ', $ class_obj );
$ Smarty-> display ('EG _ 4_2.tpl ');
?>
Tpl content:
{$ Class_obj-> username}
{$ Class_obj: PWD}
For $ class_obj-> username
Php and tpl are both normal...
For $ class_obj: PWD
It works normally in php.
When using tpl, an error is reported.
Thank you for your understanding!
------ Solution --------------------
You must comply with the smarty rules. Otherwise, you will be fired by smarty.
------ Solution --------------------
Http://wenku.baidu.com/view/c2aa98ef551810a6f52486af.html
------ Solution --------------------
Try my_class: PWD
Not yet.
Http://www.smarty.net/docs/en/advanced.features.static.classes.tpl
------ Solution --------------------
Pass the class name. $ Smarty-> assign ('My _ class', my_class );
Tpl call:
{Php}
Echo my_class: PWD;
{/Php}
PHP 5.3.0 can be called with $ class_obj: PWD. Earlier versions are not supported. I don't know what your php version is?
------ Solution --------------------
Still Struggling. Have you tried it in my own way? Why not?
------ Solution --------------------
I don't know what you're struggling:
PHP code
";}$ Obj = new C (); $ a = C: AAA; $ smarty-> assign (" A ", $ ); $ smarty-> assign ("str1", $ str1); $ smarty-> assign ("str2", $ str2 ); $ smarty-> display ("test.html");?>
------ Solution --------------------
I understand. But I can't do anything.
------ Solution --------------------
$ Smarty-> assign ("str1", $ str1 );
$ Smarty-> assign ("str2", $ str2 );
It is useless for testing data. delete it.
------ Solution --------------------
Understanding your needs, it is very likely that smarty has not received such requirements,
So you have not made this function. you can submit this requirement on their website,
Or write a plug-in by yourself.
Discussion
Reference:
Try my_class: PWD
Not yet.
Http://www.smarty.net/docs/en/advanced.features.static.classes.tpl
Read the link you gave
The link is about static classes.
My problem is the static member of the class...
Thank you for your answer...
------ Solution --------------------
Is there such an unreasonable demand? Flexible during development
------ Solution --------------------
Are you still struggling with this problem?
{$ Class_obj: PWD}
Translated
Tpl_vars ['class _ obj ']-> value: PWD;?>
Although
$ Class_obj = new my_class;
Echo $ class_obj-> username .'
';
Echo $ class_obj: PWD .'
';
You can get the correct result (but he is not strict)
But what about it?
$ Class_obj-> x = new my_class;
Echo $ class_obj-> x-> username .'
'; // Output deep space
Echo $ class_obj-> x: PWD .'
'; // An error is reported here:
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' in
------ Solution --------------------
I have checked the manual. only variables can pass values like this. constants cannot pass values like this !!
You can only do this:
Php: $ PWD = $ class_obj: PWD; $ smarty-> assign ("PWD", $ PWD );
Tpl: {$ PWD}
------ Solution --------------------