dqg95034 2014-06-26 10:24
浏览 27
已采纳

Laravel 4:为每个路由网址添加用户名

How do I add username to url?

Example: www.domain.com/feeds/username

I want to add username to every route url.

::Route::

Route::get('feeds', array('before' => 'auth', 'as' => 'feeds', 'uses' => 'FeedsController@getFeedsPage'));

::Controller::

class FeedsController extends BaseController {
    public function getFeedsPage() {
        return View::make('feeds.index');
    }
}

Thanks in advance.

Michael.

  • 写回答

1条回答 默认 最新

  • douliao8760 2014-06-26 10:28
    关注

    You may try this, declare the route like this (Notice {username}):

    Route::get('feeds/{username}', array('before' => 'auth', 'as' => 'feeds', 'uses' => 'FeedsController@getFeedsPage'));
    

    Declare the class:

    class FeedsController extends BaseController {
    
        // Use a parameter to receive the username
        public function getFeedsPage($username) {
            // You may access the username passed via route
            // inside this method using $username variable
            return View::make('feeds.index')->with('username', $username);
        }
    }
    

    Now you may use a URI like these:

    www.domain.com/feeds/username1
    www.domain.com/feeds/michaelsangma
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型