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>
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、不能使用命令创建视图
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>
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