Laravel框架相对较新,我不知道为什么该函数返回空白页。
<?php
class MainController extends Controller {
public function setLanguage($language = 'nl', $page = 'index')
{
switch ($language) {
case 'nl':
$this->showNL();
break;
case 'fr':
echo $language . ' ' . $page;
break;
case 'de':
echo $language . ' ' . $page;
break;
default:
echo "nothing here";
}
}
public function showNL() {
return "Display some text";
}
}
函数 showNL() 被调用,但它只返回一个空的 html 文档。也没有拉拉维尔错误。
你对 showNL() 的输出什么都不做
尝试做:
return $this->showNL();
另外:永远不要在控制器方法中回显或打印任何内容,始终返回输出,因此您应该更改所有 switch 语句。
不是吗?
switch ($language) {
case 'nl':
echo $this->showNL(); // Added echo