Skip to content

Instantly share code, notes, and snippets.

View victorknust's full-sized avatar
🏠
Working from home

Victor knust victorknust

🏠
Working from home
View GitHub Profile
<?php
namespace App;
class App
{
public function __construct()
{
$controller = new Controller\Example;
}
<?php
//
$view = new View();
$view->addGlobal('global', 'Hello!, I\'m a Global var.');
// in the method
echo $view->render('controller.method.phtml', ['var' => 'Hello World!']);
<?php
class View
{
public function render( $view, array $data = [] )
{
ob_start() and extract($data, EXTR_SKIP);
try {
<?php
function getWeekDays() {
$time = strtotime( 'monday this week' );
$days = [];
for($i = 0; $i<7; $i++){
$d = new DateTime();
$d->setTimestamp(strtotime("+$i day",$time));
$days[] = $d->format("Y-m-d");
}
<?php
namespace Slim;
use Pimple\Container;
trait ResolveCallable
{
protected $container;
<?php
function days_of_this_week()
{
$data = strtotime(date('Y-m-d'));
$ano = date('o', $data);
$semana = date('W', $data);
for($i = 1; $i <= 7; $i++) {
$dias[] = date("m/d/Y l", strtotime($ano . 'W' . $semana . $i));
}
@victorknust
victorknust / readme.md
Created January 18, 2017 11:45 — forked from xeoncross/readme.md
140 byte PHP routing framework (well, it's just a function actually)

140 byte PHP routing system.

This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.

require('route.php');

// A user profile
route('/(\w+)/profile', function($path, $user)
{

print "Hello " . $user;

<?php
class Router
{
public $routes = array();
public function route( $method, $pattern, $callback )
{
$pattern = '/^' . str_replace( array('/', ':id'), array('\/', '([0-9]+)'), $pattern ) . '$/';
$this->routes[$method][$pattern] = $callback;
@victorknust
victorknust / .htaccess
Created October 27, 2016 12:54 — forked from dhrrgn/.htaccess
NPSR - PSRs? We don't need to stinkin' PSRs.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?_uri=$1 [L]
<?php
// Cache the contents to a file
$cached = fopen($cachefile, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser