2017-02-26 11 views
1

で定義されているにもかかわらず、私は私のlaravelコントローラに次のコード行を持っている:エラー:laravelで未定義の関数の機能は、コントローラ

public function getTags() { 
    $tags = DB::table('tags')->get(); 
    /* convert Object to array */ 
    $tagsArray = array(); 
    foreach($tags as $tag) { 
     $tagsArray[$tag->tag] = $tag->tag; 
    } 
    return $tagsArray = json_decode(json_encode($tagsArray) , TRUE); 
} 

public function index() { 
    // $recentBlogPost = DB::table('Admin')->get(); 
    // Auth::logout(); 
    if (!(Auth::check())) { 
     return Redirect::to('login'); 
    }  

    $tagsArray = getTags(); 
    return view('admin.index')->with('tags' , $tagsArray); 
} 

は、今私は自分のコードの次の行にエラーが表示されます。

$tagsArray = getTags(); 

私は次のエラーを取得する:

Call to undefined function App\Http\Controllers\getTags() 

今私は、同じコントローラのwherに定義されているこの機能を持っていますこの関数は呼び出されていますが、なぜこの未定義関数のエラーが出ますか?

答えて

2

正しい構文は次のとおりです。

$tagsArray = $this->getTags(); 

The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs

http://php.net/manual/en/language.oop5.basic.php

1

$tagsArray = $this->getTags(); 

を試してみましたか?

関連する問題