Commit be239af7 authored by Webserver User's avatar Webserver User

1.0.4

parent 1912e06f
# 1.0.4
## notes
* some directories moved to another place:
** moved /src into the /simplemvc
** moved /views to root
** /template moved and renamed to /public/templates{TemplateName}/
* redesign Controller, {page}.view.php get data from controller with $this (object) as $view
* changed 404.controller.php to notFound.controller.php
## added
-
## fixed
-
## removed
-
# 1.0.1
## notes
Now under the MIT License
......
......@@ -9,7 +9,9 @@ Perhaps the simplest and easiest PHP MVC framework in the world.
* page creator, create pages with controller and view fully automatically and iteratively
# next features
* MYSQL Adapter based on PDO
* Caching System
* Logging System
# documenation
https://gitlab.com/mascoda/simple-mvc/wikis/home
......
{
"name": "warzz/heiko.mettelsiefen",
"description": "startup lib and project",
"description": "simplemvc-skeleton",
"type": "library",
"license": "propietary",
"authors": [
......@@ -16,7 +16,8 @@
"autoload": {
"psr-4": {
"HM\\":"models/",
"simple\\":"simplemvc/"
"simple\\":"simplemvc/",
"simpleController\\":"controller/"
}
}
}
<?
$page->title = 'simple-mvc';
$page->template('custom');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/catalog/list/item";
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
$newPage = new simple\MVC($url);
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /render/views/blog.view.php (maybe for the list of all articles)
* /render/views/blog/article.view.php (a single blog post)
*
*/
# $newPage->create();
<?
namespace simpleController;
use simple;
use HM;
class indexController {
function __construct() {
}
public function index($page) {
$page->title = 'simple-mvc';
$page->template('default');
// send $this to the view
$this->view = "Hi, i am a view object";
$this->user = "I am a user!";
$this->dir = new HM\Dir('/path_to/MyNewDirectory');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/blog/article";
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
$newPage = new simple\MVC($url);
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /views/blog.view.php (maybe for list of all blog posts)
* /views/blog/article.view.php (a single blog post)
*
*/
#$newPage->create();
/*
*
* last steps
* go to you command line interface and register you new classes to composer
*
* $ composer dump-autoload -o
*
* Congratulations, thats all :-)
*
*/
}
}
<?
namespace simpleController;
use HM;
class notFoundController {
function __construct() {
}
public function notFound($page) {
$page->title = 'simple-mvc';
$page->template('custom');
// send $this to the view
$this->view = "send to the view";
$this->user = "I am a User";
$this->dir = new HM\Dir('test');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
#$url = "/catalog/list/item";
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
#$newPage = new simple\MVC($url);
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /render/views/blog.view.php (maybe for the list of all articles)
* /render/views/blog/article.view.php (a single blog post)
*
*/
# $newPage->create();
}
}
<?
#header('Content-Type: application/json');
\ No newline at end of file
#header('Content-Type: application/json');
// error_reporting(E_ALL);
error_reporting(E_ALL);
ini_set("display_errors", 1);
\ No newline at end of file
......@@ -6,11 +6,19 @@ require __DIR__ . '/vendor/autoload.php';
$page = new simple\MVC($_SERVER["SCRIPT_URL"]);
# show info about the $page object
# var_dump($page);
#var_dump($page);
if ($page->view === false) : header('Location: '.'/404'); endif;
if ($page->view->path === false) : header('Location: '.'/notFound'); endif;
require($page->controller);
// build view controller and call the page action
$controller = $page->controller->namespace . $page->controller->name;
$action = $page->controller->action;
// call the action
$view = new $controller;
$view->$action($page);
// render template and view
require($page->template);
......@@ -11,7 +11,7 @@
<body>
<? include($page->view); ?>
<? include($page->view->path); ?>
</body>
</html>
......
......@@ -12,7 +12,7 @@
<body>
<? include($page->view); ?>
<? include($page->view->path); ?>
</body>
</html>
......
......@@ -10,8 +10,11 @@ use HM;
* https://gitlab.com/mascoda/simple-mvc/wikis/home
*
*/
public $page;
public $page;
public $controller;
public $method;
public $template;
public $view;
......@@ -33,11 +36,11 @@ use HM;
function __construct($page, $template = 'default')
{
$this->page($page);
$this->controller();
$this->page($page);
$this->getController();
$this->template($template);
$this->view();
}
/*
* Page
......@@ -54,9 +57,11 @@ use HM;
*/
private function page($page)
{
# define page from the uri
$page = rtrim($page, '/');
# define page from the uri
$page = ltrim(rtrim($page, '/'), '/');
$this->page = ($page === '') ? 'index' : $page;
}
/**
* Controller
......@@ -72,11 +77,25 @@ use HM;
* -
*
*/
private function controller()
private function getController()
{
# define the first directory from path as controller
$controller = array_shift(array_filter(explode('/', $this->page)));
$this->controller = realpath(dirname(__DIR__) . '/controller/' . $controller .'.controller.php');
# define the first directory from path as controller
$action = array_filter(explode('/', $this->page));
$action = end($action);
$controller = array_filter(explode('/', $this->page));
$controller = array_shift($controller);
$this->controller = (object)
array(
'path' => realpath(dirname(__DIR__) . '/controller/' . $controller . '.controller.php'),
'file' => $controller . '.controller.php',
'name' => $controller . 'Controller',
'action' => $action,
'namespace' => 'simpleController\\'
);
}
/**
* View
......@@ -98,8 +117,12 @@ use HM;
*/
private function view()
{
# create the template
$this->view = realpath(dirname(__DIR__) . '/render/views/' . $this->page . '.view.php');
$this->view = (object)
array(
'path' => realpath(dirname(__DIR__) . '/views/' . $this->page . '.view.php'),
'file' => $this->page . '.view.php',
'name' => $this->page
);
}
/**
* View
......@@ -118,7 +141,7 @@ use HM;
public function template($template)
{
# create the template
$this->template = dirname(__DIR__) . '/render/template/' . $template .'.template.php';
$this->template = dirname(__DIR__) . '/public/templates/' . $template .'/' . $template . '.template.php';
}
/**
......@@ -142,44 +165,48 @@ use HM;
public function create()
{
// need for subdirectories
$path_to = '';
// get pages of the given path (removed slashes)
$pages = explode('/', rtrim(ltrim($this->page, '/'),'/'));
// create directories for the views recursively
$viewDirectory = new HM\Dir(dirname(dirname(__DIR__) . '/render/views/' . $this->page));
if (!$viewDirectory->exists()) :
$viewDirectory->create($mode = 0775, $recursive = true);
endif;
// need for subdirectories
$path_to = '';
// created controller and views
foreach ($pages as $page) :
// get pages of the given path (removed slashes)
$pages = explode('/', rtrim(ltrim($this->page, '/'),'/'));
// create controller
$controller = new HM\File(dirname(__DIR__) . '/controller/' . $pages[0] .'.controller.php');
if (!$controller->exists()) :
$defaultController = SRC::getContent('controller', 'default.controller.php');
$search = array('{controllerName}', '{actionName}');
$replace = array($pages[0] . 'Controller', $pages[0]);
$defaultController = str_replace($search, $replace, $defaultController);
$controller->write($defaultController);
endif;
// create directories for the views recursively
$viewDirectory = new HM\Dir(dirname(dirname(__DIR__) . '/views/' . $this->page));
if (!$viewDirectory->exists()) :
$viewDirectory->create($mode = 0775, $recursive = true);
endif;
// init a new page
$page = new MVC($page);
// created controller and views
foreach ($pages as $page) :
// create controller
$controller = new HM\File(dirname(__DIR__) . '/controller/' . $page->page .'.controller.php');
if (!$controller->exists()) :
$controller->write(SRC::getContent('controller', 'default.controller.php'));
endif;
// init a new page
$page = new MVC($page);
// create views
$view = new HM\File(dirname(__DIR__) . '/render/views/' . $path_to . $page->page . '.view.php');
if (!$view->exists()) :
$view->create($mode = 0755);
$view->write(SRC::getContent('views', 'default.view.php'));
endif;
// create views
$view = new HM\File(dirname(__DIR__) . '/views/' . $path_to . $page->page . '.view.php');
if (!$view->exists()) :
$view->create($mode = 0755);
$view->write(SRC::getContent('views', 'default.view.php'));
endif;
// extend the path for viewfiles
$path_to .= $page->page . '/';
// extend the path for viewfiles
$path_to .= $page->page . '/';
endforeach;
endforeach;
// replace placeholder
#$file->write(str_replace('{TITLE}' , basename($file->path), file_get_contents(dirname(__DIR__) . '/render/template/default.view.php')));
// replace placeholder
#$file->write(str_replace('{TITLE}' , basename($file->path), file_get_contents(dirname(__DIR__) . '/render/template/default.view.php')));
}
}
\ No newline at end of file
......@@ -44,6 +44,6 @@ namespace simple;
*/
public static function getContent($path, $filename)
{
return file_get_contents(dirname(__DIR__) . '/src/' . $path . '/' . $filename);
return file_get_contents(dirname(__DIR__) . '/simplemvc/src/' . $path . '/' . $filename);
}
}
\ No newline at end of file
public function {actionName} ($page) {
$page->title = 'simple-mvc';
$page->template('default');
// send $this to the view
$this->view = "Hi, i am a view object";
$this->user = "I am a user!";
$this->dir = new HM\Dir('/path_to/MyNewDirectory');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/index/item";
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
$newPage = new simple\MVC($url);
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /render/views/blog.view.php (maybe for the list of all articles)
* /render/views/blog/article.view.php (a single blog post)
*
*/
#$newPage->create();
}
<?
namespace simpleController;
use simple;
use HM;
class {controllerName} {
function __construct() {
}
public function {actionName} ($page) {
$page->title = 'simple-mvc';
$page->template('default');
// send $this to the view
$this->view = "Hi, i am a view object";
$this->user = "I am a user!";
$this->dir = new HM\Dir('/path_to/MyNewDirectory');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/blog/article";
/*
* second step, build a MVC object with the uri as parameter
* !Note: do not use the variable $page to create new pages, this will overwrite the current object
*/
$newPage = new simple\MVC($url);
/*
* third step, create page
* this will generated follow files:
*
* /controller/blog.controller.php
* /views/blog.view.php (maybe for list of all blog posts)
* /views/blog/article.view.php (a single blog post)
*
*/
#$newPage->create();
/*
*
* last steps
* go to you command line interface and register you new classes to composer
*
* $ composer dump-autoload -o
*
* Congratulations, thats all :-)
*
*/
}
}
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5"><?= $page->view->file; ?></h1>
<p class="lead">
Getting started, open <strong><i>/controller/<?= $page->controller->file; ?></i></strong>
and modifiy function <strong><i><?= $page->controller->action; ?></i></strong>!
</p>
<p>Catch easy data from controller with <i>$this</i></p>
<P><pre><? var_dump($view) ?></pre></P>
<p>powered by <a href="https://gitlab.com/mascoda/simple-mvc">simple-mvc</a></p>
</div>
</main>
\ No newline at end of file
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">{TITLE}</h1>
<p class="lead">A new space for awesome content.</p>
<p>Use <a href="/docs/4.3/examples/sticky-footer-navbar/">the sticky footer with a fixed navbar</a> if need be, too.</p>
</div>
</main>
\ No newline at end of file
......@@ -8,6 +8,9 @@ $baseDir = dirname($vendorDir);
return array(
'HM\\Dir' => $baseDir . '/models/Dir.class.php',
'HM\\File' => $baseDir . '/models/File.class.php',
'simpleController\\blogController' => $baseDir . '/controller/blog.controller.php',
'simpleController\\indexController' => $baseDir . '/controller/index.controller.php',
'simpleController\\notFoundController' => $baseDir . '/controller/notFound.controller.php',
'simple\\MVC' => $baseDir . '/simplemvc/MVC.class.php',
'simple\\SRC' => $baseDir . '/simplemvc/SRC.class.php',
);
......@@ -7,5 +7,6 @@ $baseDir = dirname($vendorDir);
return array(
'simple\\' => array($baseDir . '/simplemvc'),
'simpleController\\' => array($baseDir . '/controller'),
'HM\\' => array($baseDir . '/models'),
);
......@@ -10,6 +10,7 @@ class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c
's' =>
array (
'simple\\' => 7,
'simpleController\\' => 17,
),
'H' =>
array (
......@@ -22,6 +23,10 @@ class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c
array (
0 => __DIR__ . '/../..' . '/simplemvc',
),
'simpleController\\' =>
array (
0 => __DIR__ . '/../..' . '/controller',
),
'HM\\' =>
array (
0 => __DIR__ . '/../..' . '/models',
......@@ -31,6 +36,9 @@ class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c
public static $classMap = array (
'HM\\Dir' => __DIR__ . '/../..' . '/models/Dir.class.php',
'HM\\File' => __DIR__ . '/../..' . '/models/File.class.php',
'simpleController\\blogController' => __DIR__ . '/../..' . '/controller/blog.controller.php',
'simpleController\\indexController' => __DIR__ . '/../..' . '/controller/index.controller.php',
'simpleController\\notFoundController' => __DIR__ . '/../..' . '/controller/notFound.controller.php',
'simple\\MVC' => __DIR__ . '/../..' . '/simplemvc/MVC.class.php',
'simple\\SRC' => __DIR__ . '/../..' . '/simplemvc/SRC.class.php',
);
......
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">index.view.php</h1>
<p class="lead">Getting start, look at <i>/controller/index.controller.php</i> to create more pages!</p>
<h1 class="mt-5"><?= $page->view->file; ?></h1>
<p class="lead">
Getting started, open <strong><i>/controller/<?= $page->controller->file; ?></i></strong>
and modifiy function <strong><i><?= $page->controller->action; ?></i></strong>!
</p>
<p>Catch easy data from controller with <i>$this</i></p>
<P><pre><? var_dump($view) ?></pre></P>
<p>powered by <a href="https://gitlab.com/mascoda/simple-mvc">simple-mvc</a></p>
</div>
</main>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment