FAQ Database Discussion Community


Adding data to a session

php,silex
Real simple. In Silex, the documentation says to add data to a session you use: $app['session']->set('user', array('username' => $username)); This is works fine, but I am assigning a lot of data to the session and it just makes the code unreadable with such a large array. So, in my application...

how to include functions within all Silex routes DRY / global?

php,symfony2,routes,silex
I want to include a file and a variable within all my routes e.g. $app->get('/', function() use ($app) { $auth='code'; require __DIR__.'/assets/helpers.php'; .... }); $app->get('login', function() use ($app) { $auth='code'; require __DIR__.'/assets/helpers.php'; .... }); I need to repeat the code on every route declaration. Putting the variable or redirect at...

Silex/Google API

google-api-php-client,silex
I am working on a Silex application, trying to get the Google API PHP client implemented via Composer, and having little luck. I've tried a number of different configurations, including variations in app.php, autoload_namespaces.php, autoload_classmap.php as well as in the Google_Client class itself. I load the library with: "require": {...

Adding array key dynamically PHP

php,arrays,silex
I'm creating a dynamic form in Silex that alters depending on need. If $disabled = 'true' How would I change: $form = $app['form.factory']->createBuilder('form') ->add('email', 'email', array( 'data' => $from )) to $form = $app['form.factory']->createBuilder('form') ->add('email', 'email', array( 'disabled' => true, 'data' => $from )) ...

PHP: How to prevent serialize from hitting a certain member

php,symfony2,silex
I have a User object whose protected member leads to a PDO object. I'm using Silex/Symfony and when I try to login Symfony\Component\Security\Core\Authentication\Token\AbstractToken goes to serialize that object and gives an exception since PDO objects can't be serialized. I tried making the member private but that didn't help. If I...

WebTestCase, Silex and $_GET

symfony2,silex,web-testing
I'm experiencing some issues on a WebTestCase using Silex: on one of my controller's action, I need a parameter passed through a normal $_GET (I have to as it's an URL, and Apaches interprets the %2F if it's outside of the query string -- see Url Variables with %2f not...

Silex - How to process template includes separately

symfony2,templates,include,silex
I've got a Twig base template like so: {% include "./partials/navigation.html" %} <!-- Main Wrapper --> <div id="wrapper"> {% block content %}{% endblock content %} </div> I also have a route controller which is outputting the response content to the page using twig: return template->render('path/to/teplate', args()); where args[] array is...

Silex, in symbollically liked subdirectory, does not route

php,.htaccess,url-routing,symlink,silex
I have a Silex project. Works on localhost(using php.exe) but I've just transferred it to a subdirectory of an existing website. For example: www.website.foo/silex/ On the site, because of funky existing routing, the silex app is symbolically linked in the webroot under a /silex/ folder, but is actually elsewhere in...

POST nested Json with Silex

php,json,post,silex
I'm new in Silex and I'm trying to retrieve nested Json Data with POST. Here is the Json part. { "action": "opened", "number": 3, "pull_request": { "id": 35845110, "number": 3, "state": "open", "locked": false, "title": "Kie" } } My code works for action, number and pull_request but I only want...

How to specify Silex route name using silex-annotation-provider?

php,silex
I'm using silex-annotation-provider to create routes in my Silex application. I would also like to use the Silex Url Generator to create urls based on the route names. The problem is that the annotation provider does not allow me to specify a route name, and because of this, I'm not...

How do I create a wildcard route (/something/*) in Silex?

routes,silex
How can I create a route like /something/* where * could be one or mode 'subfolders'? (Using Silex framework) For example: /something/foo or /something/foo/bar The purpose: I need to replicate a Webservice and send a POST request to another URL changing 2 $_POST parameters and give it returns back. But...

Silex session set a lifetime

php,symfony2,session,session-cookies,silex
How to change the default session lifetime in Silex. The default value is 30mn; The doc http://silex.sensiolabs.org/doc/providers/session.html#usage is giving a clue but doesn't show an example how to do it. When I set a session like this: $app['session']->set('username', 'my username'); The session variable is set but it expires in 30mn....

Silex render controller inside twig error

symfony2,twig,silex
I'm trying to render a controller inside a twig template with this: {{ render(url('contact_form')) }} But I'm getting this error: An exception has been thrown during the rendering of a template ("Unable to add function "asset" as extensions have already been initialized.") I have a twig function called asset, like...

Silex namespaces

php,namespaces,silex
I'm still quite new to namespaces and struggle to get my head around how to use them. I'm using Silex Microframework and trying to set up my folder structure. So far I have: cms/ ACP/ Controller/ HomeController.php View/ Front/ Controller/ HomeController.php View/ Template/ page.php home.php app.php bootstrap.php I'm trying to...

How to use Pimple C Extension

php,silex,pimple
I have the Pimple C extension installed and in my phpinfo() i can see that the Pimple extension is active. I also have pimple/pimple in my composer.json and the php package is loaded. As far as i see they dont collide as i dont get any errors, but how do...

Why UrlGenerator generate path without host and scheme in Silex?

symfony2,silex
I try to generate url with UrlGenerator in Silex but it seems that UrlGenerator generates only content of $_SERVER['REQUEST_URI'] without http://localhost . So instead of http://localhost/silex/rest-blog/web/blog/posts I have /silex/rest-blog/web/blog/posts. Do you have any idea why? My code: $app['url_generator']->generate('blog.posts.index'); ...

Turning off Warning/Errors for ResourceNotFoundException

php,symfony2,exception-handling,routing,silex
I have a Silex error, that repeats 4 times. I Would like to resolve or hide it. The page loads normally, otherwise. Symfony\Component\Routing\Exception\ResourceNotFoundException: in /var/www/project/vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcher.php on line 96 Followed by: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /es/blah" in /var/www/project/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php on line 145 I am testing an error page for a...

PHP Silex routes base url

routes,silex,base-url
My project is just a test API project on a local server in a subfolder. So my url would be http://localhost/test-project-x/api/. In there is an index.php. The root route is available through the URL above. But as soon as I go to http://localhost/test-project-x/api/test I get a 404. To get this...

Where has the Twig function 'render' in templates gone?

php,twig,silex
I have just updated my dependencies for my Silex application and now suddenly one of my templates is failing with the error: Twig_Error_Syntax: The function "render" does not exist. This was working fine before I performed a composer update. From the composer output the following have been updated: - Removing...

update row using php framework silex

php,mysql,angularjs,api,silex
I am making an angular application, for the backend I am creating a REST api using symphony's microframework: silex. On a certain update I keep getting an internal server error. All I try to do is update the weight. $app->put('/{id}/updateWeight', function ($id) use ($app) { $sql = "UPDATE results SET...

Command line Doctrine ORM with Silex: You are missing a “cli-config.php” or “config/cli-config.php” file in your project

php,symfony2,doctrine,silex
I am trying to use Doctrine ORM with Silex, and finding it an altogether frustrating experience, due to the lack of consistent documentation. When I run vendor/bin/doctrine at the console, I get the following output: output: You are missing a "cli-config.php" or "config/cli-config.php" file in your project, which is required...

How sending parameter in the controller method of Silex - PHP

php,routes,silex
I'm using silex and I'm trying to pass a parameter controllers , but do not work. My code below: <?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/vendor/autoload.php'; use Silex\Application; use Symfony\Component\HttpFoundation\Request; class TestController { public function testAction(Request $request, Application $app, $value) { var_dump($value); return 'test'; } } $app = new...

Silex can't find Controller Class

php,controller,silex
project directory structure /composer.json /web/index.php /app/controller/IndexController.php composer.json { "require" : { "silex/silex": "*" }, "autoload": { "psr-0": { "": "./" } } } index.php require_once __DIR__.'/../vendor/autoload.php'; use Silex\Application; $app = new Application(); $app['debug'] = true; $app->get('/', 'App\\Controller\\IndexController::getIndex'); $app->run(); IndexController.php namespace App\Controller; use Silex\Application; class IndexController { public function getIndex(Application $app)...

silex and twig css cache issues - odd behavior

css,google-chrome,twig,phpstorm,silex
I've run into a very frustrating bug. I can't reload changes in my css file. style.css seen in PhpStorm looks like: body { background-color: blue; } Yet seen in Chrome shows: body { background-color: green; } Here's the odd behaviour: If I change style.css to "foo bar testing" Chrome displays...

Attempted to call method “share” on class “Silex\Application” in Silex 2

symfony2,silex
I am developing a project with silex-skeleton in its most recent version. When trying to use the share method shows me the following error: Code: $app['login'] = $app->share(function() use($app) { return new Model\UserModel($app); }); Error: Attempted to call method "share" on class "Silex\Application" Any suggestions or possible cause of this...

How to overwrite a class from the Security Component?

php,symfony2,authentication,silex
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...

dissociated variables in array

php,variables,silex
I have a problem with php variables. I use a code that looks like this: for($i = 0; $i <= $nbRecurrence; $i++) { $res = new Reservation(); $res->setDateDebut($DateDebut->add(new \DateInterval('P1D'))); $res->setDateFin($DateFin->add(new \DateInterval('P1D'))); $lesRes[] = $res; $this->app['orm.ems']['gestionReservationAuto']->persist($res); $this->app['orm.ems']['gestionReservationAuto']->flush(); } The problem is that although I adds each element in the array, but...

Silex Framework, no route found for POST

php,forms,twitter-bootstrap,routing,silex
I have a little problem with the silex framework (I'm quite sure, that it's caused by Silex).. I have a form and want to submit it with POST, but Silex throws the following exceptions: MethodNotAllowedException in UrlMatcher.php line 101: MethodNotAllowedHttpException in RouterListener.php line 149: No route found for "POST /checkPW":...

Silex namespace : class MainController does not exist

php,class,namespaces,autoload,silex
I try to use Silex Framework, but i have a problem with namespaces I think. when I instanciate my class MainController i have the following error : Class "MainController" does not exist here the namespace declaration in my MainController.php : namespace App\Controllers; use Silex\Application; class MainController implements \Silex\ControllerProviderInterface { .......

Composer: unresolvable dependencies when installing Silex application

php,composer-php,silex
I am trying to build a Silex application, with the following requirements requirements Yaml configuration Doctrine ORM Simple User Authorisation my composer.json { "require": { "silex/silex": "~1.2", "symfony/yaml": "2.6.7", "doctrine/dbal": "~2.2", "deralex/yaml-config-service-provider": "1.0.x-dev", "dflydev/doctrine-orm-service-provider": "2.0.*@dev", "jasongrimes/silex-simpleuser": "~1.0" } } When I run composer update, I get the following output Loading...

silex loop one sql statement over another one

mysql,symfony2,doctrine,twig,silex
I have to get team members by their groups from a database. My Database looks like: table team_groups: id name table team_member: id name description imagepath team_group_id I have an twig template where the team_members are shown by there groups like this: <div class="row row-centered"> <h3 class="text-center">{{team_group.name}}</h3> <div class="col-xs-6 col-centered...

forcing silex framework to generate https links

php,symfony2,https,routing,silex
My entire application should be accessed over HTTPS, The vhost is correctly configured and when I call any of my application pages with the HTTPS prefix, it responds correctly. However when I try to access a page through a generated link within my application. it always points to a regular...

Automatically inject dependency

php,symfony2,dependency-injection,silex
I can't understand why Silex\Application object is injected in some classes but in others not. Here is an example Example 1 / Controllers Admin LoginController.php namespace SD\Controllers\Admin; use Silex\Application; class LoginController { public function loginAction(\Silex\Application $app) { //in this method Application object is injected automatically } } Example 2 /...

Silex: Pass a variable to a controller class

variables,controller,silex
I already managed to pass the parameters of a route to a class, using this: $app-get('/{$id}', 'OwnClass\Bazinga::lizard'); class Bazinga { public function lizard($id, Application $app, Request $request) { return "Scissors cuts paper, paper covers rock, rock crushes lizard..."; } But how do I pass a global variable to a class...

silex file structure for custom service providers

php,namespaces,silex
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...

Silex + RememberMeServiceProvider - login from code

silex
I'm trying to make an ajax login form. I've configured RememberMeServiceProvider according to http://silex.sensiolabs.org/doc/providers/remember_me.html It works great with default login form - the one that goes to 'login_path' and is managed by Silex. I'm now trying to make custom login controller (AJAX only). It looks like this: public function ajaxLogin(Request...