目标当然是先输出helloworld

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

hosts:127.0.0.1  www.blog.com

httpd-vhosts.conf:

<VirtualHost *:80>
  DocumentRoot "D:\www\htdocs\blog\laravel\public"
  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','Home\TestController@hello');
//直接写在模块外面
Route::get('xx/xx/xxx/xxx/xx/xx','Test2Controller@hello');

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

赋值到模板:

TestController.php

<?php
//TestController.php
namespace App\Http\Controllers\Home;
use App\Http\Controllers\Controller;
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','Home\TestController@phptemplate');
Route::get('userblade','Home\TestController@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>

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

laravel强大功能路由初探(二)的更多相关文章

  1. [转]Laravel 4之路由

    Laravel 4之路由 http://dingjiannan.com/2013/laravel-routing/ Laravel 4路由是一种支持RESTful的路由体系, 基于symfony2的R ...

  2. laravel基础课程---2、Laravel配置文件、路由及php artisan(php artisan是什么)

    laravel基础课程---2.Laravel配置文件.路由及php artisan(php artisan是什么) 一.总结 一句话总结: PHP工具匠:php artisan,其实本身就是一些PH ...

  3. FM收音机 RDS的强大功能

    FM收音机 RDS的强大功能 分类: MTK2011-04-26 16:06 14889人阅读 评论(6) 收藏 举报 交通公告体育音乐娱乐教育 前言 随着发展,会有越来越多的电台具有RDS广播功能, ...

  4. Python和SQL Server 2017的强大功能

    Python和SQL Server 2017的强大功能 摘要: 源:https://www.red-gate.com/simple-talk/sql/sql-development/power-pyt ...

  5. Python和SQL 2017的强大功能

    Python和SQL Server 2017的强大功能   原文来自:https://www.red-gate.com/simple-talk/sql/sql-development/power-py ...

  6. 将VIM配置成强大的IDE(二)

    将VIM配置成强大的IDE(二) 前面我们已经安装好了vundle这一款强大的插件管理工具. 下面,当然是配置我们需要的插件了. 在VIM下面通过命令 help vundle 我们可以知道,VUNDL ...

  7. Laravel 深入理解路由和URL生成

    原文地址: Laravel 深入理解路由和URL生成 在模板中我们一般不会直接写死url,而是用url助手生成url,本文介绍一下url助手的使用以及遇到的一些比较头疼的问题. 首先,我们创建了一个路 ...

  8. vue2.0学习笔记之路由(二)路由嵌套+动画

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. vue2.0学习笔记之路由(二)路由嵌套

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. 中大东校小米路由器mini实现inode上网,ipv6 wifi【中大】【东校】【inode】【ipv6】

    还有不到4个月就要毕业了,前几天半夜没事捣鼓小米路由没想到竟然实现了wifi的ipv6. 正好又安利了同学一台小米路由mini,从刷机到inode到ipv6全搞了一遍. 这里将教程写出来,服务学弟妹. ...

  2. BZOJ 3289: Mato的文件管理[莫队算法 树状数组]

    3289: Mato的文件管理 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 2399  Solved: 988[Submit][Status][Di ...

  3. UNITY 移动到指定位置的写法

    //move towards a target at a set speed. private void MoveTowardsTarget() { //the speed, in units per ...

  4. docker常用命令

    yum install wget -y wget -O etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7 ...

  5. [LeetCode] Validate IP Address 验证IP地址

    In this problem, your job to write a function to check whether a input string is a valid IPv4 addres ...

  6. [LeetCode] Shortest Distance from All Buildings 建筑物的最短距离

    You want to build a house on an empty land which reaches all buildings in the shortest amount of dis ...

  7. [LeetCode] Dungeon Game 地牢游戏

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  8. [LeetCode] Binary Tree Zigzag Level Order Traversal 二叉树的之字形层序遍历

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  9. 【原】Spark之机器学习(Python版)(二)——分类

    写这个系列是因为最近公司在搞技术分享,学习Spark,我的任务是讲PySpark的应用,因为我主要用Python,结合Spark,就讲PySpark了.然而我在学习的过程中发现,PySpark很鸡肋( ...

  10. [板子]ISAP

    ISAP求最大流,敲了一发板子,无压行,教程略去.转载请随意. #include <cstdio> #include <cstring> #include <algori ...