i'm getting the following errors:

Notice 8: Undefined variable: student_info [APP\controllers
\motor_developments_controller.php, line 7]

i'm getting the same notice in \motor_developments\search.ctp as
well.

The student_info data in $this->redirect is not getting passed from
merry_parents_controller's login function to
motor_developments_controller's search function.

Does anyone know on why student_info is not getting passed? Any help
is much appreciated.

merry_parents_controller.php

function login(){

        if ($this->Auth->user()){
           //debug($this->Auth->user());
           $this->data=$this->Auth->user();                    
           if (!empty($this->data)){
                $student_info=$this->MerryParent->Student->find('first',array(
                'conditions'=>array(
                'Student.merry_parent_id'=>$this->data['MerryParent']
['id']                           )
        )                                          );

             echo 'student info: '.$student_info;
        $this->set('student_info',$student_info);
                                }
else{
        echo 'Auth user has not been set';
       }

$this->redirect(array('controller'=>'motor_developments',
'action'=>'search',$student_info));
}
}

controller:motor_development_controller.php

<?php
          class MotorDevelopmentsController extends appController{
        public $name='MotorDevelopments';

        public function search(){
                    var_dump($student_info);
                $x=$this->MotorDevelopment-
>find('one',array('conditions'=>array('MotorDevelopment.student_id'=>12)));
                $this->set('x',$x);
                $this->set(compact('x'));
        }
}
?>

view: /motor_developments/search.ctp

<?php
    echo 'Hello Jen<br>';
    var_dump($student_info);
    echo '<br>x';
    var_dump($x);
     ?>

app_controller.php

class AppController extends Controller {


        //var $components=array('Email');
        var $components=array('Auth','Session','Cookie');

        function beforeFilter(){
          if (isset($this->Auth)){
                        $this->Auth->userModel=array('MerryParent');
                        $this->Auth-
>loginAction=array('controller'=>'merry_parents','action'=>'login');
                            $this->Auth->allow('*');
                        $this->Auth-
>loginRedirect=array('controller'=>'motor_developments','action'=>'search');
                        $this->Auth-
>logoutRedirect=array('controller'=>'merry_parents','action'=>'register');
                        //$this->Auth->deny('/motor_developments/index');
            $this->Auth->authorize='controller';
}
 else
           $this->Session->setFlash('Auth has not been set');
}

function isAuthorized(){
        return true;
        }

thank you.

Recommended Answers

All 3 Replies

Hello,

Try the following 2 steps in controller:motor_development_controller.php :
1. Define a parameter for the search function (an array which receives the data you are sending through the redirect() method)

public function search($student_info)

2. add the following instruction inside the search() function

$this->set('student_info',$student_info);

Hope this helps

Hello,

Try the following 2 steps in controller:motor_development_controller.php :
1. Define a parameter for the search function (an array which receives the data you are sending through the redirect() method)

public function search($student_info)

2. add the following instruction inside the search() function

$this->set('student_info',$student_info);

Hope this helps

I tried what you said. When I do a debug($search_info), i'm only getting an empty array. I have no idea on what i'm doing wrong.

My mistake; you cannot pass an array as argument.

Look at someone having the same problem at http://www.google.fr/url?sa=t&rct=j&q=cakephp+how+to+pass+an+array+as+parameter&source=web&cd=11&ved=0CCAQFjAAOAo&url=http%3A%2F%2Fgroups.google.com%2Fgroup%2Fcake-php%2Fbrowse_thread%2Fthread%2F017ddb1d1381d9e6%2F9027627f5f7df32a%3Fshow_docid%3D9027627f5f7df32a&ei=Dv_JTqubLYiWhQe915X2Bw&usg=AFQjCNFnYu5vN8wgOcwXjkj8WYtiKYX7Ig

The possible answers are:
- serialize the array in the calling functton; pass the serialized string as argument to the search function; in the search function, unserialize the argument to have the array back. http://www.php.net/manual/en/function.serialize.php
- break-up the array and pass each element as argument respecting the format /key1:value1/key2:value2 and, in your search function, read the data with $this->param

$this->redirect('/motor_developments/action/key1:value1/key2:value2/key3:value3'=>'search',$student_info));

- store the data in a session
- the answer that may be makes the most sense is to just transfer the id merry_parent_id you are looking for to the search function and do the MerryParent->Student->find() call in the search function.

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.