我正在尝试传递一个名为schoolYear的值,该值现在是2019年,可以说或用户真正选择的任何内容。用户选择提交后,将执行下面的操作,它执行了if post请求,然后通过屏幕2进入编辑控制器。在屏幕2上,我具有编辑功能,将schoolYear传递给它,并且回显返回2019年我选择的正确值。大!现在,我正在努力将该特定参数传递到表函数中,以便可以如图所示使用它。有人能指出我正确的方向吗,谢谢
现在我没有收到任何错误消息,但是如果我查看正在传递的sql,它在正在执行的sql中显示FiscalYear = 0,这意味着未从我的控制器hmmmmmm设置$ schoolyear
return $this->redirect([
'controller' => 'MassUpdateCalender',
'action' => 'edit',
$schoolYear,
$allElementary,
]);
public function edit($schoolYear)
{
$InformationCalenderTable = $this->loadModel('MMSDvSchoolFromCalendar');
echo $schoolYear;
$elementarySchools = $InformationCalenderTable->getSchoolsByLevel('0%', $schoolYear);
public function getSchoolsByLevel($schoolYear, string $code = '0', string $isSummerSchool = '0')
{
$query = $this->find()
->where([
'FiscalYear' => $schoolYear,
'DistrictCode' => 'MA',
'summerSchool' => $isSummerSchool,
'SchoolCode like' => $code,
]);
return $query->toArray();
}
结果将返回所有符合条件的学校列表。
答案 0 :(得分:0)
据我了解,您正在尝试根据学校所在的年份来获得学校。为此,请执行以下操作:
function edit($schoolYear) {
$this->loadModel('MMSDvSchoolFromCalendar');
$elementarySchools = $this->MMSDvSchoolFromCalendar->find('all', array('conditions' => array('MMSDvSchoolFromCalendar.FiscalYear' => $schoolYear)));
}
但是,如果您尝试在getSchoolsByLevel函数中执行查询,请执行以下操作:
function edit($schoolYear) {
$this->loadModel('MMSDvSchoolFromCalendar');
$code = $isSummerSchool = 0;
$elementarySchools = $this->MMSDvSchoolFromCalendar->find('all', array('conditions' => array('FiscalYear' => $schoolYear, 'DistrictCode' => 'MA', 'summerSchool' => $isSummerSchool, 'SchoolCode LIKE' => $code)));
}
如果要像示例中那样扩展功能,请执行以下操作:
function edit($schoolYear) {
$this->loadModel('MMSDvSchoolFromCalendar');
$elementarySchools = $this->_getSchoolsByLevel($schoolYear);
}
function _getSchoolsByLevel($schoolYear, string $code = '0', string $isSummerSchool = '0') {
return $this->MMSDvSchoolFromCalendar->find('all', array('conditions' => array('FiscalYear' => $schoolYear, 'DistrictCode' => 'MA', 'summerSchool' => $isSummerSchool, 'SchoolCode LIKE' => $code)));
}
注意:
输入var $ uses = array('MMSDvSchoolFromCalendar');在控制器类的顶部,因此您不必继续加载模型。
函数前的下划线表示私有函数。使用此功能,使用户无法转到MMSDvSchoolFromCalendar / getSchoolsByLevel页面。