Replace old structure with new structure
This commit is contained in:
55
app/Model/ExampleModel.php
Normal file
55
app/Model/ExampleModel.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace App\Model;
|
||||
|
||||
class ExampleModel
|
||||
{
|
||||
private $records = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Initialize with some example data
|
||||
$this->records = [
|
||||
['id' => 1, 'name' => 'Example 1', 'value' => 100],
|
||||
['id' => 2, 'name' => 'Example 2', 'value' => 200],
|
||||
['id' => 3, 'name' => 'Example 3', 'value' => 300],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new record into the example data
|
||||
*
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function insertRecord(array $data): void
|
||||
{
|
||||
$this->records[] = [
|
||||
'id' => count($this->records) + 1,
|
||||
'name' => $data['name'] ?? 'Unnamed',
|
||||
'value' => $data['value'] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all records from the example data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAllRecords(): array
|
||||
{
|
||||
return $this->records;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a record by ID from the example data
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
*/
|
||||
public function removeRecord(int $id): void
|
||||
{
|
||||
$this->records = array_filter($this->records, function ($record) use ($id) {
|
||||
return $record['id'] !== $id;
|
||||
});
|
||||
}
|
||||
}
|
30
app/Model/ProjectModel.php
Normal file
30
app/Model/ProjectModel.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace App\Model;
|
||||
|
||||
use App\Config\Database;
|
||||
use ppb\Library\Msg;
|
||||
|
||||
class ProjectModel extends Database
|
||||
{
|
||||
public function readProject()
|
||||
{
|
||||
$pdo = $this->linkDB();
|
||||
$sql = "SELECT id, name FROM project";
|
||||
|
||||
try {
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
} catch (\PDOException $e) {
|
||||
new Msg(true, null, $e);
|
||||
}
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
|
||||
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$sth->closeCursor();
|
||||
$pdo = null;
|
||||
// fetch all
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user