silex

Twig Access Array Index?

我的梦境 提交于 2021-02-06 14:20:38
问题 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]}} 回答1: Just before posting this I realized, that's exactly what you can do, but as I didn't find the answer anywhere in the docs or google (correct me if I'm wrong), I've posted this anyway. {{numbers[0]}} 回答2: The answer of Adam, is correct, only to

How do I troubleshoot a Silex application?

爱⌒轻易说出口 提交于 2020-03-21 20:24:35
问题 I'm trying to do what I would think is the most basic thing and it is taking too much time. I simply want my index file to point to or forward to another file. I was originally doing this with a simple one liner. require_once getcwd() . "/web/source/index.php"; Once I migrated to Silex I tried this: $app->get('/', function($path) use($app) { return $app->sendFile('/web/source/index.php'); }); but there was no go. When I go to my site I get a very descriptive "Whoops Something went wrong". How

How do I troubleshoot a Silex application?

不羁的心 提交于 2020-03-21 20:22:06
问题 I'm trying to do what I would think is the most basic thing and it is taking too much time. I simply want my index file to point to or forward to another file. I was originally doing this with a simple one liner. require_once getcwd() . "/web/source/index.php"; Once I migrated to Silex I tried this: $app->get('/', function($path) use($app) { return $app->sendFile('/web/source/index.php'); }); but there was no go. When I go to my site I get a very descriptive "Whoops Something went wrong". How

Url Variables with %2f not handled by silex

妖精的绣舞 提交于 2020-01-24 20:31:48
问题 I am very new to silex, but have experience with Java based MVC frameworks. The problem I have seems to be how to accept certain special characters in URL arguments. I have a controller defined as such: $app->get('/editPage/{fileName}', function ($fileName) use ($app,$action) { return $app['twig']->render('edit.twig.html',$action->editPage($fileName)); }); and this works great for urls like: /myapp/editPage/file.html /myapp/editPage/file-2.html but if I pass an encodes "/" or %2F, the route

Set default raw filter in Twig

删除回忆录丶 提交于 2020-01-24 08:41:27
问题 I'm using Silex to build a site and Twig to display the contents based on a json file. Here's the code in the controller: $app->get('/', function() use ($app) { $data = $app['data']->get('contactUs', 'es'); return $app['twig']->render('test.html', $data); }); Data is just a custom class that takes as argument the page to be displayed and the language to use and returns an array based on the json file that Twig uses as the data on the page. The problem is that the json file contains HTML tags,

Validating match and unique using Symfony validator

人走茶凉 提交于 2020-01-14 03:24:09
问题 I'm using Silex for a small project, but I'm not sure how to validate two matching password fields, also check for the uniqueness of an email using a database connection. I haven't been able to figure it out in SF2 docs. Possible someone can give me a hint or sample? Thanks in advance if ('POST' === $user->getMethod()) { $constraint = new Assert\Collection(array( 'name' => array(new Assert\NotBlank(array('message' => 'Name shouldnt be blank'))), 'username' => array(new Assert\NotBlank(), new

How to use the PHP template engine in Twig instead of the Twig syntax within Silex

眉间皱痕 提交于 2020-01-12 18:53:52
问题 In Silex I am able to use Twig templates but I want to use the PHP engine of Twig, instead of the Twig syntax. For example this guide describes how to do it for Symfony but not Silex. My Silex index.php looks like: $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/views', )); $app->get('/', function() use ($app) { return $app['twig']->render('index.html.php', array( 'name' => 'Bob', )); }); My index.html.php looks like: <p>Welcome to the index <?php echo

How to use the PHP template engine in Twig instead of the Twig syntax within Silex

╄→尐↘猪︶ㄣ 提交于 2020-01-12 18:53:32
问题 In Silex I am able to use Twig templates but I want to use the PHP engine of Twig, instead of the Twig syntax. For example this guide describes how to do it for Symfony but not Silex. My Silex index.php looks like: $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/views', )); $app->get('/', function() use ($app) { return $app['twig']->render('index.html.php', array( 'name' => 'Bob', )); }); My index.html.php looks like: <p>Welcome to the index <?php echo

Where to put 3rd party service providers in my Silex app?

对着背影说爱祢 提交于 2020-01-07 04:02:51
问题 I've just started exploring Silex for the first time and sorry if this sounds like a stupid question. I'd like to use a ServiceProvider written by Igorw to load YAML files. Every 3rd party Service Provider has the same structure: - /src -- /Igorw --- /Silex ---- SomeServiceProvider.php I was wondering where to put these files in my own app? What is considered best practice? I can't really find any information about that. My own app structure looks like this: /app /src /controller /view ...

How can I register a custom form field type in Silex / Twig?

喜你入骨 提交于 2020-01-06 06:52:27
问题 My App ist running, but when I use a custom Form-Field-Type (shtumi_daterange) like: public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options) { $dateRange4 = new DateRange('m/d/Y'); $dateRange4->parseData('03/27/2012 - 04/05/2012'); $builder->add('builddate', "shtumi_daterange", array('required'=>false, 'default'=>$dateRange4)); } the this error occurs: Uncaught exception 'Symfony\Component\Form\Exception\FormException' with message 'Could not load type