2013-02-14 2 views
0

내 MVC 사이트에 세션 변수를 설정하여 후속 페이지에서 사용할 ID를 전달합니다.Zend_Session이 값을 전달하지 않음

내 컨트롤러에서 세션을 var_dumping하면 올바른 값으로 표시되지만,이 값을 뷰에 전달하고 거기에 에코를 표시하려고하면 빈 값이 표시됩니다.

무슨 일이 일어나고 있는지 알려주는 포인터.

보기는 일부보기가 아니라 기본보기입니다.

부트 스트랩 세션 관련 코드 :

protected function _initSession(){ 
    Zend_Session::start(); 
    $SessAuto2Auto = new Zend_Session_Namespace('SessAuto2Auto'); 

    $SessAuto2Auto->cityIds = "1,2,3"; // Hard code values for testing purposes 
    $SessAuto2Auto->IndustryIds = "3,4"; // Hard code values for testing purposes 
} 

컨트롤러 관련 코드 : ProductController.php 부분

public function indexAction() 
{ 
    // .. Unrelated code removed for brevity 

    $response = $this->getResponse(); 
    $response->insert('sidebar', $this->view->render('sidebar.phtml')); 

    // This code is dumping the values correctly 
    echo('<pre>'); 
    var_dump($this->sessionAuto2Auto); 
    echo('</pre>'); 

    // .. Unrelated code removed for brevity 

    $this->view->filterCity = $this->sessionAuto2Auto['cityIds']; 
    $this->view->filterIndustryIds = $this->sessionAuto2Auto['IndustryIds']; 
} 

보기 : sidebar.phtml

<?php 
    // This code does NOT show the value, comes up blank 
    echo($this->filterCity); 
?> 

답변

0

당신이 사용 sidebar.phtml를 호출하는 경우 부분 도우미, 부분 변수는 자체 변수 범위를 가지며 그들에게 전달되는 액세스 변수 만. , 큰 도움을

<?=$this->render('sidebar.phtml')?> 
+0

감사 :

echo $this->partial('sidebar.phtml', array( 'filterCity' => $this->filterCity, 'filterIndustryIds' => $this->filterIndustryIds ) 

또는 (다른보기 스크립트와 같은 범위를 사용하는) 대신 렌더링 사용 : 당신은 당신의 부분 도우미 호출에서 세션 변수를 포함하거나 필요 –

관련 문제