silex

Filtering and splicing an array in Twig

馋奶兔 提交于 2019-12-12 11:07:46
问题 I have an array of user records (0 indexed, from a database query), each of which contains an array of fields (indexed by field name). For example: Array ( [0] => Array ( [name] => Fred [age] => 42 ) [1] => Array ( [name] => Alice [age] => 42 ) [2] => Array ( [name] => Eve [age] => 24 ) ) In my Twig template, I want to get all the users where the age field is 42 and then return the name field of those users as an array. I can then pass that array to join(<br>) to print one name per line. For

Silex redirect changing the locale

你说的曾经没有我的故事 提交于 2019-12-12 05:05:16
问题 I am using Silex 2 and I would like to redirect to homepage with default locale if any url is loaded using an invalid locale. // homepage / root $this->get('{_locale}/', function (Request $request) use ($app) { return $app['twig']->render('index/index.html.twig', array()); })->bind('homepage'); Before middleware: // i18n Control $locale = $request->getLocale(); $allowLocale = ['en','es','de']; if (!in_array($locale, $allowLocale)) { $request->setLocale('en'); $response = new \Symfony

Silex2: Security firewall and locale

僤鯓⒐⒋嵵緔 提交于 2019-12-12 04:42:42
问题 How do I add the current locale to paths like /user/login or /user/logout? Controllers do support the '{_locale}' placeholder, but within the security pattern it is reported as an error. $app['security.firewalls'] = array( 'login' => array( 'pattern' => '^/user/login$', ), 'secured_area' => array( 'pattern' => '^.*$', 'anonymous' => false, 'remember_me' => array(), 'form' => array( 'login_path' => '/user/login', 'check_path' => '/user/login_check', ), 'logout' => array( 'logout_path' => '

Nginx serving static files with 404 status code?

懵懂的女人 提交于 2019-12-12 04:40:07
问题 I'm trying to let Nginx serve my authenticated admin users some static files with PHP. This works great, I get back the file. But it's served with a 404 status code.. I'm using the following (Symfony / Silex) php code: use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\ResponseHeaderBag; $filePath = '/usr/share/nginx/project/src/path/to/my/protected/static/dir/' . $file; if (empty($file) || !is_readable($filePath)) { $app->abort(404); } $response =

Silex - get right condionals in finish middleware

坚强是说给别人听的谎言 提交于 2019-12-12 04:32:49
问题 I want to create a pdf file out of some route-dependant data {http://example.com/products/123/?action=update} $app->finish(function (Request $request, Response $response) { // Make a pdf file, only if: // - the route is under /products/ // - the action is update // - the subsequent ProductType form isSubmitted() and isValid() // - the 'submit' button on the ProductType form isClicked() }); As a normal form submission process I have: public function update(Application $app, Request $request) {

Symfony (Silex) radio choice form builder does not render attr

风格不统一 提交于 2019-12-12 02:55:56
问题 I'm trying to add attributes to my rendered radios $builder ->add('myRadios', 'choice', array( 'choices' => array( 'one' => 'uno', 'two' => 'due'), 'multiple' => false, 'attr' => array('class' => 'testClass'), 'expanded' => true the output is: <div class="control-group"> <label class="control-label required">Myradios</label> <div class="controls"> <label for="form_one_0" class="required radio"> <input type="radio" id="form_one_0" name="form[one]" required="required" value="uno" /> <span>Uno<

How to overwrite a class from the Security Component?

青春壹個敷衍的年華 提交于 2019-12-12 01:59:46
问题 I am using Basic Auth in my API (Silex), an endpoint receives user+pw from client, validates the user via basic auth and then returns the token to be used for further requests. Now when my app makes an AJAX call, if the credentials are right, everything works smooth. If the credentials are wrong, the API returns a 401 and a set WWW-Authenticate header. This causes the browsers to automatically show the default browser login form. I don't want that to happen. In StackOverflow, they say the

Silex - access to user outside a secured area

这一生的挚爱 提交于 2019-12-12 01:36:39
问题 I have set up a secured area in my Silex website. I need to display the username in the header when the user is connected or a link to the login form if the user is not connected. But when the user is on a page not secured (outside the firewall), the app.user is not defined. I have tried this solution, but it does not work. Here my security configuration: $app->register(new Silex\Provider\SecurityServiceProvider(), array( 'security.firewalls' => array( 'account' => array( 'pattern' => '^

silex file structure for custom service providers

半世苍凉 提交于 2019-12-11 20:22:30
问题 I am working on a Silex project which requires some custom service providers and their related classes to be written. I am aware of the preferred file structure of silex projects but cannot anywhere find information on where custom classes should fit into this structure. All composer supplied libraries are naturally in the vendor folder, where do custom ones go? At the moment (trimmed down for space) my directory structure follows: . ├── composer.json ├── composer.lock ├── composer.phar ├──

Silex: jQuery AJAX request throws exception - No route found for “GET …”

*爱你&永不变心* 提交于 2019-12-11 19:54:08
问题 I'm trying to make an ajax call on tr click like this: $.ajax({ type: "GET", url: "/segments/ajaxGetHostsSegment", data: { deelgebied: deelgebiedid }, success: function( data ) { // CHECK ID'S WITH ID'S IN FORM AND CHECK CHECKBOXES }, error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); } }) In my routes file I have: $app->get('/segments/ajaxgethostssegment', 'Segments\Controller\IndexController::ajaxGetHostsSegment')->bind('segments.gethosts');