【问题标题】:Laravel view rendering issueLaravel 视图渲染问题
【发布时间】:2015-04-20 05:52:40
【问题描述】:

以下是我的控制器类,

namespace Admin;
class CategoriesController extends \BaseController {

    public function index($action = '', $id= ''){
       //return \View::make('welcome');View is correctly rendered here
        switch ($action){
            case ''     :
            case 'list' : $this->showList();
            break;
            case 'add'  : $this->addCategories();
            break;
            case 'edit' : $this->editCategories($id);
            break;
        }

    }

    public function showList($id_category =''){
        echo "testing";
        return \View::make('welcome'); //it does not work here
   }

在调用视图时,它在函数 showList() 中不起作用。函数内的回显有效,但视图只返回一个空白页而没有任何错误。这可能是什么问题?

【问题讨论】:

  • dd(\View::make('welcome'));显示?在 laravel 5 中,我建议您改用 view()。问题可能是由于名称空间,因为 View 是 Illuminate\Support\Facades\View 而不是 \View
  • 它正在打印视图。错误在于回报。感谢您的关心。

标签: php laravel view


【解决方案1】:

我想你想从 index 函数而不是路由中调用 showList。如果是这样,index 函数没有返回操作。为了使其工作,您需要在index 函数中返回从showList 函数返回的内容,否则将不会呈现视图。尝试将您的 index 函数更改为:

public function index($action = '', $id= '') {
    switch ($action) {
        case ''     :
        case 'list' : 
                    return $this->showList();
        case 'add'  : 
                    return $this->addCategories();
        case 'edit' : 
                    return $this->editCategories($id);
    }

}

【讨论】:

    【解决方案2】:

    这是问题所在...从返回视图行中删除 /

    public function showList($id_category =''){
        echo "testing";
        return View::make('welcome'); //it does not work here
    

    }

    【讨论】:

    • 这用于命名空间,而不是问题的原因。视图在 index 函数中以相同的方式呈现。
    • 好的...感谢您的澄清,非常感谢@RunningAdithya
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 2019-01-11
    • 1970-01-01
    相关资源
    最近更新 更多