view為空,輸出不了,為什么?
index.php
require_once('function.php');
require_once('config.php');
//對(duì)smarty初始化
$view=ORG('Smarty/','Smarty',$viewconfig);
//設(shè)置允許的控制器名和方法名數(shù)組
$controllerAllow=array('test','index');
$methodAllow=array('test','index','show');
//in_array函數(shù)作用:判斷一下這個(gè)字符串是否存在于字符串里
$controller=in_array($_GET['controller'],$controllerAllow)?daddslashes($_GET['controller']):'index';
$method=in_array($_GET['method'],$methodAllow)?daddslashes($_GET['method']):'index';
C($controller,$method);
testController
class testController{
function show(){
global $view;
$testModel = M('test');
$data=$testModel->get();
var_dump($view);
$view->assign('str','哈哈哈');
$view->display('test.tpl');
}
}
提示出錯(cuò):Call to a member function assign() on a non-object
2016-12-09
說(shuō)的是你調(diào)用成員方法assign()的這個(gè)$view不是一個(gè)對(duì)象!
2017-08-09
$view是從function.php實(shí)例化smarty類(lèi)返回的對(duì)象,
2017-04-01
好吧,困擾了這么久突然解決了,是function.php,前面好像是照著老師的視頻抄代碼,在function里多調(diào)用了一次大C函數(shù),所以導(dǎo)致了兩個(gè)輸出結(jié)果,還有是在Smarty實(shí)例函數(shù)之前調(diào)用,所以后面的global沒(méi)有生效。
2017-04-01
問(wèn)題解決了嗎?我也遇到了這個(gè)問(wèn)題,在控制器里global的$view變量是null的,但是在入口文件index.php里實(shí)例化的smarty對(duì)象是有效的。
2016-12-09
說(shuō)明你實(shí)例化Smarty的時(shí)候有問(wèn)題