Commit b1702db6 authored by Webserver User's avatar Webserver User

read the readme

parent 3b8c8ff5
MIT License
Copyright (c) 2019 Heiko Mettelsiefen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# 1.0.1
## notes
Now under the MIT License
## added
* page creator, create pages easy with the page creator
* 404 routing with a standard error page
* source class, handle framework components like default.view.php
* mini tutorial on the index page
## fixed
-
## removed
-
# 1.0.0
## notes
Initial commit simple-mvc
Perhaps the simplest and easiest MVC framework in the world.
## added
* complete framework
## fixed
-
## removed
-
......@@ -11,10 +11,14 @@ Perhaps the simplest and easiest PHP MVC framework in the world.
* page creator, create pages with controller and view fully automatically and iteratively
# documenation
coming soon
https://gitlab.com/mascoda/simple-mvc/wikis/home
# copyrights
licenses under MIT
developed by <heiko@mybannerworld.com>
in Hamburg, Germany
feel free to contact me
\ No newline at end of file
feel free to contact me
# download
https://gitlab.com/mascoda/simple-mvc
......@@ -5,7 +5,8 @@ namespace HM;
/**
* Generate page with controller and view
*
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
*
*/
public $page;
......@@ -137,39 +138,47 @@ namespace HM;
* -
*
*/
private function create($page)
public function create()
{
$path_to = "";
$pages = explode('/', $page);
#if (count($pages)>0) :
$pages = array_filter($pages);
#endif;
$this->controller = realpath(__DIR__ . '/../controller/' . current($pages) .'.controller.php');
// need for subdirectories
$path_to = '';
// get pages of the given path (removed slashes)
$pages = explode('/', rtrim(ltrim($this->page, '/'),'/'));
// current path
$this->page = substr($page,1);
// create directory if not exists
$path = new Dir(dirname(dirname(__DIR__) . '/render/views/' . $this->page));
if ($path->exists() === false) :
$path->create($mode = 0777, $recursive = true);
// create directories for the views recursively
$viewDirectory = new Dir(dirname(dirname(__DIR__) . '/render/views/' . $this->page));
if (!$viewDirectory->exists()) :
$viewDirectory->create($mode = 0775, $recursive = true);
endif;
// create views, if not exists
foreach ($pages as $page):
$file = new File(dirname(__DIR__) . '/render/views/' . $path_to . $page . '.view.php');
// created controller and views
foreach ($pages as $page) :
// init a new page
$page = new MVC($page);
if ($file->exists() === false) :
$file->create($mode = 0777, $recursive = true);
$file->write(str_replace('{TITLE}' , basename($file->path), file_get_contents(dirname(__DIR__) . '/render/template/default.view.php')));
endif;
// create controller
$controller = new File(dirname(__DIR__) . '/controller/' . $page->page .'.controller.php');
if (!$controller->exists()) :
$controller->write(SRC::getContent('controller', 'default.controller.php'));
endif;
// create views
$view = new 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;
// extend the path for viewfiles
$path_to .= $page->page . '/';
endforeach;
$path_to .= $page . '/';
endforeach;
// 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
<?
namespace HM;
class SRC {
/**
* Deliver sources from src directory
*
* @description
* https://gitlab.com/mascoda/simple-mvc/wikis/home
*
*/
public $path;
public $filename;
/*
* Constructor
*
* @description
* -
*
* @param
* -
*
* @return
* -
*
*/
function __construct()
{
// tbd
}
/*
* getContent
*
* @description
* get content from files in the src directory
*
* @param
* path (string)
* filename (string)
*
* @return
* content (string)
*
*/
public static function getContent($path, $filename)
{
return file_get_contents(dirname(__DIR__) . '/src/' . $path . '/' . $filename);
}
}
\ No newline at end of file
<?
$page->title = 'pagetitle';
$page->template('custom');
$array = array('Key' => 'Value');
$dir = new HM\Dir(__DIR__ . '/test');
<?
$page->title = 'console';
$page->template('custom');
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/items/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 HM\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();
<?
/*
$file = new HM\File($dir->path . '/test2.json');
$page->title = 'simple-mvc';
$page->template('default');
if ($file->exists() === false) :
$file->create();
endif;
$info = new SplFileObject($file->path);
/* How to create a new page
* create a new page included controller and views
*
* first step, define the page / url
*
*/
$url = "/items/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 HM\MVC($url);
HM\Log::debug('hi');
*/
\ No newline at end of file
/*
* 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();
\ No newline at end of file
<?
$dir = new HM\Dir(__DIR__ . '/../media/files', 0777, TRUE);
if ($dir->exists() === false) :
$dir->create();
endif;
$A = "A";
#echo "controller";
#echo $dir->path;
HM\MVC::render();
/*
$file = new HM\File($dir->path . '/test2.json');
if ($file->exists() === false) :
$file->create();
endif;
$info = new SplFileObject($file->path);
HM\Log::debug('hi');
*/
?>
\ No newline at end of file
favicon.ico

10.7 KB

......@@ -5,9 +5,12 @@ require __DIR__ . '/vendor/autoload.php';
$page = new HM\MVC($_SERVER["SCRIPT_URL"]);
#var_dump($page);
# show info about the $page object
# var_dump($page);
if ($page->view === false) : header('Location: '.'/404'); endif;
if ($page->view === false) : header('Location: '.'/404'); endif;
require($page->controller);
require($page->template);
\ No newline at end of file
require($page->template);
<!doctype html>
<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/cerulean/bootstrap.min.css" rel="stylesheet">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
......
......@@ -2,7 +2,7 @@
<div class="container">
<h1 class="mt-5">404</h1>
<p class="lead">not found</p>
<p>Use <a href="/index">Go to start</a></p>
<p><a href="/index">Go to index</a></p>
</div>
</main>
......
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">catalog.view.php</h1>
<p class="lead"><? var_dump($array); ?><? var_dump($page); ?><?= "hi"; ?><?= $template; ?> a footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS.</p>
<p>-----------</p>
<p>Test: $dir = new HM\Dir() : <?= $dir->path; ?></p>
<p>Page object <pre><? var_dump($page); ?></pre></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
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">show.view.php</h1>
<p>Page object <pre><? var_dump($page); ?></pre></p>
<h1 class="mt-5">console.view.php</h1>
<p class="lead">Console: </p>
<p class="card"><pre><? var_dump($newPage) ?></pre></p>
</div>
</main>
\ No newline at end of file
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">docs.view.php</h1>
<p class="lead">Pin a footer to the bottom of the viewport in desktop browsers with this custom HTML and CSS.</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
<main role="main" class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">index.view.php</h1>
<p class="lead"><? var_dump($dir); ?></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>
<p class="lead">Getting start, look at <i>/controller/index.controller.php</i> to create more pages!</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">shop.view.php</h1>
<p class="lead"><? echo $A; ?></p>
<p><? echo $dir->path; HM\Log::debug($dir->path); echo $A; ?> b</p>
</div>
</main>
\ No newline at end of file
......@@ -8,6 +8,6 @@ $baseDir = dirname($vendorDir);
return array(
'HM\\Dir' => $baseDir . '/classes/Dir.class.php',
'HM\\File' => $baseDir . '/classes/File.class.php',
'HM\\Log' => $baseDir . '/classes/Log.class.php',
'HM\\MVC' => $baseDir . '/classes/MVC.php',
'HM\\MVC' => $baseDir . '/classes/MVC.class.php',
'HM\\SRC' => $baseDir . '/classes/SRC.class.php',
);
......@@ -23,8 +23,8 @@ class ComposerStaticInitc9276e89b85b1a7c62ea9fd02827598c
public static $classMap = array (
'HM\\Dir' => __DIR__ . '/../..' . '/classes/Dir.class.php',
'HM\\File' => __DIR__ . '/../..' . '/classes/File.class.php',
'HM\\Log' => __DIR__ . '/../..' . '/classes/Log.class.php',
'HM\\MVC' => __DIR__ . '/../..' . '/classes/MVC.php',
'HM\\MVC' => __DIR__ . '/../..' . '/classes/MVC.class.php',
'HM\\SRC' => __DIR__ . '/../..' . '/classes/SRC.class.php',
);
public static function getInitializer(ClassLoader $loader)
......
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