【问题标题】:Laravel - loading view -> getting blank page issueLaravel - 加载视图 -> 出现空白页问题
【发布时间】:2017-06-13 19:46:09
【问题描述】:

这是我的课

class PageController extends Controller
{
    public function show($slug = null, $slug2 = null)
    {
        if (!$slug2) { 
            $cat1 = 1;
            return view('frontend/pages/category', [
               'categories' => $cat1
            ]);
        }
    }
}

此版本的代码运行良好。 如果我将返回视图逻辑移动到这样的单独函数中:

        class PageController extends Controller
        {

                public function show($slug = null, $slug2 = null)
                {
                    if (!$slug2) { 
                        $cat1 = 1;
                        $this->myfunction($cat1);
                    }
                }
                public function myfunction($cat1)
                {
                        return view('frontend/pages/category', [
                           'categories' => $cat1
                        ]);
                }
         }

我得到一个空白页。日志中没有任何内容。知道为什么吗?

【问题讨论】:

  • 您不需要在show 方法中使用return $this->myfunction($cat1);
  • 这是路线Route::get('{slug?}/{slug2?}', 'PageController@show');
  • 因为myfunction 的参数是cat1
  • @u_mulder 不是我更新了我的答案,抱歉,错了
  • 更新问题后 - 更新代码并运行它。

标签: php laravel view


【解决方案1】:

你应该在show中返回myfunction的结果

【讨论】:

  • 你能说得更具体些吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-16
  • 1970-01-01
  • 2016-04-19
  • 2021-09-14
  • 1970-01-01
  • 2016-05-20
相关资源
最近更新 更多