1: <?php
2: /**
3: * @filesource Kotchasan/Model.php
4: *
5: * @copyright 2016 Goragod.com
6: * @license http://www.kotchasan.com/license/
7: *
8: * @see http://www.kotchasan.com/
9: */
10:
11: namespace Kotchasan;
12:
13: use Kotchasan\Database\Query;
14:
15: /**
16: * Model base class
17: *
18: * @author Goragod Wiriya <admin@goragod.com>
19: *
20: * @since 1.0
21: */
22: class Model extends Query
23: {
24: /**
25: * ชื่อของการเชื่อมต่อ ใช้สำหรับโหลด config จาก settings/database.php
26: *
27: * @var string
28: */
29: protected $conn = 'mysql';
30:
31: /**
32: * Class constructor
33: */
34: public function __construct()
35: {
36: parent::__construct($this->conn);
37: }
38:
39: /**
40: * create Model
41: *
42: * @return \static
43: */
44: public static function create()
45: {
46: return new static();
47: }
48:
49: /**
50: * create Database connection.
51: *
52: * @return \Kotchasan\Database\Driver
53: */
54: public static function createDb()
55: {
56: $model = new static();
57: return $model->db();
58: }
59:
60: /**
61: * create QueryBuilder
62: *
63: * @return \Kotchasan\Database\QueryBuilder
64: */
65: public static function createQuery()
66: {
67: $model = new static();
68: return $model->db()->createQuery();
69: }
70: }
71: