如何解决在cakePHP中的控制器内传递数组
| 在我的控制器中,我有2个动作,例如action1() {
//code
SomeArray=();
//code
}
如何将所有SomeArray数据传递给action2?
我试图在类中创建一个公共数组变量并将其传递,但是没有运气。
我试图将其作为参数传递给action2 ...
例如在action1中,$ this-> action2(SomeArray)然后在action2($ param)中再也没有运气。
function doExam($id = null) {
if (!$id) {
$this->Session->setFlash(__(\'Invalid exam\',true));
$this->redirect(array(\'action\' => \'index\'));
}
$this->Exam->recursive=1;
$conditions_question = array(\'Question.exam_id\' => $id);
$questions = $this->Exam->Question->find(\'all\',array(\'conditions\' => $conditions_question));
foreach ($questions as $question) {
**$this->questionsByExam[]** = $question[\'Question\'][\'qst\'];
}
//OK PASSED
echo debug($this->questionsByExam);
//OK $exam_id
$this->exam_id = $id;
}
我还有另一个动作validate_answer,我想在这里传递问题
有什么帮助吗?
提前致谢
解决方法
我试图在类中创建一个公共数组变量并将其传递,但是没有运气。
您可以显示此代码吗?它应该可以作为类变量正常工作...
例如:
class FooController extends AppController {
var $someArray = array();
function doExam() {
// Populate the array here
$this->someArray = array(1,2,3);
}
function bar() {
// Use it here,no need to pass it as an argument
print_r($this->someArray);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。