This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //... | |
| ob_start(); | |
| include "home.php"; | |
| $body = ob_get_clean(); | |
| returen $response->write($body); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Building a Middleware for Authentication | |
| Components: | |
| 1) AuthFactory | |
| - Responsible for creating the the session and loading it with data | |
| */ | |
| interface IAuthFactory { | |
| public function setData($data = []); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ew_GetKeyword(&$src, &$kwlist, &$x, &$y, &$kw) { | |
| $thisy = -1; | |
| $thiskw = ""; | |
| foreach ($kwlist as $wrkkw) { | |
| $wrkkw = trim($wrkkw); | |
| if (EW_HIGHLIGHT_COMPARE) { // Case-insensitive | |
| if (function_exists('stripos')) { // PHP 5 | |
| $wrky = stripos($src, $wrkkw, $x); | |
| } else { | |
| $wrky = strpos(strtoupper($src), strtoupper($wrkkw), $x); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $app->add(function (Request $request, Response $response, $next) { | |
| if ($request->getUri()->getScheme() !== 'https') { | |
| $uri = $request->getUri()->withScheme("https")->withPort(null); | |
| return $response->withRedirect( (string)$uri ); | |
| } else { | |
| return $next($request, $response); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Use case | |
| I have several "components" which are standalone Slim applications. | |
| Maybe its a "UserManagement"... while I can run this module at /users on it's own... I want to install this package on another larger project. | |
| In my main app, | |
| I load "components"... | |
| $components = [ | |
| "UserManagement" => [ | |
| "routes" => "../usermanagement/routes.php", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $app->get('/hello[/[{name}]]', function ($req, $res, $args) { | |
| if (!empty($args['name'])) { | |
| return $res->write("Why Hello " . $args['name']); | |
| } else { | |
| return $res->write("Hello!"); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Let's configure it. | |
| // Fetch DI Container | |
| $container = $app->getContainer(); | |
| // Register Twig View helper and configure it | |
| $container['view'] = function ($c) { | |
| //You can change this as you want | |
| $view = new \Slim\Views\Twig('templates', [ | |
| 'cache' => false //or specify a cache directory | |
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $app->get('/hello[/[{name}]]', function ($req, $res, $args) { | |
| $get = $req->getQueryParams(); // Grab the Query Params... ["test" => "true"] | |
| if (!empty($args['name'])) { | |
| return $this->view->render($res, "hello.twig", ["name" => $args['name'], "test" => $get['test']]); | |
| } else { | |
| return $this->view->render($res, "hello.twig", ["name" => "", "test" => $get['test']]); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Let's use it! | |
| $app->get('/hello[/[{name}]]', function ($req, $res, $args) { | |
| if (!empty($args['name'])) { | |
| return $this->view->render($res, "hello.twig", ["name" => $args['name']]); | |
| } else { | |
| return $this->view->render($res, "hello.twig", ["name" => ""]); | |
| } | |
| }); | |
| $app->run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $myGET = $request->getQueryParams(); |