将值从一个函数传递到另一个函数时,视图文件未加载到 codeigniter 4 中?
While passing values from one function to another function the view files are not loading in codeigniter 4?
我需要帮助。在控制器中,当我从另一个函数调用一个函数时,视图文件未加载。只显示空白页。
在下面的代码中,我需要将数组 $calc 从 calc() 函数传递给 sem1() 函数。数组值在函数中传递,但 sem1() 函数中的视图文件未加载,仅显示空白页。我正在使用 CodeIgniter 4。请帮忙。
public function calc()
{
$calc = [
'regulation' => $this->request->getPost("regulation"),
'branch' => $this->request->getPost("branch"),
'calculation' => $this->request->getPost("calculation"),
"semester" => $this->request->getPost("semester")
];
if ($calc['calculation'] == "GPA") {
if ($calc['semester'] == "Semester 1") {
$this->sem1($calc);
}
}
}
public function sem1($calc = '')
{
$this->builder->select('elective, sub_code, sub_name');
$this->builder->where('semester', $calc['semester']);
$this->builder->where('branch', $calc['branch']);
$query = $this->builder->get();
$isElective = [0, 0, 0, 0, 0];
return view('au/auform', ['query' => $query, 'semester' => $semester, 'isElective' => $isElective]);
}
您应该添加回显以呈现视图:
public function calc(){
$calc = [
'regulation' => $this->request->getPost("regulation"),
'branch' => $this->request->getPost("branch"),
'calculation' => $this->request->getPost("calculation"),
"semester" => $this->request->getPost("semester")
];
if ($calc['calculation'] == "GPA") {
if ($calc['semester'] == "Semester 1") {
echo $this->sem1($calc);
}
}
}
有关更多信息,请查看文档 - LINK
我需要帮助。在控制器中,当我从另一个函数调用一个函数时,视图文件未加载。只显示空白页。
在下面的代码中,我需要将数组 $calc 从 calc() 函数传递给 sem1() 函数。数组值在函数中传递,但 sem1() 函数中的视图文件未加载,仅显示空白页。我正在使用 CodeIgniter 4。请帮忙。
public function calc()
{
$calc = [
'regulation' => $this->request->getPost("regulation"),
'branch' => $this->request->getPost("branch"),
'calculation' => $this->request->getPost("calculation"),
"semester" => $this->request->getPost("semester")
];
if ($calc['calculation'] == "GPA") {
if ($calc['semester'] == "Semester 1") {
$this->sem1($calc);
}
}
}
public function sem1($calc = '')
{
$this->builder->select('elective, sub_code, sub_name');
$this->builder->where('semester', $calc['semester']);
$this->builder->where('branch', $calc['branch']);
$query = $this->builder->get();
$isElective = [0, 0, 0, 0, 0];
return view('au/auform', ['query' => $query, 'semester' => $semester, 'isElective' => $isElective]);
}
您应该添加回显以呈现视图:
public function calc(){
$calc = [
'regulation' => $this->request->getPost("regulation"),
'branch' => $this->request->getPost("branch"),
'calculation' => $this->request->getPost("calculation"),
"semester" => $this->request->getPost("semester")
];
if ($calc['calculation'] == "GPA") {
if ($calc['semester'] == "Semester 1") {
echo $this->sem1($calc);
}
}
}
有关更多信息,请查看文档 - LINK