0

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)) {

        $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

2 Answers 2

3

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');
Sign up to request clarification or add additional context in comments.

1 Comment

Also, you should still be able to access variables with the $_SESSION superglobal. CakePHP is still PHP! But yes, this answer is the proper way to do this while adhering to CakePHP conventions.
0
$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 .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.