小弟最近自己写了个mvc框架基本代码如下单一入口index.php:
<?php
require_once("init.php");
require_once("controllers/index.php");
$Action = new $index();
$Action->$indexAction();
?>init.php
<?php
session_start();//不都是require_once吗。那是不是说整个程序的session都启动了。
?>test.php
<?php
sesstion_start();
$_session['test'];//模拟给session赋值
?>controllers/index.php
<?php
class index{
function indexAction(){
echo $_session['test'];//这里获取不到session值。我在这个页面的任何地方加sesstion_start()都不行
}
}
?>test2.php
<?php
sesstion_start();
echo $_session['test'];//这里就能显示,证明session已经有值了,只不过我在类中调不出来
?>
以上就是我遇到的问题,万望各位前辈给我指点个明路。要不这个十一都过不踏实谢谢了
<?php
require_once("init.php");
require_once("controllers/index.php");
$Action = new $index();
$Action->$indexAction();
?>init.php
<?php
session_start();//不都是require_once吗。那是不是说整个程序的session都启动了。
?>test.php
<?php
sesstion_start();
$_session['test'];//模拟给session赋值
?>controllers/index.php
<?php
class index{
function indexAction(){
echo $_session['test'];//这里获取不到session值。我在这个页面的任何地方加sesstion_start()都不行
}
}
?>test2.php
<?php
sesstion_start();
echo $_session['test'];//这里就能显示,证明session已经有值了,只不过我在类中调不出来
?>
以上就是我遇到的问题,万望各位前辈给我指点个明路。要不这个十一都过不踏实谢谢了
而是 $_SESSIONphp 的变量是大小写敏感的
$index()是什么没见过这么写的一个变量+()奇怪啊
这东西都我手误了。。本地程序里是没有问题的。
我是想知道我样在
index.php里边require_once('init.php'),而init.php里有session_start(),能否影响到全局。现在看来是否定的。我想知道解决方法。
controllers/index.php
<?php
class index{
function indexAction(){
echo $_session['test'];//这里获取不到session值。我在这个页面的任何地方加sesstion_start()都不行
}
}
?>在controllers/index.php中自定义的一个类
但需要传参数时,这个方法就得挂了。
建议使用 call_user_func_array() 来调用吧。
class A {}
$index = 'A';
$a = new $index();
why?
class A {
function __construct($str) {
echo $str;
}
}
$index = 'A';
$a = new $index('asdasdasd');
index.php中
$Action = new $index();
应该为
$Action = new index();test.php和test2.php中
sesstion_start();
应该为
session_start();这几个都是我刚才着急发帖手误打错了。。大家不要揪着这几个问题不放。谢谢了
这没赋值吧 $_session['test']=‘test;
<?php
require_once("init.php");
require_once("controllers/index.php");
$Action = new index();
$Action->indexAction();
?>init.php
<?php
session_start();//不都是require_once吗。当然整个程序的session都启动了。
?>controllers/index.php
<?php
class index{
function indexAction(){
echo $_SESSION['test'];
}
}
?>
test.php
<?php
sesstion_start();
$_SESSION['test'] = 'test';//模拟给session赋值
?>
所以这个方法只能确定方法的参数。
一般都会使用 call_user_func_array()来实现的。例如 CI 框架就是了。
function包function的层模式的.这样要传递全局变量的... //带入全局变量
foreach ($GLOBALS as $k=>$v) {
global $$k;
}