基於以下推薦答案:What are the best practices and best places for laravel 4 helpers or basic functions?我的laravel-class應該延伸什麼?
我已經創建了一個文件app/library/sitehelpers.php
並將其添加到應用程序中。我的班級應該延長什麼,我如何在控制器中接受它?
<?php
class SiteHelpers{
function save($type, $postid, $url, $author, $content)
{
$post = new Post;
$post->type = $type;
$post->postid = $postid;
$post->url = $url;
$post->author = $author;
$post->content = $content;
try
{
$post->save();
echo $post;
}catch(Exception $e){
throw new Exception('Already saved', 0, $e);
}
}
}
我試着像這樣引用它的控制器:
public function savepostController($type, $postid, $url, $author, $content)
{
SiteHelpers::save($type, $postid, $url, $author, $content);
}
,但我得到沒有找到控制方法。
好的,laravel在哪? – Himmators
以及如果這是一個輔助函數,我將如何從控制器中引用它? – Himmators
編輯添加關於如何以靜態方式調用您的函數的精度。 – Atrakeur