2012-11-05 44 views
0

http://docs.phalconphp.com/en/0.6.0/reference/session.html文檔有錯誤,我不知道

存儲/ Session中

檢索數據從一個控制器,一個視圖或任何其他成分,多數民衆贊成延伸爾康\ DI \注射就可以訪問會話服務並以下列方式存儲物品並將其檢索:

<?php 
    class UserController extends Phalcon\Mvc\Controller 
    { 
     public function indexAction() 
     { 
      //Set a session variable 
      $this->session->set("user-name", "Michael"); 
     } 

     public function welcomeAction() 
     { 

      //Check if the variable is defined 
      if ($this->session->has("user-name")) { 

       //Retrieve its value 
       $name = $this->session->set("user-name"); //here, set or get? 
      } 
     } 
    } 

回答

0

你是對的。這應該是get(用於檢索記錄)。校正的例子是:

http://docs.phalconphp.com/en/latest/reference/session.html

<?php 

class UserController extends Phalcon\Mvc\Controller 
{ 

    public function indexAction() 
    { 
     //Set a session variable 
     $this->session->set("user-name", "Michael"); 
    } 

    public function welcomeAction() 
    { 

     //Check if the variable is defined 
     if ($this->session->has("user-name")) 
     { 

      //Retrieve its value 
      $name = $this->session->get("user-name"); 
     } 
    } 
} 
相關問題