akrabat / slim3-skeleton Goto Github PK
View Code? Open in Web Editor NEWSimple Slim Framework 3 skeleton with Twig & Monolog
License: BSD 3-Clause "New" or "Revised" License
Simple Slim Framework 3 skeleton with Twig & Monolog
License: BSD 3-Clause "New" or "Revised" License
Hello, Dear Rob.
Thank you for great code!
Is it possible to put full DI container to HomeAction construct method?
slim3-skeleton/app/src/Action/HomeAction.php:
public function __construct(Twig $view, LoggerInterface $logger)
{
$this->view = $view;
$this->logger = $logger;
}
change to something like this:
public function __construct(ContainerInterface $container)
{
$this->view = $container['view'];
$this->logger = $container['logger'];
$this->db = $container['db'];
$this->flash = $container['flash'];
}
In order to have access to full list of dependencies from class?
Or it's a bad idea?
If I need a logger, view, flash, database mapper etc in one place.
Rob,
I'm not sure if it's deliberate or not, but I noticed that the example action suggests that the Request
and Response
objects are PSR-7, but they're actually Slim\Http\Request
and Slim\Http\Response
respectively.
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
should be
use Slim\Http\Request;
use Slim\Http\Response;
The documentation states:
Because this is a common task, Slim’s built-in PSR 7 implementation also provides these proprietary methods that return true or false
So it's not technically a PSR-7 implementation. I'll submit a PR in case this isn't deliberate :)
That would be an excellent addition to the skeleton.
I can't seem to accomplish this by mocking the environment.
To allow loading resources when running app from a sub folder, it may be appropriate to include reference to base_url()
in resource paths.
<link href='{{ base_url() }}/css/style.css' rel='stylesheet' type='text/css'>
I create a new Class in app/src/Action which namespace is App\Action too. And use exactly the same constructor with HomeAction .
I use it in route file but got next error:
Catchable fatal error: Argument 1 passed to App\Action\ProductAction::__construct() must be an instance of Slim\Views\Twig, instance of Slim\Container given, called in /Users/tinker010/zhengjie/kafe/vendor/slim/slim/Slim/CallableResolver.php on line 64 and defined in /Users/tinker010/zhengjie/kafe/app/src/Action/ProductAction.php on line 21
Don't know why, here is my New Class:
view = $view; $this->logger = $logger; } public function productAddPage(Request $request, Response $response, $args) { return $this->view->render($response, 'product.html'); } ``` }This is my first time using Slim and have a question. In looking at your config, would you suggest putting the Actions within another directory for example
or do you have a different suggestion.
Here is how I currently have my project structure
I find this structure will keep my actions contained and small. AllActions is the final class which extends the baseclass. I use traits for CRUD and use
them in the Class.
I try to use https://github.com/akrabat/rka-scheme-and-host-detection-middleware to prevent "Mixed content" error. After set X-Forwarded-Proto:https header in controller everything ok: $request->getUri()->getScheme(); return "https".
But here it's not working:
slim3-skeleton/app/dependencies.php
Line 16 in a39939d
$c->get('request')->getUri()->getScheme(); return "http" :(
Hi,
I use php 5.6 and get error in Twig when try to render page.
Catchable fatal error: Argument 1 passed to Twig_Filter::__construct() must be an instance of string, string given, called in system/vendor/twig/twig/lib/Twig/Extension/Core.php on line 139 and defined in system/vendor/twig/twig/lib/Twig/Filter.php on line 35
How to create a independent cron script using this framework. pls revert.
Running this skeleton on a PHP5.5 install, user will see an error related to the lack of default timezone (used by the log).
Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in my-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272
This can be easily fixed by adding a date_default_timezone_set('Etc/UTC');
to index.php
.
Probably HomeActionTest
would be enough.
The point is to show how to work with mock environment.
There is some work done for the 2.x version here: https://github.com/shahariaazam/slim-test-case-skeleton
Hello,
Using your example, what's the better way to throw exceptions from within HomeAction class?
Have you thought to integrate your rka-content-type-renderer component?
As per discussion in this Tweet stream.
Defining a new factory for every controller separately seems wasteful, especially when most might share some, if not all dependencies.
What would be good approaches to handling this? Originally, I thought about something like this:
And then extending the get
and has
methods as necessary.
But this seems a bit clumsy and too much work for such a simple feature - especially considering a new offsetExists
would need to be added into the mix, too, and some other things.
Suggestions?
If there is a best practice to unit test a Slim application with PHPunit it would be nice to have some examples on how to write such tests.
The syntax: 'App\Action\HomeAction:dispatch'
Where can I learn more about this? I have never encountered it before outside of a Slim3 context. Is this something unique to Slim/Pimple/FastRoute or this a feature in PHP5 that has eluded me?
I feel silly, but I would very much like to understand this seemingly simple syntactical detail.
Thank you very much for this skeleton. It is proving to be extremely helpful.
is there a way I can declare constants somewhere so I can just use them in my controllers ? @akrabat @namaless @needcaffeine @jeremykendall
To avoid mixed content issues when running slim3-skeleton from https, remove scheme from url to google fonts.
<link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
in app/templates/home.twig
Hi!
How do i use the flash message?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.