惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Y
Y Combinator Blog
O
OpenAI News
K
Kaspersky official blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
S
Securelist
C
CERT Recently Published Vulnerability Notes
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
V
Vulnerabilities – Threatpost
量子位
爱范儿
爱范儿
I
Intezer
博客园 - 叶小钗
The Hacker News
The Hacker News
N
News and Events Feed by Topic
Project Zero
Project Zero
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Privacy & Cybersecurity Law Blog
Google Online Security Blog
Google Online Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Heimdal Security Blog
NISL@THU
NISL@THU
V
Visual Studio Blog
The Last Watchdog
The Last Watchdog
Know Your Adversary
Know Your Adversary
Cisco Talos Blog
Cisco Talos Blog
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
The Cloudflare Blog
小众软件
小众软件
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Schneier on Security
雷峰网
雷峰网
B
Blog RSS Feed
美团技术团队
T
Threat Research - Cisco Blogs
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
N
Netflix TechBlog - Medium
月光博客
月光博客
S
Security Affairs

博客园 - Zhangjinglin

Laravel 5 基础(十二)- 认证 Laravel 5 基础(十一)- Eloquent 关系 Laravel 5 基础(十一)- 子视图和表单复用 Laravel 5 基础(十一)- 表单验证 Laravel 5 基础(十)- 日期,Mutator 和 Scope Laravel 5 基础(九)- 表单 Laravel 5 基础(八)- 模型、控制器、视图基础流程 Laravel 5 基础(七)- Eloquent (laravel 的ORM) Laravel 5 基础(六)- 数据库迁移(Migrations) Laravel 5 基础(五)- 环境与配置 Laravel 5 基础(四)- Blade 简介 Laravel 5 基础(三)- 向视图传送数据(续) Laravel 5 基础(三)- 向视图传送数据 Laravel 5 基础(一)- Laravel入门和新建项目 Android 随机铃声管理器 ubuntu netbeans 字体解决 Mac OS 10.6 原版安装 git 强制恢复到某一版本 混乱中生存
Laravel 5 基础(二)- 路由、控制器和视图简介
Zhangjinglin · 2015-03-31 · via 博客园 - Zhangjinglin
  • 查看 app/Http/routes.php
Route::get('/', 'WelcomeController@index');

@是一个界定符,前面是控制器,后面是动作,表示当用户请求url / 的时候,执行控制器 WelcomeController 中的 index 方法

  • app/http/controllers/welcomecontroller.php
public function index()
{
return view('welcome');
}

当前默认返回一个视图,视图的名字叫做 welcome,实际上是 welcome.blade.php,blade是laravel的视图模板。

  • 可以查看 `resources/views/welcome.blade.php

  • 修改welcomecontroller.php

public function index()
{
//    return view('welcome');
return 'hello, laravel';
}

在浏览器中测试,得到一个简单的反馈。

  • 我们新建一个路由,在routes.php中增加:
Route::get('/contact', 'WelcomeController@contact');

可以新建一个路由,但是现在我们还是直接使用默认的控制器,在 WelcomeController.php 中添加:

public function contact() {
    return 'Contact Me';
}

在浏览器终测试新增加的路由。

  • 我们可以返回简单的字符串,也可以返回json或者html文件,所有的视图文件存储在resource->views中。
    例如:return view('welcome') ,我们不需要考虑路径,也不要添加.blade.php扩展名,框架自动为我们完成。如果在views目录中需要子目录,例如views/forum子目录,只需要return view('forum/xxx'),或者跟简单而明确的方式是:return view('forum.xxx')。😄

  • 我们返回一个页面

public function contact() {
    return view('pages.contact');
}
  • 在 views 目录下创建 pages目录,然后创建contact.blade.php
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<h1>Contact</h1>
</body>
</html>