sudo chgrp -R www-data blog sudo chmod -R 775 blog
<?php require __DIR__.'/lib/base.php'; //F3::set('CACHE',TRUE); F3::set('DEBUG',3); F3::set('UI','ui/'); F3::run(); ?>
F3::set('DB', new DB( 'mysql:host=localhost;port=3306;dbname=', '', '' ) );
F3::route('GET /', function () { // - } );
F3::route('GET /view/@id', function () { $id = F3::get('PARAMS["id"]'); } );
// F3::route('GET /admin', function () { } ); // F3::route('GET /admin/add', function() { } ); // F3::route('GET /admin/edit/@id', function() { $id = F3::get('PARAMS["id"]'); } ); // F3::route('POST /admin/edit/@id','edit'); F3::route('POST /admin/add','edit'); function edit() { } // F3::route('GET /admin/delete/@id', function() { $id = F3::get('PARAMS["id"]'); } );
CREATE DATABASE `blog` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `blog`; CREATE TABLE IF NOT EXISTS `article` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `timestamp` datetime NOT NULL, `title` VARCHAR(128) NOT NULL, `summary` VARCHAR(128) NOT NULL, `content` text NOT NULL, `author` VARCHAR(128) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO `article` (`id`, `timestamp`, `title`, `summary`, `content`, `author`) VALUES (1, '2011-07-28 02:03:14', 'Hello World!', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', 'Mr White'), (2, '2011-07-28 02:03:14', 'More Hello World!', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', 'Mr Green'); CREATE TABLE IF NOT EXISTS `user` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO `user` (`id`, `name`, `password`) VALUES ('1', 'admin', 'password');
$article=new Axon('article'); $articles=$article->afind(); F3::set('articles',$articles);
<!DOCTYPE html> <html> <head> <title>{{@html_title}}</title> <meta charset='utf8' /> </head> <body> <F3:include href="{{@content}}"/> </body> </html>
<p>Blog Titles</p> <F3:repeat group="{{@list}}" value="{{@item}}"> <p><a href="view/{{@item['id']}}">{{trim(@item['title'])}}</a> by {{@item['author']}}</p> <p>{{@item['summary']}}</p> </F3:repeat>
F3::set('content','blog_home.html'); echo Template::serve('layout.html');
F3::route('GET /', function () { F3::set('html_title','Home Page'); $article=new Axon('article'); F3::set('list',$article->afind()); F3::set('content','blog_home.html'); echo Template::serve('layout.html'); } );
F3::route('GET /view/@id', function () { $id = F3::get('PARAMS["id"]'); // Axon id $article=new Axon('article'); $article->load("id='$id'"); // F3::set('html_title',$article->title); $article->copyTo('POST'); // F3::set('content','blog_detail.html'); echo Template::serve('layout.html'); } );
<h1>{{@POST.title}}</h1> <p>Published: {{@POST.timestamp}} by {{@POST.author}}</p> {{@POST.content}} <p><a href='../'>Back to Homepage</a></p>
F3::route('GET /admin', function () { F3::set('html_title','My Blog Administration'); $article=new Axon('article'); $list=$article->afind(); F3::set('list',$list); F3::set('content','admin_home.html'); echo Template::serve('layout.html'); } );
<!-- , --> <h1> </h1> <p><a href='admin/edit'> </a></p> <table> <thead> <tr> <th></th> <th></th> <th></th> <th colspan='2'></th> </tr> </thead> <tbody> <F3:repeat group="{{@list}}" value="{{@item}}"> <tr> <td>{{@item['title']}}</td> <td>{{@item['timestamp']}}</td> <td>{{@item['author']}}</td> <td><a href="admin/edit/{{@item['id']}}"></a></td> <td><a href="admin/delete/{{@item['id']}}"></a></td> </tr> </F3:repeat> </tbody> </table>
<h1>Edit</h1> <form name="blog" method="post" action="{{ @BASE }}{{ @PARAMS.0 }}" > <F3:check if="{{ @message }}"> <p><span class="fail">{{ @message }}</span></p> </F3:check> <label for='title'>Title: </label><br /><input type="text" name="title" id="title" value="{{ htmlspecialchars(@POST.title) }}" size="60"/><br /> <label for='author'>Author: </label><br /><input type="text" name="author" id="author" value="{{ htmlspecialchars(@POST.author) }}" size="60"/><br /> <label for='summary'>Summary: </label><br /><textarea name="summary" id="summary" cols="60" rows="10">{{ htmlspecialchars(@POST.summary) }}</textarea><br /> <label for='content'>Content: </label><br /><textarea name="content" id="content" cols="60" rows="10">{{ htmlspecialchars(@POST.content) }}</textarea><br /> <input type="submit" value="Submit"/> </form>
F3::route('GET /admin/add', function() { F3::set('html_title','My Blog Create'); F3::set('content','admin_edit.html'); echo Template::serve('layout.html'); } ); F3::route('GET /admin/edit/@id', function() { F3::set('html_title','My Blog Edit'); $id = F3::get('PARAMS["id"]'); $article=new Axon('article'); $article->load("id='$id'"); $article->copyTo('POST'); F3::set('content','admin_edit.html'); echo Template::serve('layout.html'); } );
function edit() { // Reset previous error message, if any F3::clear('message'); $id = F3::get('PARAMS["id"]'); $article=new Axon('article'); //load in the article, set new values then save //if we don't load it first Axon will do an insert instead of update when we use save command if ($id) $article->load("id='$id'"); //overwrite with values just submitted $article->copyFrom('POST'); //create a timestamp in MySQL format $article->timestamp=date("Ymd H:i:s"); $article->save(); // Return to admin home page, new blog entry should now be there F3::reroute('/admin'); }
// F3::set('AUTH',array('table'=>'user','id'=>'name','pw'=>'password')); $auth = Auth::basic('sql'); // if ($auth) { // F3::set('SESSION.user',$auth->name); // F3::set('content','admin_home.html'); } else { // F3::set('content','security.html'); }
<p>You must supply valid login details.</p>
if (!F3::get('SESSION.user')) F3::set('content','security.html');
if (!F3::get('SESSION.user')) F3::reroute('/');
Source: https://habr.com/ru/post/135619/
All Articles