doukan5332 2014-02-08 17:29
浏览 34
已采纳

Laravel 4.1 link_to

I'm just starting with Laravel and I was doing some tutorials and crashed into something that I don't seem to work out. The thing is, I'm creating a link_to in a file like this:

<li>{{ link_to("/users/{$user->username}", $user->username) }}</li>

This link works and the page /users/foo is created, but then, in that page I'm using the username to print a message like "User foo page" using the following code:

<body>
    <h1> User {{$user->username }} page</h1>
</body>

As I said, the page is created with the link http://myhost/users/foo but it just comes out blank, nothing is displayed and I can't seem to understand why. Thank you for your help.

EDIT: Sorry people, I was just being dumb and blind. I've forgotten to return the view. Jesus. With that corrected all went fine, thanks to all the people that helped me as they're solutions worked all fine with the view being returned.

  • 写回答

2条回答 默认 最新

  • dongyanggan3025 2014-02-08 21:37
    关注

    I don`t think you should use link_to:

      link_to('foo/bar', $title, $attributes, $secure);
    

    Try something like this:

    <li><a href="{{ URL::route('get_user', 'SomeUsername') }}">SomeUsername</a></li>
    

    routes.php:

    Route::get('users/{username}', array('as'=>'get_user', 'uses'=>'UserController@getUser'));
    

    UserController.php:

    class UserController extends BaseController{
    
    public function getUser($username){
       $user = User::where('username','=', $username)->first();
       return View::make('users.show')
                  ->with('user', $user);
    }
    

    blade view (users.show):

    <body>
      <h1> User {{$user->username }} page</h1>
    </body>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题