Laravel框架学习笔记(二)项目实战之模型(Models),laravelmodels
Jun 13, 2016 am 09:23 AMLaravel框架学习笔记(二)项目实战之模型(Models),laravelmodels
在开发mvc项目时,models都是第一步。
下面就从建模开始。
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文件下生成一个带时间戳前缀的迁移文件
代码:
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; 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/schema
<?php use 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
先写到这里明天继续

인기 기사

인기 기사

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











세계에서 가장 강력한 오픈 소스 MoE 모델이 여기에 있습니다. 중국의 기능은 GPT-4와 비슷하며 가격은 GPT-4-Turbo의 거의 1%에 불과합니다.

MLP를 대체하는 KAN은 오픈소스 프로젝트를 통해 컨볼루션으로 확장되었습니다.

Google은 열광하고 있습니다. JAX 성능이 Pytorch와 TensorFlow를 능가합니다! GPU 추론 훈련을 위한 가장 빠른 선택이 될 수 있습니다.

AI가 수학적 연구를 전복시킨다! 필즈상 수상자이자 중국계 미국인 수학자, Terence Tao가 좋아하는 11개 논문 발표 |

안녕하세요, 일렉트릭 아틀라스입니다! 보스턴 다이나믹스 로봇 부활, 180도 이상한 움직임에 겁먹은 머스크

시계열 예측 + NLP 대규모 모델에 대한 새로운 작업: 시계열 예측을 위한 암시적 프롬프트 자동 생성

FisheyeDetNet: 어안 카메라를 기반으로 한 최초의 표적 탐지 알고리즘

공장에서 일하는 테슬라 로봇, 머스크 : 올해 손의 자유도가 22도에 달할 것!
