-
Notifications
You must be signed in to change notification settings - Fork 1
Models
Aurelijus edited this page Dec 16, 2019
·
3 revisions
Models are classes which you use to get data from database.
/* app/Topic.php */
<?php
namespace App;
use App\Core\Model;
class Topic extends model
{
// Default table name = 'class name'
protected static $table = "topics";
// Default primary key = 'id'
protected static $primary_key = "id";
}
/* app/controllers/TopicController.php */
<?php
namespace App\Controllers;
use App\Topic;
class TopicController extends controller
{
public function show($id) {
$topic = Topic::find($id);
var_dump($topic);
}
}
Every model must inherit base model!
- Model::find(table_primary_key);
- Model::where('row', 'value');