A PHP namespace problem .... Very silent question .....
Just a little bit of code.
To define a subclass of inherited smarty, implement the basic path configuration in the constructor ....
namespace Smarty;
Class Smarty_test {
function SetName () {
Echo ' Name ';
}
}
Use Smarty\smarty_test;
$smarty = new Smarty_test ();
$smarty->assign (' name ', ' Ned ');
$smarty->debugging = true;
$smarty->display (' Index.tpl ');
?>
Code as above, very simple, two pieces of code of the file structure in the same directory
In this way, the operation can not find the class .....
Fatal error:class ' smarty\smarty_test ' is not found in .....
I really do not understand, I am in the thinkphp framework is also using the namespace completely no problem, how to create a new project to put a file, test it is not good or dead .... Even Zend Studio editor can show the existence of smarty_test this class, how to run the time is not,, depressed AH
------to solve the idea----------------------
Very good LLL
------to solve the idea----------------------
You did not load the file containing the Smarty_test class definition
------to solve the idea----------------------
Yes, include included in
or set automatic loading
Spl_autoload_register ();
Use Smarty\smarty_test;
$smarty = new Smarty_test ();
$smarty->assign (' name ', ' Ned ');
$smarty->debugging = true;
$smarty->display (' Index.tpl ');