obsidian/MyObsidianVault/Knowledgebase/WebDev/2 CodeIgniter/API Project setup/05.) Create Domain Model+Controller+Migration.md

41 lines
683 B
Markdown
Raw Normal View History

2024-12-08 09:19:03 +01:00
```bash
php spark make:model Board --suffix
php spark make:controller Api/Board --suffix --restful
```
Add allowed fields to model:
(BoardModel.php)
```php
$allowedFields = ["name"];
```
```php
php spark make:migration create_boards
```
Migration file:
```php
//up:
$this->forge->addField([
"id" => [ "type"=>"INT", "constraint"=>5, "auto increment" => true, "unsigned" => true ],
"name" => [ "type"=>"VARCHAR", "constraint" => 120, "null" => false ]
]);
$this->forge->addPrimaryKey("id);
$this->forge->createTable("boards");
//down:
$this->forge->dropTable("boards");
```
```bash
php spark migrate:status
php spark migrate
```
Create seeder ?