Questions tagged [silex]

Silex is a PHP microframework for PHP >=5.3. It is built on the shoulders of Symfony2 and Pimple and also inspired by Sinatra.

Silex is a PHP microframework for PHP. It is built on the shoulders of and and also inspired by .

As of March 2018, the latest stable release of Silex is 2.2.3. For actual improvements check out the changelog.

Silex became end-of-life in June 2018 and is not maintained anymore. Its advised to now use symfony 4 and flex to replace Silex. More information here: https://symfony.com/blog/the-end-of-silex

Information

A microframework provides the guts for building simple single-file apps. Silex aims to be:

  • Concise: Silex exposes an intuitive and concise API that is fun to use.
  • Extensible: Silex has an extension system based around the Pimple micro service-container that makes it even easier to tie in third party libraries.
  • Testable: Silex uses Symfony's HttpKernel which abstracts request and response. This makes it very easy to test apps and the framework itself. It also respects the HTTP specification and encourages its proper use.

Useful links

1368 questions
43
votes
1 answer

Silex & Twig helpers in custom error pages

I'm struggling with a problem while trying to render a custom error page in Silex. According to what I found in this link :http://refactoring.us/silex/custom-error-pages-with-silex-and-twig/ I am trying to set up a custom 404 error page in my…
Piotr
  • 457
  • 5
  • 7
39
votes
2 answers

Twig Access Array Index?

Is it possible to directly access an array index from within a Twig template? Here's my setup, using Silex: return $app['twig']->render('template', array('numbers' => array('one', 'two', 'three'))); so can I do something like this? {{numbers[0]}}
Adam
  • 4,733
  • 4
  • 28
  • 48
36
votes
8 answers

The difference between Symfony and Silex

I would like to try Silex but i've some questions. I know to use Symfony2 and i would like to know if Silex is very different of Symfony or it's the same thing (same operation, same code... ) ? Moreover, Silex is recommanded for small PHP projects…
Alex L.
  • 804
  • 2
  • 15
  • 33
29
votes
1 answer

How do I obtain all the GET parameters on Silex?

I've been using Silex for a day, and I have the first "stupid" question. If I have: $app->get('/cities/{city_id}.json', function(Request $request, $city_id) use($app) { .... }) ->bind('city') ->middleware($checkHash); I want to get all the…
fesja
  • 3,225
  • 5
  • 25
  • 41
28
votes
3 answers

Symfony2 Form Component - creating fields without the forms name in the name attribute

I'm currently trying to use the Symfony2 Form Component though the Silex microframework. My login form is generated as follows: $app = $this->app; $constraint = new Assert\Collection(array( 'username' => new Assert\NotBlank(), 'password' =>…
thingygeoff
  • 283
  • 1
  • 3
  • 6
28
votes
1 answer

Difference between Include, Extends, Use, Macro, Embed in Twig

What is the difference between use and include in Twig? Documentation: include The include statement includes a template and returns the rendered content of that template into the current one: {% include 'header.html' %} Body here... {% include…
Pmpr
  • 14,501
  • 21
  • 73
  • 91
21
votes
2 answers

"A Token was not found in the SecurityContext" on Silex / Symfony

I built a Silex project with an login mechanism. Not being a Symfony expert, I strictly followed the guidelines here for the authentication process : http://silex.sensiolabs.org/doc/providers/security.html ... and it works fine on my development…
benoit
  • 861
  • 12
  • 22
20
votes
2 answers

Argument 1 passed to Twig_Filter::__construct() must be an instance of string, string given

I have a problem with TWIG. This code works at school but absolutely not with my laptop. I tried with a simple code but I have the error: Catchable fatal error: Argument 1 passed to Twig_Filter::__construct() must be an instance of string, string…
Ben
  • 203
  • 1
  • 2
  • 5
19
votes
3 answers

Mockery - call_user_func_array() expects parameter 1 to be a valid callback

I have a class I need to mock: class MessagePublisher { /** * @param \PhpAmqpLib\Message\AMQPMessage $msg * @param string $exchange - if not provided then one passed in constructor is used * @param string $routing_key *…
mrok
  • 2,570
  • 3
  • 25
  • 42
18
votes
3 answers

How to use a YAML config file in Silex Framework

Is it possible to configure a Silex Application with YAML config files? I bet yes, but how is it done correctly? For instance I want to use different configurations according to the environment, like config.dev.yml and config.prod.yml. The config…
fbrandel
  • 1,595
  • 3
  • 16
  • 18
16
votes
6 answers

Silex vs SLIM PHP Framework

We have narrow down our search between Silex and Slim PHP frameworks for routing our REST APIs on our Apache/PHP/MySQL Server. Both seem to have good reviews. Silex has probably a bigger community because it came from Symfony. But the documentation…
16
votes
2 answers

How to use silex with Doctrine orm EntityManager?

Am new to the Silex framework. And I would like to do simple SQL DB connection using doctrine entity manager. Kindly give some simple examples. Thanks in Advance, SK
KSK
  • 195
  • 1
  • 2
  • 7
16
votes
1 answer

Using Javascript variable in Twig template using Silex framework

I am trying to create a route inside of some Javascript inside of a Twig template and need to use a JS variable as a value to a route parameter. Example: window.location.href = {{ path('post_display', { 'id': this_is_where_i_need_to_use_the_js_var…
Moismyname
  • 330
  • 1
  • 4
  • 16
15
votes
1 answer

Sessions do not work in Silex\App

For whatever reason, Sessions don't work in my Silex-app. I set error_reporting in my php.ini to E_ALL | E_STRICT and errors are displayed and logged. Nothing to see there. But for some reason no session is created and there is no file in…
dbrumann
  • 15,087
  • 1
  • 35
  • 52
15
votes
1 answer

Attempted to call method "share" on class "Silex\Application" in Silex 2

I am developing a project with silex-skeleton in its most recent version. When trying to use the share method shows me the following error: Code: $app['login'] = $app->share(function() use($app) { return new…
1
2 3
91 92