data save
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
@@ -27,7 +29,7 @@ abstract class BaseController extends Controller
|
||||
* @var CLIRequest|IncomingRequest
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
use ResponseTrait;
|
||||
/**
|
||||
* An array of helpers to be loaded automatically upon
|
||||
* class instantiation. These helpers will be available
|
||||
@@ -35,6 +37,8 @@ abstract class BaseController extends Controller
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $db;
|
||||
private $con_name = 'digifi_db'; // 'wrench_blog';
|
||||
protected $helpers = [];
|
||||
|
||||
/**
|
||||
@@ -54,5 +58,22 @@ abstract class BaseController extends Controller
|
||||
// Preload any models, libraries, etc, here.
|
||||
|
||||
// E.g.: $this->session = \Config\Services::session();
|
||||
|
||||
try {
|
||||
$this->db = \Config\Database::connect($this->con_name);
|
||||
} catch (Exception $e) {
|
||||
echo 'Caught Data Connect Exception ::: ', $e->getMessage(), "\n";
|
||||
}
|
||||
}
|
||||
|
||||
protected function insert_db($table_name, $insert_data) : array{
|
||||
$row = [];
|
||||
$this->db->table($table_name)->insert($insert_data);
|
||||
|
||||
$query = $this->db->query("SELECT * FROM $table_name ORDER BY id DESC LIMIT 1");
|
||||
$row = $query->getRowArray();
|
||||
// echo $row->name;
|
||||
return $row;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user