使用控制器功能显示多个页面

时间:2018-12-20 15:05:32

标签: cakephp

让我们说我在一个控制器中有多个公共功能,例如,我正在尝试一种更好的方法,以便每页显示一个选项,例如,第一页用户选择学校,然后点击提交,下一页用户选择学校,然后点击提交第三页,用户选择一个术语,并显示所有选定字段的最后一页和一个删除按钮。我现在开始测试我的页面,并且想知道完成此操作的最佳方法是什么?

class SchoolYearsController extends AppController
{
public function index()
{

}

public function chooseYear()
{
    $schoolYearsTable = $this->loadModel('SchoolYears');

    $schoolYears = $schoolYearsTable->find()->order(['SchoolYears.endYear'=>'desc']);

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

    $this->request->getSession()->write('App.schoolYear',$this->request->getData('schoolYear'));

    return $this->redirect(['controller'=>'SchoolYears', 'action'=>'chooseSchool']);
}

public function chooseSchool()
{
    $schoolListsTable = $this->loadModel('Schools');

    $schoolYear = $this->session->read('App.schoolYear');
    $schools = $schoolListsTable->find()
    ->where([
        'fiscalYear' => $schoolYear,
        'districtCode' => 'MA',
    ])
    ;

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

    return $this->redirect(['controller'=>'SchoolYears', 'action'=>'chooseTerm']);
}

public function chooseTerm()
{
    $chosenTerm = $this->request->getData();
}
}

0 个答案:

没有答案