Laravel(二)

2017-09-05  本文已影响95人  PHPer_

控制器

<?php

namespace App\Http\Controllers;
class MemberController extends Controller {
    public function info() {
        return 'member-info';
    }
}
//第一种关联方法
Route::get('member/info', 'MemberController@info');
//第二种关联方法
Route::get('member/info', ['uses' => 'MemberController@info']);
//给路由起别名
Route::get('member/info', ['uses' => 'MemberController@info','as' => 'memberinfo']);
//控制层直接打印路由
public function info() {
    return route('memberinfo');
}
//路由文件代码,where条件里面要指定过滤的字段,并写明规则(正则表达式)
Route::get('member/{id}', ['uses' => 'MemberController@info'])->where('id','[0-9]+');
//控制层代码
public function info($id) {
     return 'member-info-id-' . $id;
}

视图

public function info() {
     return view('member/info');
}
return view('member/info',[
      'name' => 'gsy',
      'age' => 18,
]);
{{$name}}  {{$age}}

模型

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;

class Member extends Model {
    public static function getMember() {
        return 'member name is gsy';
    }
}
return Member::getMember();
上一篇 下一篇

猜你喜欢

热点阅读