【发布时间】:2023-03-04 19:47:01
【问题描述】:
我正在尝试了解 RESTfull 控制器和 Laravel 3 路由。我创建了一个restfull控制器文章,现在想创建以下方法:
GET: index
GET: write // (new but new is reserved)
GET: edit
POST: create
PUT: update
DELETE: destroy
然而,在我开始之前,当我在我的视图中按下 New article 链接时,我一直被重定向到应该重定向到 articles/write 的链接,而不是我被重定向到带有 chrome 错误的空白页面:Chrome 找不到本地主机。
我的控制器:
<?php
class Articles_Controller extends Base_Controller {
public $restful = true;
public function get_index()
{
return View::make('articles.index', array('articles' => Article::all()));
}
public function get_write()
{
return View::make('articles.new');
}
public function post_create()
{
return 'Created';
}
}
我的路线:
?php
Route::get('/', 'home@index');
// Articles
Route::controller('articles');
我的看法:
<h1>Todays articles:</h1>
<?php
if(sizeof($articles) == 0)
{
echo 'No articles published';
}
?>
<br /><br />
<?= HTML::Link('articles/write', 'New article') ?>
【问题讨论】:
-
试试 HTML::Link('/articles/write', '新文章')
-
你能做一个
php artisan route并将结果添加到你的问题中吗?