开发者

How to display session variables in cakePHP

I have a controller class below which adds a student in to session.

class StudentsController extends AppController { var $name="Student";

    function addstudent()
    {
        //$id=$_REQUEST['id'];
        //$this->Session->write('id', $id);
        static  $count=0;
        if (!empty($this->data)) {

   开发者_StackOverflow中文版     $students = $this->Session->read('Student');
        if (!$students) {
            $students = array();


        }
        $students[] = $this->data['Student'];/* data */
        $this->Session->write('Student', $students);
        $this->Session->write('student_count',$count);
            $this->redirect(array('controller'=>'students','action' => 'addstudent'));
        }       

    }
}

my question is how to display all the added students in the view page.please explain me with syntax


Add the Session helper to your view. The code to access the student_count variable would be

$session->read('student_count');

The general syntax is

$session->read('var_name');


$student_list = $this->Session->write('Student', $students);
$student_count = $this->Session->write('student_count',$count);

$this->set('$student_list',student_list);
$this->set('$student_count',student_count);

use the student_list and student_count in view page .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜