还是我,刚才那个写的可能比较乱,大家没理解我意思。从新写一个,希望大家能帮我
以下是我的关键程序部分单一入口index.php:
<?php
require_once("init.php");
require_once("controllers/index.php");
$Action = new index();
$Action->indexAction();
?>init.php
<?php
session_start();//这里是不是整个程序的session都启动了。
?>controllers/index.php
<?php
class index{
 function indexAction(){
   echo "接受到的session:".$_SESSION['test'];//只输出了接受到的session:
 }
}
?>
test.php//此页面为测试页面。模拟给$_SESSION['test']赋值
<?php
session_start();
$_SESSION['test'] = 'test';//模拟给session赋值
?>test2.php//此页面为测试页面。模拟给$_SESSION['test']赋值
<?php
session_start();
echo $_SESSION['test'];//输出test。直接在页面中调用session正常。
?>
小弟的基本思路就是这样了
1)执行test.php,给$_SESSION['test']赋值
2)index.php中引用init.php,session启动
3)index.php引用controllers/index.php
4) index.php实例化一个对象index
5)index.php中调用index对象的方法indexAction()
发现能够调用成功方法,但是没有获取到$_SESSION['test']
于是新建页面test2.php测试$_SESSION['test']是否有值
在test2.php中$_SESSION['test']被获取到请问我现在如何才能在indexAction()方法中获取到$_SESSION['test']。谢谢大家了。

解决方案 »

  1.   

    哪位大虾帮我解决了
    http://topic.csdn.net/u/20100930/16/9b6f28ad-332f-4961-835b-b5f6956209b7.html
    这贴的100分也给他。谢谢了。
      

  2.   

    controllers/index.php
    <?php
    class index{
    public $str;
     function indexAction($string){
       $this->str=$string;
       echo "接受到的session:".$this->str;  
     }
    }
    ?>
    $Action = new index();
    $Action->indexAction($_SESSION('test'));
      

  3.   

    有没有在访问test.php之后再访问index.php
      

  4.   


    我现在要做个登陆,总不能把每一项要用的session都传参递过去啊根本的解决办法还是得在方法中能让session正常使用才行啊
      

  5.   

    单一入口肯定会一直访问index.php的这个有关系吗?
      

  6.   

    你第一次访问index.php   $_SESSION['test']这个还没有值
    你试下访问过test.php 再访问index.php
      

  7.   

    我先执行的test.php。然后才访问的index.php取不到值。弄的我很郁闷。
      

  8.   

    以你相同的代码 相同的路径试了没问题
    如果你的文件是utf8的 看下有没有报错  是不是多了 BOM头
      

  9.   

    我疯了
    ini_set('session.save_path', WEBSITE_ROOT.'/session');
    init中session_start()前边有这句话,我给删了就好了
    我关了浏览器从新开下试试。
      

  10.   

      你的配置有问题。我把你的代码存起来运行了,  能正常获取到。先运行test.php , 再运行index.php  ,输出为     接受到的session:test
      

  11.   

    运行test.php的时候,重新打开一个IE窗口 ,运行 index.php ...记住别把test.php关闭~~