diff --git a/console/Generator/ViewsGenerator.php b/console/Generator/ViewsGenerator.php index 9a20b58..bda5d04 100644 --- a/console/Generator/ViewsGenerator.php +++ b/console/Generator/ViewsGenerator.php @@ -154,24 +154,27 @@ protected static function index(string $table, array $attributes) $current .= File::nl(4, '') . File::nl( 5, - 'View' + . self::$_entities[$table]->getPrimary() . ']) ?>' ) . File::nl( 5, - 'Update' + . self::$_entities[$table]->getPrimary() . ']) ?>' ) . File::nl( 5, - 'Delete' + . self::$_entities[$table]->getPrimary() . ']) ?>' ) . File::nl(4, '') . File::nl(3, '') diff --git a/index.php b/index.php index d1f5b41..97484de 100644 --- a/index.php +++ b/index.php @@ -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 */ diff --git a/src/Helper/Helper.php b/src/Helper/Helper.php new file mode 100644 index 0000000..ed6dab6 --- /dev/null +++ b/src/Helper/Helper.php @@ -0,0 +1,18 @@ + + * @license http://www.opensource.org/licenses/mit-license.php MIT License + * @link https://github.com/tatooine-coders/simple-php-framework/ + */ +abstract class Helper +{ + +} diff --git a/src/Helper/HtmlHelper.php b/src/Helper/HtmlHelper.php new file mode 100644 index 0000000..bce8057 --- /dev/null +++ b/src/Helper/HtmlHelper.php @@ -0,0 +1,66 @@ + + * @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 '' . $title . ''; + } + + /** + * 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; + } +} diff --git a/src/Model/Collection/Collection.php b/src/Model/Collection/Collection.php index be086af..eb837b7 100755 --- a/src/Model/Collection/Collection.php +++ b/src/Model/Collection/Collection.php @@ -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); diff --git a/src/Model/Entity/Entity.php b/src/Model/Entity/Entity.php index 80e92ce..664b320 100755 --- a/src/Model/Entity/Entity.php +++ b/src/Model/Entity/Entity.php @@ -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); diff --git a/src/View/View.php b/src/View/View.php index 8b7843b..b025e09 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -1,6 +1,8 @@ Html=new HtmlHelper; + // Create path $filename = './app/View/' . $template . '.php'; if (file_exists($filename)) { diff --git a/src/test/Helper/HtmlHelperTest.php b/src/test/Helper/HtmlHelperTest.php new file mode 100644 index 0000000..7e0a90d --- /dev/null +++ b/src/test/Helper/HtmlHelperTest.php @@ -0,0 +1,40 @@ + + * @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(); + } +}