2017-07-18 53 views
0

我需要一些幫助來顯示2頁中的所有類別。 現在我將它們顯示在1頁中。我的問題是我怎樣才能在其他頁面顯示他們呢? 這是控制器:如何在2頁上顯示類別

class ShopController extends MainController 
{ 
    public function categories(){  
     self::$data['categories']=Categorie::all()->toArray(); 
     self::$data['title']=self::$data['title'].'| Shop Categories'; 
     return view('content.categories', self::$data); 
    } 

如果我嘗試使用延伸,並從頁面「content.categories」得到它,它說,$類是不確定的。 (所以它只適用於content.categories)

+0

你試圖在由'延伸佈局訪問類別content.categories'? –

+0

是的,但它告訴我的$類別是未定義的 –

+0

嘗試'返回視圖('content.categories') - > withCategories(self :: $ data);'! – Maraboc

回答

0

如果你堅持這樣做,你可以在你的content.categories視圖文件中使用這個片段。

@extends('your-layout', ['categories' => $categories]) 
+0

還是說未定義變量:categories(查看:categories.blade.php) –

0

變化控制器像下面

class ShopController extends MainController 
{ 

public function __construct() 
{ 
    // define variable in your construct 
    $this->data = array(
         'title' => 'Your Title' 
        ); 
} 

public function categories(){  
    $this->data['categories']=Categorie::all()->toArray(); 
    $this->data['title']=$this->data['title'].'| Shop Categories'; 
    return view('content.categories', $this->data); 
} 

在你的視圖文件content/categories.blade.php

使用$categories得到DATAS

相關問題