【问题标题】:Laravel route throwing: cannot find localhostLaravel路由抛出:找不到本地主机
【发布时间】: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 并将结果添加到你的问题中吗?

标签: php laravel laravel-3


【解决方案1】:

尝试使用

HTML::link_to_action('articles@write', 'New article');

并在application/config/app.phphttp://localhosthttp://127.0.0.1 中设置您的根URL!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 2012-07-26
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    相关资源
    最近更新 更多