• laravel框架总结(三) -- 路径分析


    1.直接写绝对路径,这样会用在/goods/show前面加上域名

      <a href="/goods/show?id=<?php echo $item['id']; ?>">这是一个跳转</a>
     

    2.分析使用route和url辅助函数

      2.1route()配合路由中的别名来使用
        route 函数生成指定路由名称网址:
          Route::get('user/profile', ['as' => 'profile', function ($id) { // }])
          $url = route('profile');
        如果该路由接受参数,你可以作为第二参数传递:
          Route::get('user/{id}/profile', ['as' => 'profile', function ($id) { // }]); $url = route('profile', ['id' => 1]);
        这样的好处是当我们修改user/profile时候不用去我们工程的所有地方修改url跳转
        
        注意:
          关于传递参数,例如route('profile', ['id' => 1,'name'=>test])
          当我们在创建路由时候有规则,参数先走规则,不符合规则,那么就相当于http://xxxxx.com?id=1&name=test
     
      2.2url()
        url 函数生成指定路径的完整网址:
          function url($path = null, $parameters = [], $secure = null)
        url()方法生成一个完整的网址。
          Route::get('user/profile', ['as' => 'profile', function ($id) { // }])
          echo url('user/profile');
     

    3.进一步分析

      创建路由如下所示:
        Route::get('articles',['uses'=>'ArticlesController@index','as'=>'articles.index']);
      要访问该URL可以通过如下形式:
        //URL方式
          <a href="{{ url('/articles') }}">
        //Route方式
          <a href="{{ URL::route('articles.index') }}">
        //Action方式
          <a href="{{ URL::action('ArticlesController@index') }}">
      所以在路由配置中,每个参数的代表意义为:以下粗体部分别人对应url,action,router
        Route::get('articles',['users'=>ArticelsController@index','as'=>'articles.index']);
     

    4.asset()的用法

      function asset($path, $secure = null)
      asset()方法用于引入 CSS/JavaScript/images 等文件,文件必须存放在public文件目录下。
      这样比直接引用的好处是,可以节省资源,压缩文件
  • 相关阅读:
    js Touch事件(向左滑动,后退)
    浏览器滚动条到底部自动加载更多
    如何终止terminal后台进程
    DFT介绍
    GDS area estimation
    Web Scraping with Python第二章
    Web Scraping with Python第一章
    python技巧汇总
    centos6.4安装zsh与dircolors
    linux解压命令汇总
  • 原文地址:https://www.cnblogs.com/redirect/p/6098036.html
Copyright © 2020-2023  润新知