silex

How to Implement Resumable Download in Silex

白昼怎懂夜的黑 提交于 2019-12-20 14:42:21
问题 In silex I can do this to force-download a file: use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; $app = new Silex\Application(); // Url can be http://pathtomysilexapp.com/download $app->get('/download', function (Request $request) use ($app) { $file = '/path/to/download.zip'; if( !file_exists($file) ){ return new Response('File not found.', 404); } return $app->sendFile($file)-

How to send a POST request using HTTPie?

亡梦爱人 提交于 2019-12-18 09:34:36
问题 I have a basic silex application, and I try to test it using HTTPie. Yet when posting using: http POST http://localhost:1337 data="hello world" The data , that I get from the Request object via: $data = $request->request->get('data'); will always be empty. What is the problem here? 回答1: It was an httpie usage problem as the form flag was necessary, as silex requires the parameters to be form-encoded, yet the default of HTTPie is to pass a JSON object. $ http --form POST http://localhost:1337

Using Javascript variable in Twig template using Silex framework

。_饼干妹妹 提交于 2019-12-18 03:17:46
问题 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 }) }}; I am using the Silex framework and am unsure if FOS JS works for Silex. I don't think it does, though. 回答1: Twig, since it's written in PHP , runs on the server, completely separately than the javascript code, so what you want needs a

How to have twig path() with silex slug?

本秂侑毒 提交于 2019-12-14 04:04:33
问题 In silex I have something like $controllers->get('/{id}', 'Controllers\\Login::index')->bind('login'); when in twig I try to get path('login') I get exception ("Some mandatory parameters are missing ("id") to generate a URL for route "login"."). ? I know this is because of {id} and I have to pass a second parameter to path() but how should it look like? 回答1: In order to pass parameters to twig path, use the following syntax: {{ path('login', {'id': 'your-id-here'}) }} you can have a look at

How to insert a Controller in Twig with “render” in Silex

社会主义新天地 提交于 2019-12-14 01:54:07
问题 Should it work in Silex with symfony/twig-bridge ? {{ render(controller('MyController')) }} Now I have message like this: Twig_Error_Syntax: The function "controller" does not exist in "... 回答1: I've found this working: {{ render(controller('services.controller:action', {[params]}) }} And you can define the controller as a service: $app['services.controller'] = function() use ($dependecy1, .., $dependencyN){ return new \\PathToYourControllerClass($dependecy1, .., $dependencyN); } 回答2: You can

Postman show unexpected 'A' in json response , but json is well formed

瘦欲@ 提交于 2019-12-13 18:04:48
问题 I'm developing a backend with Silex framework and i'm testing this piece of code foreach($P as $key=>$value) { $strInsert =$key."=>".$value; array_push($json,$strInsert); } print_r($json); return json_encode($json); On every browser calling the route which contains the foreach it prints well, and the output given is considered well-formed by different json validators. In postman when i click on 'pretty' Json it shows Unexpected 'A' . On raw,html and other views options the json document is

Call to a member function addPaiementType() on null

僤鯓⒐⒋嵵緔 提交于 2019-12-13 07:05:57
问题 I have 3 files: The first one: public function register(\Pimple\Container $app) { $app['manager.form'] = function() use ($app) { return new Form($app); }; } Second: class Form { private $form; public function __construct(Application $app) { $this->form = $app['form.factory']->createBuilder(FormType::class); } public function addDuree() { $this->form->add('duree', ChoiceType::class, [ 'choices' => [ '1' => '1', '3' => '3', '6' => '6', '12' => '12' ], 'multiple' => false, 'expanded' => true,

Why is KernelEvents::TERMINATE blocking the response to the user?

梦想的初衷 提交于 2019-12-13 02:07:51
问题 In a Silex application running on HVVM I have setup a dummy event listener on Kernel TERMINATE : $app['dispatcher']->addListener( KernelEvents::TERMINATE, function () use ($app) { usleep(10000000); $app['logger']->alert("I AM REGISTERED!"); } ); I was expecting my application to render the response as fast as possible within a second and after 10s I expected the message "I AM REGISTERED" to appear in my log. Yet strangely the response is sent after the event has been executed, meaning the

Doctrine DBAL: Updating timestamp field with 'NOW()' value

随声附和 提交于 2019-12-13 00:29:13
问题 Using Doctrine DBAL, I have some code that inserts a new row into the main database from a form values binded as $telephone_international and $surname . After that is done, it inserts a new record into a duplicate database. $app['dbs']['backup'] If that's successful, the entry inserted previously the main database gets its copied value updated. The copied column is a timestamp, default value is 0, but the following code should change it to the current time. $app['dbs']['main']->update(

Default values for symfony2 choice radio box

社会主义新天地 提交于 2019-12-12 20:18:31
问题 My project is written using Silex and Symfony Components (i.e. Form component). I try to create a battery of radio buttons built from a class and I want to preselect one of those radios. I create form like that: $form = $app['form.factory']->createBuilder(new QueryFormType(), $query) where QueryFormType is my custom type (it extends AbstractType) where I define form fields and $query is an entity with default values for the form. Form fields within QueryFormType look like that (I omitted