• laravel强大功能路由初探(二)


    目标当然是先输出helloworld

    配置hosts文件和apache下的httpd-vhosts.conf,

    hosts:127.0.0.1  www.blog.com

    httpd-vhosts.conf:

    <VirtualHost *:80>
      DocumentRoot "D:wwwhtdocsloglaravelpublic"
      ServerName www.blog.com
    </VirtualHost>
    以下代码 均在routes.php里面操作

    //基础路由1
    Route::get('/',function(){ return 'helloworld'; });

    输出如下:

    //基础路由2
    //不能直接输入post方法访问路由
    Route::post('test1',function(){ return 'post'; });

    //基础路由 3
    Route::get('test',function(){ return 'testx'; });

    //多请求
    Route::match(['get','post'],'xx/xx',function(){
        return 'heihei1';
    });
    //或者
    Route::any('xx/xx',function(){
        return 'heihei2';
    });

    //路由传参
    Route::get('user/{id}',function($id){
        return '用户的id是'.$id;
    });
    
    //两个参数
    Route::get('user/{name}/{id}',function($name,$id){
        return '用户的名字是'.$name.'用户的id是'.$id;
    });

    //路由可选参数
    Route::get('user/{name?}',function($name=null){ return '用户的名字是'.$name; });

    //参数限制where(),用正则判断
    Route::get('user/{name}',function($name){
        return '用户的名字是'.$name;
    })->where('name','[a-zA-Z]+');
    
    //多个参数限制
    Route::get('user/{name}/{id}',function($name,$id){
        return '用户的名字是'.$name.'用户的id是'.$id;
    })->where(['name'=>'[a-zA-Z]+','id'=>'d+']);
    //控制器路由,前一个参数随便填写,你开心就好
    //例如admin/test或者test或者nikaixinjiuhao或者xx/xx/xxx/xxx/xx/xx,仍然可以访问
    Route::get('xxx/xx','TestController@hello');
    Route::get('xx/xx/xxx/xxx/xx/xx','TestController@hello');

    //routes.php中
    //控制器路由,前一个参数随便填写,你开心就好
    //例如admin/test或者test或者nikaixinjiuhao或者xx/xx/xxx/xxx/xx/xx,仍然可以访问
    Route::get('xxx/xx','HomeTestController@hello');
    //直接写在模块外面
    Route::get('xx/xx/xxx/xxx/xx/xx','Test2Controller@hello');

    <?php
    //控制器可以直接手动创建,或者使用cmd命令行创建
    //TestController.php namespace AppHttpControllersHome; use AppHttpControllersController; class TestController extends Controller{ public function hello(){ echo 'hello world'; } }
    <?php
    //Test2Controller.php
    namespace AppHttpControllers;
    use AppHttpControllersController;
    class Test2Controller extends Controller{
        public function hello(){
            echo 'hello world';
        }
    }

     

    赋值到模板:

    TestController.php

    <?php
    //TestController.php
    namespace AppHttpControllersHome;
    use AppHttpControllersController;
    class TestController extends Controller{
        public function hello(){
            return  'hello world';
        }
    
        public function phptemplate(){
            $data=['name'=>'zhangsan','userid'=>'39'];
            return view('test',$data);
        }
    
        public function phpblade(){
            $data=['name'=>'zhaowu','userid'=>'23'];
            return view('test2',$data);
        }
    }

    routes.php

    Route::get('usertemplate','HomeTestController@phptemplate');
    Route::get('userblade','HomeTestController@phpblade');

    test页面

    <!DOCTYPE html>
    <html>
    <head>
    	<title>这是php形式的模板</title>
    </head>
    <body>
    {{$name}}
    {{$userid}}
    <hr>
    <span style="color:red;font-size:29px"><?php echo $name;?></span> <span style="color:red;font-size:39px"><?php echo $userid;?></span> </body> </html>

     test2.blade.php

    <!DOCTYPE html>
    <html>
    <head>
    	<title>这是phpblade的模板</title>
    </head>
    <body>
    
    <span style="color:red;font-size:29px"><?php echo $name;?></span>
    <span style="color:red;font-size:39px"><?php echo $userid;?></span>
    <hr>
    <span style="color:red;font-size:29px">{{$name}}</span>
    <span style="color:red;font-size:39px">{{$userid}}</span>
    </body>
    
    </html>
    

     得到效果,两者的区别一目了然:

  • 相关阅读:
    Halcon 如何将图像转化为矩阵形式
    Halcon 图像分割
    Halcon intensity算子,用于计算灰度的均值和方差
    Halcon draw_region接口
    Halcon scale_image 函数用法技巧
    Halcon 保存图像
    Halcon 读取多张图片
    Halcon 算子 sub_image add_image mult_image div_image
    Halcon 算子 get_grayval 用于读取图像的灰度值
    Halcon 算子 convert_image_type 转换图像类型
  • 原文地址:https://www.cnblogs.com/xiong63/p/6138564.html
Copyright © 2020-2023  润新知