【发布时间】:2013-08-21 00:32:38
【问题描述】:
根据这些答案中的建议:What are the best practices and best places for laravel 4 helpers or basic functions?
我创建了一个文件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);
}
但我得到 Controller 方法未找到。
【问题讨论】: