Models - Icybrew/Stackoverflow-documentation GitHub Wiki

Models

Models are classes which you use to get data from database.

Example

/* 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);
    }
}

Important

Every model must inherit base model!


Currently supported methods

  • Model::find(table_primary_key);
  • Model::where('row', 'value');

You can always use DB::CLASS if additional functionality is needed!

See Database wiki