国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

Laravel框架學習筆記(二)項目實戰之模型(Models)

2020-03-22 17:48:24
字體:
來源:轉載
供稿:網友
1.實體關系圖,由于不知道php有什么好的建模工具,這里我用的vs ado.net實體模型數據建模下面開始laravel編碼,編碼之前首先得配置數據庫連接,在app/config/database.php文件'mysql' = array( 'driver' = 'mysql', 'read' = array( 'host' = '127.0.0.1:3306', 'write' = array( 'host' = '127.0.0.1:3306' 'database' = 'test', 'username' = 'root', 'password' = 'root', 'charset' = 'utf8', 'collation' = 'utf8_unicode_ci', 'prefix' = '', ),配置好之后,需要用到artisan工具,這是一個php命令工具在laravel目錄中首先需要要通過artisan建立一個遷移 migrate ,這點和asp.net mvc幾乎是一模一樣在laravel目錄中 shfit+右鍵打開命令窗口 輸入artisan migrate:make create_XXXX會在app/database/migrations文件下生成一個帶時間戳前綴的遷移文件代碼:use Illuminate/Database/Schema/Blueprint;use Illuminate/Database/Migrations/Migration;html' target='_blank'>class CreateTablenameTable extends Migration { * Run the migrations. * @return void public function up() * Reverse the migrations. * @return void public function down()}看到這里有entityframework 遷移經驗的基本上發現這是出奇的相似啊。接下來就是創建我們的實體結構,laravel 的結構生成器可以參考http://v4.golaravel.com/docs/4.1/schemause Illuminate/Database/Schema/Blueprint;use Illuminate/Database/Migrations/Migration;class CreateTablenameTable extends Migration { * Run the migrations. * @return void public function up() Schema::create('posts', function(Blueprint $table) { $table- increments('id'); $table- unsignedInteger('user_id'); $table- string('title'); $table- string('read_more'); $table- text('content'); $table- unsignedInteger('comment_count'); $table- timestamps(); Schema::create('comments', function(Blueprint $table) { $table- increments('id'); $table- unsignedInteger('post_id'); $table- string('commenter'); $table- string('email'); $table- text('comment'); $table- boolean('approved'); $table- timestamps(); Schema::table('users', function (Blueprint $table) { $table- create(); $table- increments('id'); $table- string('username'); $table- string('password'); $table- string('email'); $table- string('remember_token', 100)- nullable(); $table- timestamps(); * Reverse the migrations. * @return void public function down() Schema::drop('posts'); Schema::drop('comments'); Schema::drop('users');}繼續在上面的命令窗口輸入php artisan migrate 將執行遷移更多遷移相關知識:http://v4.golaravel.com/docs/4.1/migrations先寫到這里明天繼續PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桂平市| 宁化县| 进贤县| 湟中县| 湖口县| 淄博市| 湘乡市| 太康县| 锡林浩特市| 铜梁县| 昌乐县| 滕州市| 秦安县| 黔东| 香格里拉县| 惠水县| 阳城县| 兰溪市| 广饶县| 沁源县| 甘泉县| 天门市| 肇州县| 福鼎市| 册亨县| 渭南市| 云龙县| 汪清县| 隆德县| 东山县| 晋中市| 额济纳旗| 临沧市| 忻城县| 乌鲁木齐市| 沙雅县| 龙里县| 神农架林区| 麦盖提县| 安泽县| 商水县|