我的页面里出现了如下警告信息,说我没有定义:
Notice: Undefined variable: navs in D:\wamp\www\phpweb\index.php on line 29Notice: Undefined variable: news in D:\wamp\www\phpweb\index.php on line 39Notice: Undefined variable: anno in D:\wamp\www\phpweb\index.php on line 48Notice: Undefined variable: flink in D:\wamp\www\phpweb\index.php on line 57Notice: Undefined index: username in D:\wamp\www\phpweb\index.php on line 60Notice: Undefined variable: username in D:\wamp\www\phpweb\index.php on line 66
对应的源码行如下:$template->assign("navs",$navs);
$template->assign("news",$news);
$template->assign("anno",$anno);
$template->assign("flink",$flink);
$is_login = $_COOKIE['username'] ? 1 : 0;
$template->assign("username",$username);
求高手指点,我在保证功能的前提下应该怎样修改呢?php不是不用定义的吗,怎么出现这问题?
Notice: Undefined variable: navs in D:\wamp\www\phpweb\index.php on line 29Notice: Undefined variable: news in D:\wamp\www\phpweb\index.php on line 39Notice: Undefined variable: anno in D:\wamp\www\phpweb\index.php on line 48Notice: Undefined variable: flink in D:\wamp\www\phpweb\index.php on line 57Notice: Undefined index: username in D:\wamp\www\phpweb\index.php on line 60Notice: Undefined variable: username in D:\wamp\www\phpweb\index.php on line 66
对应的源码行如下:$template->assign("navs",$navs);
$template->assign("news",$news);
$template->assign("anno",$anno);
$template->assign("flink",$flink);
$is_login = $_COOKIE['username'] ? 1 : 0;
$template->assign("username",$username);
求高手指点,我在保证功能的前提下应该怎样修改呢?php不是不用定义的吗,怎么出现这问题?
,你的这个原因是没有先定义变量,也可以先定义变量
php.ini 配置文件下的信息
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
$template->assign("navs",$navs);
$template->assign("news",$news);
$template->assign("anno",$anno);
$template->assign("flink",$flink);
$template->assign("username",$username);
是告诉你那些变量没有定义,也就是说:你的页面将什么都不显示。这不是你需要的效果吧?对于
$is_login = $_COOKIE['username'] ? 1 : 0;
应写作
$is_login = isset($_COOKIE['username']) ? 1 : 0;
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
这样做实际是在掩耳盗铃,问题依然存在.
这样修改之后就算你的本机不报错了,但是如果服务器没有这么设置结果还是报错.
所以我建议的方法是:
Notice: Undefined variable: navs in D:\wamp\www\phpweb\index.php on line 29
既然他说你的变量没有定义,那么你只要给变量定义一下就好了.
$navs='';这样简单的一行就ok了,就不报错了.
作为模版传值?它毫无意义,毫无价值可言!看不懂,你至少得让它有用途吧?那就该在前面定义这个函数的意义,让php明白该让它做什么.....
$a+=$i;
}
尽管php不需要定义变量,但是上边的代码是错误的,应该改成
$a=0;
for($i=0;$i<10;$i++){
$a+=$i;
}
所以由此可见,适当的定义变量是没有坏处的,会给你少带来很多麻烦.