silex

Inject Silex $app in my custom class

爷,独闯天下 提交于 2020-01-04 06:50:33
问题 I'm on a Silex project and I use classes to different treatments: $connection = new Connection($app); $app->match('/connection', function () use ($app, $connection) { $connexion->connectMember(); return $app->redirect($app['url_generator']->generate('goHome')); })->method('GET|POST')->bind('doConnection'); In the function 'connectMember()' of my class 'Connection', I have : [...] if($isMember){ [...] }else{ return $this->_app['twig']->render( 'message.twig', array('msg' => "This member does

Silex and Doctrine - ORMException: Unknown Entity namespace alias [semi fixed]

大兔子大兔子 提交于 2020-01-03 06:07:21
问题 I'm trying to use the Doctrine components in my app built using silex. I was able to get it to work - well almost. I have my "User" entity and the corresponding repository When doing $app['em']->getRepository('Foo\Entity\User')->findAll() works as expected, however when trying to make a custom query $this->getEntityManager() ->createQuery( 'SELECT u FROM Foo:User u WHERE c.id = :x' ) ->setParameter('x',$in) ->getResult(); I get this exception ORMException: Unknown Entity namespace alias 'Foo'

Silex and Doctrine - ORMException: Unknown Entity namespace alias [semi fixed]

雨燕双飞 提交于 2020-01-03 06:06:48
问题 I'm trying to use the Doctrine components in my app built using silex. I was able to get it to work - well almost. I have my "User" entity and the corresponding repository When doing $app['em']->getRepository('Foo\Entity\User')->findAll() works as expected, however when trying to make a custom query $this->getEntityManager() ->createQuery( 'SELECT u FROM Foo:User u WHERE c.id = :x' ) ->setParameter('x',$in) ->getResult(); I get this exception ORMException: Unknown Entity namespace alias 'Foo'

Silex Exception handler

断了今生、忘了曾经 提交于 2020-01-03 05:14:09
问题 I have big problem I don't know why exceptions are not catch by silex exception handler ? My simple Code looks like this: <?php use Silex\Application; use Silex\Provider\ValidatorServiceProvider; use Silex\Provider\FormServiceProvider; use Symfony\Component\HttpFoundation\Request; $app = new Application(); // SPL Logic Exceptions // Handle other exception as 500 errors $app->error(function (\Exception $e, $code) { exit('asd'); }); throw new Exception('test'); return $app; And the result is:

Silex Exception handler

久未见 提交于 2020-01-03 05:14:03
问题 I have big problem I don't know why exceptions are not catch by silex exception handler ? My simple Code looks like this: <?php use Silex\Application; use Silex\Provider\ValidatorServiceProvider; use Silex\Provider\FormServiceProvider; use Symfony\Component\HttpFoundation\Request; $app = new Application(); // SPL Logic Exceptions // Handle other exception as 500 errors $app->error(function (\Exception $e, $code) { exit('asd'); }); throw new Exception('test'); return $app; And the result is:

PHP Silex routing localization

青春壹個敷衍的年華 提交于 2020-01-02 06:47:07
问题 starting with Silex. Say I want a localised site where all routes have to start with /{_locale} and don't fancy repeating myself as : $app->match('/{_locale}/foo', function() use ($app) { return $app['twig']->render('foo.twig'); }) ->assert('_locale', implode('|', $app['languages.available'])) ->value('_locale', $app['locale.default']) ->bind('foo'); $app->match('/{_locale}/bar', function() use ($app) { return $app['twig']->render('bar.twig'); }) ->assert('_locale', implode('|', $app[

Route.php can't find controller class I created

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 05:44:07
问题 I'm trying to build a silex application. My file structure is: ROOT/ /App/ /Controller/{IndexController.php} /Config/{dev.php,prod.php,route.php} /vendor /web/{index.php, index_dev.php} When I'm trying to see http://localhost/web/ I get error: PHP Fatal error: Class 'App\Controller\IndexController' not found in ../App/config/route.php on line 2 Here are the relevant files: index_dev.php <?php require_once __DIR__.'/../vendor/autoload.php'; require __DIR__.'/../App/config/dev.php'; $app =

Capture exceptions with a different handler for applications REST

陌路散爱 提交于 2020-01-01 14:10:34
问题 The problem I'm building a small application with Silex . It's divided between a REST application and a website. (two controllers, same app). The website has installed its own custom error handler, which returns a user friendly html page. The problem is that in the part dedicated REST application, I should somehow handle exceptions to return type [json] and content different from the error handler's custom website. With Symfony2 This argument can also be applied to Symfony2, I would like also

How to return an image to an https request with PHP

时光怂恿深爱的人放手 提交于 2020-01-01 05:41:07
问题 After many hours, I nailed down my problem concerning downloading an image with an https request. When I access an image with the hard path (https://mysite/tmp/file.jpg) , apache returns it with success and I can view it in the browser, without any extra manipulation. When I try to access it with another path (https://mysite/files/file.jpg) , in order to control its access with php, I get a response from my php code, but I cannot view the image in the browser. VirtualHost defined; mysite: set

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

ⅰ亾dé卋堺 提交于 2020-01-01 01:57:11
问题 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 given, called in /opt/lampp/htdocs/webalizer/projetSilex/vendor/twig/twig/lib/Twig/Extension/Core.php on line 139 and defined in /opt/lampp/htdocs/webalizer/projetSilex/vendor/twig/twig/lib/Twig/Filter.php on line 35 I use php 5.6 / SILEX 2.0 / Twig