protected function init_model() { $model = new Model_Log_SQLite($this->config, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); if (!$model->create_table_if_not_exists()) { throw new Exception('For some reason the table in SQLite database can not be created'); } $model->create_indexes_if_not_exists(); return $model; }
protected function action_index() { try { if (!($post = $this->request->post())) { // Returns only static template return $this->action_media($this->dir, $this->template); } $json = json_decode($post['json']); $file_path = realpath($this->config['directory']) . DIRECTORY_SEPARATOR . $this->config['filename']; if (!file_exists($file_path)) { return $this->send_json_msg('success', "<strong>SQLite3:</strong> database not exists in <i>{$file_path}</i>.<br><br>" . "(It is created automatically if required)"); } $model = new Model_Log_SQLite($this->config, SQLITE3_OPEN_READONLY); if (!$model->check_if_exitsts_table()) { return $this->send_json_msg('success', "<strong>SQLite3:</strong> Table <i>" . $this->config['tablename'] . "</i> not exists in database <i>{$file_path}</i><br><br>" . "(It is created automatically if required)"); } $this->response->headers('Content-Type', 'application/json; charset=utf-8')->body(json_encode($model->select($json), JSON_HEX_AMP)); } catch (Exception $e) { if (!$this->request->post()) { throw $e; } $this->send_json_msg('danger', "<strong>PHP Exception:</strong> {$e->getMessage()}<br>in {$e->getFile()}:{$e->getLine()}<br><br>" . "<strong>Debug:</strong><br>" . "<span style=\"white-space: pre-line;\">{$e->getTraceAsString()}</span>"); } }