silex

handle {_locale} prefixes on Silex with the TranslationServiceProvider

女生的网名这么多〃 提交于 2019-12-11 12:26:29
问题 I am trying to make the website I am working on, translatable. As I am using Silex, I chose the TranslationServiceProvider which is working nicely. Here is my code from app.php : $app->register(new Silex\Provider\TranslationServiceProvider(), array( 'locale' => 'en', 'locale_fallback' => array('en'), )); $app['translator'] = $app->share($app->extend('translator', function($translator, $app) { $translator->addLoader('yaml', new YamlFileLoader()); $translator->addResource('yaml', __DIR__.'

How can i inject class inside custom repository - Symfony 2.7

你说的曾经没有我的故事 提交于 2019-12-11 05:30:07
问题 I have custom repository class in which i must inject class that helps me to upload file, and erase file if needed. I expanded EntityRepository constructor, but i don't know how to add third argument inside custom repository class. class NewRepository extends EntityRepository { protected $fileUploader; public function __construct(EntityManager $em, Mapping\ClassMetadata $class,FileUploader $fileUploader) { parent::__construct($em, $class); } public function create($data, Item $item = null) {

Silex “->after” middleware usage

拈花ヽ惹草 提交于 2019-12-11 04:43:07
问题 I am testing Silex "->after" middleware to set the response header to enable CORS access. Silex is running V2.0.4. My index.php excerpt as below: $app->get('/{entity}/{func}', function ($entity, $func) use ($app) { if (method_exists($namespace, $func)) { $result = call_user_func_array([$namespace, $func], [$app]); $status = 200; } $out = ['status' => $status, 'out' => $result]; return json_encode($out); })->after(function (Request $request, Response $response) { $response->headers->set(

Accessing “dot” namespaced services in Twig view

被刻印的时光 ゝ 提交于 2019-12-10 22:12:42
问题 I know that I can access registered services by using the dot notation in a Twig template (example app.request.host ). However, if I've created my own namespaced service (in this case tagframe.photoservice ), when I try to access it, I am given an error that the method "tagframe" doesn't exist on the object "Silex\Application". Is it possible to access services that have been dot namespaced? In other words, a service that I would normally access using $app['tagframe.photoservice'] in the

Composer Autoload - Can't find class

妖精的绣舞 提交于 2019-12-10 18:44:54
问题 I have a little Silex app going on. Trying to get some sort of structure going on. This is my composer.json : { "require": { "silex/silex": "~1.3" }, "autoload": { "psr-0": { "HelloWorld\\Controller": "src/HelloWorld/Controllers" } } } In my web/index.php file I have this $loader = require_once __DIR__.'/../vendor/autoload.php'; $ctrl = new \HelloWorld\Controller\IndexController(); // <- Doesn't work My IndexController controller in src/HelloWorld/Controllers namespace HelloWorld\Controller;

What is the difference betweed getcwd and __DIR__?

守給你的承諾、 提交于 2019-12-10 18:37:24
问题 DIR is a magic constant as stated in the PHP docs. getcwd() is just the current working directory according to the PHP docs. My use case is: // this is my index.php file require_once __DIR__ . '/vendor/autoload.php'; $app = new Silex\Application(); $app['debug'] = true; $app->get('/{name}', function($name) use($app) { return $app->sendFile(__DIR__ . '/web/source/index.php'); }); I don't fully understand why I need either of these mechanisms as I should just be able to use relative paths.

PHPUnit fails when using Silex SessionServiceProvider

旧街凉风 提交于 2019-12-10 17:56:01
问题 I am trying to create a unit test for my Silex application. The unit test class looks something like this: class PageTest extends WebTestCase { public function createApplication() { $app = require __DIR__ . '/../../app/app.php'; $app['debug'] = true; $app['session.storage'] = $app->share(function() { return new MockArraySessionStorage(); }); $app['session.test'] = true; unset($app['exception_handler']); return $app; } public function testIndex() { $client = $this->createClient(); $client-

PHP Twig: access current template variable from within macro without passing?

家住魔仙堡 提交于 2019-12-10 16:45:51
问题 Is it possible to access the current template's variables from within a macro without passing the variable to the macro directly? Thanks. 回答1: It's possible to pass all context variables to a macro: {{ macro(_context) }} _context is a special variable, which contains all currently defined variables (by name => value). 来源: https://stackoverflow.com/questions/7586924/php-twig-access-current-template-variable-from-within-macro-without-passing

Symfony2 Form Collection allow_add and allow_delete null error (Silex)

旧巷老猫 提交于 2019-12-10 11:18:31
问题 I've run into a problem when following the Symfony cookbook for form collections with add/remove. See: http://symfony.com/doc/current/cookbook/form/form_collections.html Now, for some reason, if I dynamically add a form row but don't fill in any of its fields , I get the following error: ContextErrorException: Catchable Fatal Error: Argument 1 passed to Project::addTask() must be an instance of Task, null given in D:\web_workspace\wedding\src\testapp.php line 82 I would like people to be able

Is it possible to use EventSubscribers with Silex?

隐身守侯 提交于 2019-12-10 11:05:43
问题 Whilst looking around at using AuthenticationHandlers I saw that Symfony supports EventSubscribers which can be more flexible when authenticating with multiple methods. I have been using this as an example: https://knpuniversity.com/screencast/guard/success-handling So I have got my subscriber class all setup, but what I do not know how to do is register is as an event in Silex. I am pretty sure that I need to use the $app['dispatcher'] but what I do not know is what event to listen on. Using