我正在關注的PHP模板實例https://stackoverflow.com/questions/62617/whats-the-best-way-to-separate-php-code-and-htmlPHP:可變擴展
我的模板不解的是:
class ViewTemplate {
private $args;
private $file;
public function __get($name) {
return $this->args[$name];
}
public function __construct($file, $args = array()) {
$this->file = $file;
$this->args = $args;
}
public function render() {
include $this->file;
}
}
我使用的是這樣的:
$event = "calendar";
$view = new ViewTemplate('views/main.php', array(
'topNav' => new ViewTemplate('views/topNav.php', array('login' => $login)),
'leftPane' => new ViewTemplate('views/leftPane.php', array('login' => $login)),
'mainContentNav' => new ViewTemplate('views/mainContentNav.php', array('login' => $login, 'event' => $event)),
'mainContent' => new ViewTemplate('views/mainContent/' + $event + '.php', array('login' => $login, 'event' => $event)),
'footer' => new ViewTemplate('views/footer.php', array('login' => $login))
));
我'm getting:
[12-Apr-2013 21:33:42 UTC] PHP Warning: include(0): failed to open stream: No such file or directory in C:\Users\Owner\PhpstormProjects\CRM\admin\classes\Lifestyle\ViewTemplate.php on line 23
[12-Apr-2013 21:33:42 UTC] PHP Warning: include(): Failed opening '0' for inclusion (include_path='C:\Users\Owner\wamp\bin\php\php5.3.13\pear;C:\Users\Owner\PhpstormProjects\CRM\admin\classes\Lifestyle\classes') in C:\Users\Owner\PhpstormProjects\CRM\admin\classes\Lifestyle\ViewTemplate.php on line 23
這個問題似乎是以下位,在那裏我初始化數組:
'mainContent' => new ViewTemplate('views/mainContent/' + $event + '.php', array('login' => $login, 'event' => $event)),
如果我更改到:
'mainContent' => new ViewTemplate('views/mainContent/calendar.php', array('login' => $login, 'event' => $event)),
然後,它的工作原理,但它剝奪了我的動態使用我想要的情況。
什麼給?
的意見/搜索Maincontent /「+ $事件+名 '.php'= 0 –
PHP JavaScript不。 http://php.net/language.operators.string - 對於一般的指導,請參閱:[?參考 - 這是什麼符號意味着PHP(http://stackoverflow.com/q/3737139/2261774) –