zoukankan      html  css  js  c++  java
  • 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文件目录下。
      这样比直接引用的好处是,可以节省资源,压缩文件
  • 相关阅读:
    JAVA多线程2 锁
    IE8标准模式下VML不能显示问题
    JAVA多线程1
    JAVA判断32位还是64位,调用不同的DLL
    JNA调用DLL
    如何提高执行力
    httpClient多线程请求
    【NodeJS】安装
    [转载]一个项目涉及到的50个Sql语句(整理版)
    resultMap中的collection集合出现只能读取一条数据的解决方法
  • 原文地址:https://www.cnblogs.com/redirect/p/6098036.html
Copyright © 2011-2022 走看看