Skip to content
This repository was archived by the owner on May 22, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 12 additions & 9 deletions console/Generator/ViewsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,27 @@ protected static function index(string $table, array $attributes)
$current .= File::nl(4, '<td>')
. File::nl(
5,
'<a href="/' . $table . '/view?'
. self::$_entities[$table]->getPrimary() . '=<?php echo $'
'<?php echo $this->Html->link(\'View\', [\'controller\' => \'' . $table . '\', '
. '\'action\' => \'view\', '
. '\'' . self::$_entities[$table]->getPrimary() . '\' => $'
. Str::singularize($table) . '->'
. self::$_entities[$table]->getPrimary() . '?>">View</a>'
. self::$_entities[$table]->getPrimary() . ']) ?>'
)
. File::nl(
5,
'<a href="/' . $table . '/update?'
. self::$_entities[$table]->getPrimary() . '=<?php echo $'
'<?php echo $this->Html->link(\'Update\', [\'controller\' => \'' . $table . '\', '
. '\'action\' => \'update\', '
. '\'' . self::$_entities[$table]->getPrimary() . '\' => $'
. Str::singularize($table) . '->'
. self::$_entities[$table]->getPrimary() . '?>">Update</a>'
. self::$_entities[$table]->getPrimary() . ']) ?>'
)
. File::nl(
5,
'<a href="/' . $table . '/delete?'
. self::$_entities[$table]->getPrimary() . '=<?php echo $'
'<?php echo $this->Html->link(\'Delete\', [\'controller\' => \'' . $table . '\', '
. '\'action\' => \'delete\', '
. '\'' . self::$_entities[$table]->getPrimary() . '\' => $'
. Str::singularize($table) . '->'
. self::$_entities[$table]->getPrimary() . '?>">Delete</a>'
. self::$_entities[$table]->getPrimary() . ']) ?>'
)
. File::nl(4, '</td>')
. File::nl(3, '</tr>')
Expand Down
10 changes: 10 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
*/
require_once('vendor/autoload.php');

/*
* Constants
*/
// App base, in the filesystem
define('__APP_BASE__', 'appbase');
// App folder in the filesystem
define('__APP__', __APP_BASE__.'app');
// App absolute URL
define('__APP_URL__', str_replace('index.php', '', $_SERVER['PHP_SELF']));

/*
* Load the configuration
*/
Expand Down
18 changes: 18 additions & 0 deletions src/Helper/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace TC\Helper;

/**
* This file is part of the Simple PHP Framework
*
* Main helper class
*
* @category Helper
* @package TC
* @author Manuel Tancoigne <m.tancoigne@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @link https://github.com/tatooine-coders/simple-php-framework/
*/
abstract class Helper
{

}
66 changes: 66 additions & 0 deletions src/Helper/HtmlHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
namespace TC\Helper;

use TC\Helper\Helper;
use TC\Lib\Config;
use TC\Lib\Str;
use const APP_URL;

/**
* This file is part of the Simple PHP Framework
*
* Html helper
*
* @category Helper
* @package TC
* @author Manuel Tancoigne <m.tancoigne@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @link https://github.com/tatooine-coders/simple-php-framework/
*/
class HtmlHelper extends Helper
{

/**
* Creates an HTML link to the given route
*
* @param string $title Link content
* @param string|array $route Route to target. If a string is given, the string will be returned
* @param array $options Not used yet
*
* @return string
*/
public function link(string $title, $route = null, array $options = [])
{
return '<a href="' . (is_array($route) ? $this->url($route) : $route) . '">' . $title . '</a>';
}

/**
* Generates a route with the given array of controller/action/params
*
* @param array $route Target route
*
* @return string
*/
public function url(array $route = [])
{
$defaults = [
'controller' => Config::get('defaultRoute.controller'),
'action' => Config::get('defaultRoute.action')
];

$route += $defaults;
// Creating URL
$base = __APP_URL__ . Str::underscore($route['controller']) . '/' . Str::underscore($route['action']);
$paramsList = [];
unset($route['action']);
unset($route['controller']);
foreach ($route as $k => $v) {
$paramsList[] = $k . '=' . $v;
}

if (count($paramsList) > 0) {
$base .= '?' . implode('&', $paramsList);
}
return $base;
}
}
2 changes: 1 addition & 1 deletion src/Model/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function fetchAll()
$statement = DB::c()->prepare($query);
$statement->execute();

$statement->setFetchMode(PDO::FETCH_OBJ);
$statement->setFetchMode(PDO::FETCH_ASSOC);
// Entity name
$entity = Str::entityName($this->_table, true);

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function fetch($id)
$statement->bindParam('id', $id);

$statement->execute();
$statement->setFetchMode(PDO::FETCH_OBJ);
$statement->setFetchMode(PDO::FETCH_ASSOC);
$row = $statement->fetch();
if (!empty($row)) {
$this->set($row, true);
Expand Down
6 changes: 6 additions & 0 deletions src/View/View.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace TC\View;

use TC\Helper\HtmlHelper;

/**
* This file is part of the Simple PHP Framework
*
Expand All @@ -26,6 +28,10 @@ class View
public function render(string $template, array $variables)
{
extract($variables);

// Add helpers
$this->Html=new HtmlHelper;

// Create path
$filename = './app/View/' . $template . '.php';
if (file_exists($filename)) {
Expand Down
40 changes: 40 additions & 0 deletions src/test/Helper/HtmlHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace TC\Test\Helper;

use PHPUnit\Framework\TestCase;
use TC\Helper\HtmlHelper;

/**
* This file is part of the Simple PHP Framework
*
* HtmlHelper class tests
*
* @category Test
* @package TC
* @author Manuel Tancoigne <m.tancoigne@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @link https://github.com/tatooine-coders/simple-php-framework/
*/
class HtmlHelperTest extends TestCase
{

/**
* Test for the url() method
*
* @return void
*/
public function testUrl()
{
$this->markTestIncomplete();
}

/**
* Test for the link() method
*
* @return void
*/
public function testLink()
{
$this->markTestIncomplete();
}
}