Blogger Information
Blog 65
fans 2
comment 0
visits 60413
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
lavarel7学习笔记:Model模型+Views视图定义+命令行artisan+blade流程控制
张福根一修品牌运营
Original
892 people have browsed it

2020-1-12 lavarel7学习笔记

一、模型

控制器:\mylaravel\app\Http\Controllers
模型:\mylaravel\app\Http\Modeels\Article.php
namespace App\Http\Models;
use Illuminate\Database\Eloquent\Model;
class Article extends Model{……}
视图:\mylaravel\resources\views

连接数据库:
mylaravel.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=root

namespace App\Http\Models\ArticleModel.php
1、模型定义表
2、模型封装自定义方法
namespace App\Http\Controllers\Article.php
3、控制器引用模型方法

4、视图输出
1、return view(‘article/index’,[‘title’=>’4000多名村民聚集打麻将’]);
2、$res = $article->where(‘id’,1)->first()->toArry();
$data =(array)$res;
return view(‘article/index’,$data);

二、视图定义

1、\mylaravel\resources\views\article\index.php

<div><?php echo $title></div>

三、命令行artisan

1、创建控制器
php artisan make:controller Product
php artisan make:controlle Admin/Orders
2、创建模型
php artisan make:model Product
php artisan make:model Http/Models/Product
3、不能使用命令创建视图

四、blade模板引擎

1、文件名后缀.blade.php
{{$title}}
2、视图翻译/缓存文件:\mylaravel\storage\framework\views
<?php echo e($title)>
3、e函数
function e(){
return htmlentities($vel);
}
4、不希望blade翻译
<div>单价:¥@{{price}}</div>
5、不希望blade转义,原样输出
div>{{!!$contents!!}}</div>

五、blade流程控制

1、blade的if条件
@if(user[‘uid’]>0)
<span>{{$user[‘username’]}}</span>
<a href="">退出</a>
@else
<a href="">登录</a>
<a href="">注册</a>
@endif

@if($score==60)
<span>及格</span>
@elseif($score==80)
<span>还行</span>
@elseif($score==100)
<span>天才</span>
@endif

断点打印
dd();不会往下走
dump();会往下走

2、blade的foreach遍历
@foreach($srticle_list as $article)
<div><a href="">{{$article[‘title’]}}</a></div>
@endforeach

3、blade的for循环
@for($i=0;$i<count($srticle_list);$i++) <div><a href=""{{$srticle_list[$i]['title']}}</div>
@endfor

lavarel7学习笔记

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post