Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developed #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
view & controller modified
Arif-Shahriar028 committed Mar 26, 2024
commit a921d9cccb267da027d024f61d402db73d3eb843
17 changes: 7 additions & 10 deletions controller/aboutUsPage.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?php

class AboutController
class AboutController extends Controller
{
// @TODO add defaultAction function

/**
* @function showPageAction() return the expected about-us-page
*/
function showPageAction()
function defaultAction()
{
require_once("view/about-us-page.html");
echo "about controller";
$variables['title'] = 'About Us';
$variables['content'] = 'We are the developers';
$template = new Template('default');
$template->view('static-page', $variables);
}
}


// require_once("view/about-us-page.html");
53 changes: 41 additions & 12 deletions controller/contactPage.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
<?php

require("src/Controller.php");
// require("src/Controller.php");
class ContactController extends Controller
{


function defaultAction()
{
require("view/contact-page.html");
$variables['inputOneLabel'] = 'Your Message';
$variables['inputTwoLabel'] = 'You Email';
$variables['buttonText'] = 'Submit';
$template = new Template('default');
$template->view('contact/contact-page', $variables);
}
/**
* @function showPageAction includes views on condition
*/
function showPageAction($action)


function runBeforeAction()
{
if ($action == 'show') {
require("view/contact-page.html");
} else if ($action == 'submit') {
require("view/contact-us-thank-you.html");
} else {
echo $action;
if ($_SESSION['has_submitted_form'] ?? 0 == 1) {
$variables['title'] = 'Already Submitted';
$variables['content'] = 'You already submitted a message to us. We will try to reach you as soon as possible!';
$template = new Template('default');
$template->view('static-page', $variables);
return true;
}
return false;
}

function submitContactFormAction()
{
$variables['title'] = 'Thank You Contacting Us!';
$variables['content'] = 'We will try to reach you as soon as possible!';
$template = new Template('default');
$template->view('static-page', $variables);
$_SESSION['has_submitted_form'] = 1;
}


/**
* @method showPageAction includes views on condition
*/
// function showPageAction($action)
// {
// if ($action == 'show') {
// require("view/contact-page.html");
// } else if ($action == 'submit') {
// require("view/contact-us-thank-you.html");
// } else {
// echo $action;
// }
// }
}
12 changes: 11 additions & 1 deletion controller/homePage.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<?php

require_once("view/home-page.html");
// require("src/Controller.php");
class HomeController extends Controller
{
function defaultAction()
{
$variables['title'] = 'Home Page';
$variables['content'] = 'You are on the home page. Welcome!';
$template = new Template('default');
$template->view('static-page', $variables);
}
}
20 changes: 11 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?php

session_start();

include "src/template.php";
include "src/controller.php";

$section = $_GET['section'] ?? $_POST['section'] ?? 'home-page';
$action = $_GET['action'] ?? $_POST['action'] ?? 'default';

/**
* @param $section = 'home-page', execute the else-if block
*/
if ($section == 'home-page') {
require_once("./controller/homePage.php");
}

/**
* @param $section = 'contact-page', execute the else-if block
*/
else if ($section == 'contact-page') {
if ($section == 'contact-page') {
require_once("./controller/contactPage.php");
$contactController = new ContactController();
$contactController->runAction($action);
@@ -26,12 +24,16 @@
else if ($section == 'about-us') {
require_once("./controller/aboutUsPage.php");
$aboutCrontroller = new AboutController();
$aboutCrontroller->showPageAction();
$aboutCrontroller->runAction($action);
}

/**
* Default condition block, include home-page
*
* @param $section = 'home-page', execute the else-if block
*/
else {
require_once("./controller/homePage.php");
$homeController = new HomeController();
$homeController->runAction($action);
}
10 changes: 10 additions & 0 deletions src/Controller.php → src/controller.php
Original file line number Diff line number Diff line change
@@ -4,10 +4,20 @@ class Controller
{
function runAction($actionName)
{

if (method_exists($this, 'runBeforeAction')) {
$result = $this->runBeforeAction();
if ($result) {
return;
}
}

$actionName .= 'Action';

if (method_exists($this, $actionName)) {
$this->$actionName();
} else {
// var_dump($actionName);
require_once("view/status-pages/404.html");
}
}
17 changes: 17 additions & 0 deletions src/template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Template
{
private $layout;

function __construct($layout)
{
$this->layout = $layout;
}

function view($template, $variables)
{
extract($variables);
include "view/layout/" . $this->layout . ".html";
}
}
114 changes: 0 additions & 114 deletions view/contact-page.html

This file was deleted.

Loading