Replace old structure with new structure
This commit is contained in:
65
app/Controller/ExampleController.php
Normal file
65
app/Controller/ExampleController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
use App\Model\ExampleModel;
|
||||
use Exception;
|
||||
|
||||
class ExampleController
|
||||
{
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Initialize the ExampleModel
|
||||
$this->model = new ExampleModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a new record to the database
|
||||
*
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function writeRecord(array $data): void
|
||||
{
|
||||
try {
|
||||
$this->model->insertRecord($data);
|
||||
} catch (Exception $e) {
|
||||
// Log the error or handle it as needed
|
||||
error_log("Error writing record: " . $e->getMessage());
|
||||
throw new Exception("Failed to write record.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all records from the database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllRecords(): array
|
||||
{
|
||||
try {
|
||||
return $this->model->fetchAllRecords();
|
||||
} catch (Exception $e) {
|
||||
// Log the error or handle it as needed
|
||||
error_log("Error fetching records: " . $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a record by ID
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
*/
|
||||
public function deleteRecord(int $id): void
|
||||
{
|
||||
try {
|
||||
$this->model->removeRecord($id);
|
||||
} catch (Exception $e) {
|
||||
// Log the error or handle it as needed
|
||||
error_log("Error deleting record: " . $e->getMessage());
|
||||
throw new Exception("Failed to delete record.");
|
||||
}
|
||||
}
|
||||
}
|
||||
47
app/Controller/ProjectController.php
Normal file
47
app/Controller/ProjectController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Model\ProjectModel;
|
||||
|
||||
class ProjectController {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Method to get all projects
|
||||
// This method is called by the router
|
||||
// and is used to get all projects from the database
|
||||
// and return them as JSON
|
||||
|
||||
public function getProject(): void
|
||||
{
|
||||
echo "This is the Table Project";
|
||||
echo "<br>";
|
||||
$model = new ProjectModel();
|
||||
$data = $model->readProject();
|
||||
|
||||
echo "<br>";
|
||||
|
||||
|
||||
// Display the data in a table format
|
||||
echo '<table border="1" cellpadding="5" cellspacing="0">';
|
||||
// Table header
|
||||
echo '<tr>';
|
||||
foreach (array_keys($data[0]) as $header) {
|
||||
echo '<th>' . htmlspecialchars($header) . '</th>';
|
||||
}
|
||||
echo '</tr>';
|
||||
// Table rows
|
||||
foreach ($data as $row) {
|
||||
echo '<tr>';
|
||||
foreach ($row as $cell) {
|
||||
echo '<td>' . htmlspecialchars($cell) . '</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user