Menu
  • HOME
  • TAGS

Trouble using Silex framework on IIS

symfony2,iis,iis-7.5,silex

Turns out I just needed to install the rewrite module for IIS at the following link: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module...

Silex can't find Controller Class

php,controller,silex

Sigh, it was a capitalization issue. My macbook has a case insensitive filesystem and my linux VPS has a case sensitive filesystem so when deploying to Linux I had to capitalize the directories in my project so that Silex could correctly resolve the controllers.

Silex, in symbollically liked subdirectory, does not route

php,.htaccess,url-routing,symlink,silex

Your RewriteBase directive is wrong, its related to web root, not your filesystem structure, so just use RewriteBase /silex/

Silex Framework, no route found for POST

php,forms,twitter-bootstrap,routing,silex

Look, you only define a route for get: $app->get('/checkPW', function () use ($app) { return $app['templating']->render( 'checkPW_blog.php' ); }); Just define one for post: $app->post('/checkPW', function () use ($app) { // do post stuff... }); ...

Silex 'App\Controller\IndexController' not found on server

php,.htaccess,silex

@Maerlyn "You have folders app and controller, not App and Controller like in your namespace." This made me on the right track ! I have renamed my folders with first letter uppercase and it was worked. But I thought about the Silex vendor wich was working with uppercase namespace...

Adding data to a session

php,silex

The session api is quite minimalistic, has no functionality that you need. The quick fix is to retrieve the current value, add to it and then set it again: $foo = $app["session"]->get("foo", array()); $foo[] = $newData; $app["session"]->set("foo", $foo); If you're ready to dive into code, you may also create your...

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

symfony2,silex

Silex 2.0 is using Pimple 3.0 which has removed the shared method, now all services are shared by default, if you want a new instance you must call the factory method as stated in the changelog for version 2.0. So if you want a login service you should create it...

Ajax route works offline, not on server + Silex

php,ajax,symfony2,routes,silex

Long shot, but do you have anything in your .htaccess for friendly urls? This could be screwing it

WebTestCase, Silex and $_GET

symfony2,silex,web-testing

The server globals (like $_GET) are populated by Apache. When running the functional test, Apache is skipped so $_GET is not populated anymore. Instead of using the server globals, you should use the Request object to extract the GET parameters. This way, the framework will intercept both the PHPUnit injected...

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

You need to move bin/cli-config.php in config/cli-config.php. Unfortunately I have not found documentation about it. I opened doctrine/dbal/bin/doctrine-dbal.php and checked how it worked....

Why UrlGenerator generate path without host and scheme in Silex?

symfony2,silex

To generate an absolute URL you have to do that : $app['url_generator']->generate('blog.posts.index', [], true); ...

silex file structure for custom service providers

php,namespaces,silex

Vendor folder is supposed to contain only composer dependencies, so it is for sure a bad design to add some specific classes there manually. You can put your custom Service providers into separate git repositories and use them in your project via composer. Or, if this way too hard to...

Capturing POST data with Silex/Bolt

php,silex,bolt-cms

This is just a question of understanding the Request/Response process in Silex. The initialize method in your extension is run before the request cycle starts, to access it you need to register a controller which can then setup routes to handle requests. Here's a simple example. // In Extension.php public...

silex loop one sql statement over another one

mysql,symfony2,doctrine,twig,silex

Oh yeah twig is really nice... I thought I have to link the objects in the controller, but now I simply wrote: {% for teamGroup in teamGroups %} <div class="row row-centered"> <h3 class="text-center">{{ teamGroup.name }}</h3> {% for teamMember in teamMembers %} {% if teamMember.team_group_id is same as(teamGroup.id) %} <div class="col-xs-6...

How to debug php fatal errors in Silex Framework

php,debugging,silex

Try this: use Symfony\Component\HttpKernel\Debug\ErrorHandler; use Symfony\Component\HttpKernel\Debug\ExceptionHandler; // set the error handling ini_set('display_errors', 1); error_reporting(-1); ErrorHandler::register(); if ('cli' !== php_sapi_name()) { ExceptionHandler::register(); } // init application $app = new Silex\Application(); // set debug mode $app['debug'] = true $app->run(); it's important to set the error handling before initialize the $app....

How to retrieve custom columnDefinition of Doctrine2 Entity?

php,orm,doctrine2,entitymanager,silex

You should be able to grab the info you want like this: $metadata = $em->getClassMetadata('My\Entity'); $myPropertyMapping = $metadata->getFieldMapping('myProperty'); A "field" in Doctrine is a property of an "entity" that has mapping information, but is not an "association". In other words: if you've defined a @Column annotation in the docblock, it's...

forcing silex framework to generate https links

php,symfony2,https,routing,silex

For that specific case, I solved the problem declaring a base url like so in app.php: $app['customBaseUrl'] = 'https://mybaseurl'; then prefixed all my links with this custom baseUrl. Those links aren't generated by the url() twig function anymore. Not the prettiest way to do it though. I would recommend Artamiel's...

update row using php framework silex

php,mysql,angularjs,api,silex

Thanks for responding guys, I took another look at the error right before I wanted to post it and I found the problem. I assumed the error was created inside the piece of code I posted above but actually it seemed that this route got mixed up with another one,...

How to sort by a certain key of an Array in Silex/Twig

php,arrays,sorting,twig,silex

What about using some PHP? usort($data, function($a, $b) { return strtotime($a['timestamp']) < strtotime($b['timestamp']) ? -1 : 1; }); If you are getting the data from a database then you should let the database sort it for you. It is a lot faster than doing it yourself....

Wrong path in Silex templates

symfony2,twig,silex

Solution: In your template replace your relative paths with: {{ app.request.basepath }}/your/path/js...

Silex - How to process template includes separately

symfony2,templates,include,silex

Yes. They are called sub requests. Read the documentation here.

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

php,symfony2,routes,silex

This is probably best accomplished with route middleware: use Silex\Application; use Symfony\Component\HttpFoundation\Request; $app = new Application(); $setup = function (Request $request) use ($app) { $auth='code'; require __DIR__.'/assets/helpers.php'; }; $app->get('/', function() use ($app) {}) ->before($setup); $app->get('/login', function() use ($app) {}) ->before($setup); The only thing I am not sure of here is...

Turning off Warning/Errors for ResourceNotFoundException

php,symfony2,exception-handling,routing,silex

So, I've figured this out. As said above, I was getting messages about Exception handling, but Silex and $app->error(Exception $e) should catch exceptions. In fact, exceptions were thrown and being caught properly. In my original question, I mention Xdebug, which was the problem. Xdebug has a setting xdebug.show_exception_trace that when...

Silex and Doctrine mysql: how to return results from select all

php,mysql,symfony2,doctrine2,silex

And what is a problem? In the second piece of code db returns the array of associated arrays. and to show each item from it you have to use some kind of loop. The return example you provided is ugly, actually. Why don't you use some template engine (like twig...

Composer: unresolvable dependencies when installing Silex application

php,composer-php,silex

Two of your dependencies require different versions of pimple package: silex/silex v1.2.0 requires pimple/pimple ~1.0 dflydev/doctrine-orm-service-provider v2.0.0 requires pimple/pimple >=2.1 You can switch to latest silex or previous version of doctrine-orm-service-provider to resolve this. Look at packagist.org to see available versions with their dependencies: silex, doctrine-orm-service-provider....

Silex namespace : class MainController does not exist

php,class,namespaces,autoload,silex

I believe your problem is caused by the way you named your directory controllers. According to the documentation about PSR-4 standard: 5) Alphabetic characters in the fully qualified class name MAY be any combination of lower case and upper case. 6) All class names MUST be referenced in a case-sensitive...

Redirect after login succes + Silex

php,symfony2,cookies,login,silex

I am not sure that this is correct, but I believe you have to return object of another instance, see this question for details (particularly the answer of igorw) Another option is to intercept the AUTHENTICATION_SUCCESS event of the dispatcher, I tried the following: $app['dispatcher']->addListener(AuthenticationEvents::AUTHENTICATION_SUCCESS , function($authEvent) use ($app) {...

Silex render controller inside twig error

symfony2,twig,silex

I had to ignore the error by wrapping it with a try/catch block for it to work. It's a dirty solution but worked. try { $twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) use ($app) { return $app['request_stack']->getMasterRequest()->getBasepath().'/'.$asset; })); } catch (Exception $e) { // do nothing } ...

Automatically inject dependency

php,symfony2,dependency-injection,silex

Silex does parameter conversion in controllers (and in controllers only), so in the controllers methods you can type hint and expect to "automatically" have the instance, but not anywhere else. From the official docs: You can (in the controller method) use Request and Silex\Application type hints to get $request and...

How to know if this request triggered by a redirection in Silex?

php,redirect,silex

Having your example in mind, you can send the url as a GET parameter, and check the request for it, instead of checking the referer. Another way would be to store the url in the session before doing the redirect, and then check the session in the route/s you are...

Silex : The token storage contains no authentication token

silex

Since the error message says that the error happens in layout.html, I'm guessing it is used on every page even the ones like /login that is not behind a firewall. The error is caused by calling is_granted when not behind a firewall. So there are a few options: Use a...

How sending parameter in the controller method of Silex - PHP

php,routes,silex

Your code is correct. That's 404 error that you get is from apache. You need to call your page with http://site/index.php/value. If you want remove index.php from the url then follow this page....

Silex + RememberMeServiceProvider - login from code

silex

The problem is that you bypass the security listerner to create the authentiated token by yourself. To create the remember-me cookie, you must trigger the loginSuccess method of your RememberMeServices. $app['security.remember_me.service.my-firewall']->loginSuccess($request, $response, $token); Otherwise, you should implement your own PreAuthenticator : http://symfony.com/doc/current/cookbook/security/api_key_authentication.html...

Low TPS using Virtualbox + Ubuntu + Nginx + PHP-FPM + Silex

php,ubuntu,nginx,php-fpm,silex

Found the issue, it's the Virtualbox share that's extremely slow. Moving the code to a folder on the VM resulted in a 15 fold TPS increase.

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

php,twig,silex

I had the same problem. Did you register HttpFragmentServiceProvider before registering the Web Profiler? It is not obvious, but the documentation mentions about it here. It worked nicely for me. Regards...

Silex/Google API

google-api-php-client,silex

You should never add your dependencies in your autoload map (composer does that for you). In this case, google PHP API client is not namespaced so composer can't autoload the library using namespaces. In order to use it you just need to append the root namespaces before the class: <?php...

Silex/Twig : Conflict between a custom filter and form widget

php,twig,silex

The Silex documentation show the following code as example: $app['twig'] = $app->share($app->extend('twig', function($twig, $app) { $twig->addGlobal('pi', 3.14); $twig->addFilter('levenshtein', new \Twig_Filter_Function('levenshtein')); return $twig; })); I think you should try to add the filter in this way....

Soap connection with Silex

php,soap,silex

You need to specify the namespace of class you are trying to instantiate. use Ibsciss\Silex\Provider\ZendSoapServiceProvider; ...

PHP Silex routes base url

routes,silex,base-url

Just use the RewriteBase with the correct folder: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /test-project-x/api/ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule> And there you have, your routes now are on the /test-project-x/api folder....

How to use Pimple C Extension

php,silex,pimple

PHP will use the extension's one. This is because autoloading will only happen if you are attempting to access a class which does not already exist. Extension functions and classes will exist after PHP's startup meaning before the code starts to run. (answers from hek2mgl user)...

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

routes,silex

The trick is to overwrite the default regex for a url parameter, that doesn't match /: $app->post("/something/{the_rest})", function () { // do stuff })->assert("the_rest", ".*"); ...

Silex namespaces

php,namespaces,silex

You need to add your source folder into the composer autoloading (https://getcomposer.org/doc/01-basic-usage.md#autoloading) "autoload": { "psr-4": {"Acme\\": "./"} } In your case the path "./" should work (have not tested), if not you should try to put cms folder into a folder like src and set the path to "src/" Remember...

“Using $this when not in object context” appears in Silex/phpunit case

php,symfony2,phpunit,this,silex

You use $this inside a closure. Prior to 5.4, the $this could not be used inside the closure. Since 5.4, $this refers to the object that it is declared in. To be able to run your tests in PHP 5.3, you have to use something like: public function register(Application $app)...

POST nested Json with Silex

php,json,post,silex

It's quite simple actually. After you decode your json object, pull_request becomes an array, and therefore if you want to access state you need to refer to pull_request first. One way would be the so called array dereferencing, like this: 'state' => $request->request->get('pull_request')['state'] but in order to use that syntax,...

How to overwrite a class from the Security Component?

php,symfony2,authentication,silex

Ok so here's what I did in case someone wonders: First in my Security folder, I created my own version of the BasicAuthenticationEntryPoint.php <?php /* * Redefinition of the Symfony's BasicAuthenticationEntryPoint */ namespace multikanban\multikanban\Security\Http\EntryPoint; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; /** *...

PHP: How to prevent serialize from hitting a certain member

php,symfony2,silex

You need to implement Serializable to your User Object. class User implements UserInterface, Serializable { // ... public function serialize() { // see http://php.net/manual/en/serializable.serialize.php return serialize(array( $this->id, $this->username, $this->password )); } public function unserialize($serialized) { // see http://php.net/manual/en/serializable.unserialize.php list ($this->id, $this->username, $this->password) = unserialize($serialized); } } EDIT Warning: This answer...

How can I make the entity field type available in silex?

symfony2,doctrine2,silex

I use this Gist to add EntityType field in Silex. But the trick is register the DoctrineOrmExtension form extension by extending form.extensions like FormServiceProvider doc says. DoctrineOrmExtension expects an ManagerRegistry interface in its constructor, that can be implemented extending Doctrine\Common\Persistence\AbstractManagerRegistry as the follow: <?php namespace MyNamespace\Form\Extensions\Doctrine\Bridge; use Doctrine\Common\Persistence\AbstractManagerRegistry; use Silex\Application;...

Silex: Pass a variable to a controller class

variables,controller,silex

I would use $app container to share globals throught controlers (and other places): $app->get('/{$id}', 'OwnClass\Bazinga::lizard'); $app['a.unique.identifier'] = $globalvariable; class Bazinga { public function lizard($id, Application $app, Request $request) { $globalvariable = $app['a.unique.identifier']; return "Scissors cuts paper, paper covers rock, rock crushes lizard..."; } } ...

silex and twig css cache issues - odd behavior

css,google-chrome,twig,phpstorm,silex

Turns out the issue is with running Nginx withing VirtualBox. in /etc/nginx/nginx.conf sendfile needs to be off...

add element to array in PHP

php,silex

You can try to use a reference (with &) instead of a copy and add the item: foreach ($result as &$DN) { $DT = $DN['dateN']; $am = explode('-', $DT); $an = explode('/', date('Y/m/d')); $age = $an[0] - $am[0]; $DN['age'] = $age; } ...

dissociated variables in array

php,variables,silex

I guess $DateDebut is a DateTime object. I also guess that Reservation::setDateDebut() looks something like: class Reservation { private $dateDebut; public function setDateDebut(DateTime $dateDebut) { $this->dateDebut = $dateDebut; } } And let's write again the code that uses it: $res = new Reservation(); $res->setDateDebut($DateDebut->add(new \DateInterval('P1D'))); What you miss is the...

Symfony RememberMe token_provider

symfony2,silex,symfony-security

This parameter is a service id of a token provider to use. Services id are strings (then Symfony looks for the class in the DIC, Silex does the same) so you need to declare a FQDN of your token provider class. By default Symfony uses the Symfony\Component\Security\Core\Authentication\RememberMe\InMemoryTokenProvider class If you...

silex webprofiler not displaying logs

php,symfony2,composer-php,silex

This was caused by a bug. No longer an issue. https://github.com/silexphp/Silex-WebProfiler/pull/38

register namespace in silex without composer

php,composer-php,autoload,silex

Hello, The following line: $loader->add('App', __DIR__ . '/../App/'); Should be: $loader->add('App', __DIR__ . '/../'); ...

Silex ControllerCollection not cascading __call to fellow ControllerCollection

php,symfony2,routing,silex

The issue lies in the ControllerCollection's implementation of __call(). The ControllerCollection first checks if it supports the method: if (!method_exists($this->defaultRoute, $method)) { throw new \BadMethodCallException(sprintf('Method "%s::%s" does not exist.', get_class($this->defaultRoute), $method)); } And then it cascades the calls to it's Controllers (it is a Collection of Controllers, afterall): foreach ($this->controllers...

Missing variable in silex, php

php,silex

Variables inside function are not global, means you need to instantiate Request again inside addComment() function public function addComment($data, Request $request) { $posts_id = (int)$request->get('posts_id'); $sql = 'INSERT INTO comments (comment, date, posts_id) VALUES (?,?,?)'; $this->_db ->executeQuery( $sql, array( $data['comment'], $data['date'], $data['posts_id'] ) ); } ...

Adding array key dynamically PHP

php,arrays,silex

You could accomplish it like this: $form = $app['form.factory']->createBuilder('form'); $options = array( 'data' => $from ); if($disabled == 'true'){ $options['disabled'] = true; } $form->add('email', 'email', $options) ...

Silex session set a lifetime

php,symfony2,session,session-cookies,silex

Silex uses the Symfony Components. You can set the expiration using the migrate method for a certain session. E.g.: $app['session']->migrate(false, 3600); Docs To set the expiration for all sessions: $app['session.storage.options'] = [ 'cookie_lifetime' => 3600 ]; Source...

Send array as a parameter + twig

php,arrays,symfony2,twig,silex

To pass an array in a GET request check this answer how to pass an array in GET in PHP?. You can also do that on a POST request, for instance using a form as described here Passing arrays from HTML form to PHP. But in your case it seems...

Silex FormServiceProvider and form.secret parameter

php,silex

You can see it being used in line 100, when $app["form.csrf_provider"] is first accessed: $app['form.csrf_provider'] = function ($app) { if (isset($app['session'])) { return new SessionCsrfProvider($app['session'], $app['form.secret']); } return new DefaultCsrfProvider($app['form.secret']); }; Since whatever you pass is ignored and overwritten with the md5 call you mention, correct usage would be: $app->register(new...

Mount operation in Silex - additional trailing slash

php,symfony2,silex

There is a difference between mounting a collection of routes and simply limiting a route to post. Adding mount means that a collection of routes are being created under specific namespace, in your case that would be /other. Meaning that the default URL for this namespace would be /other/ -...

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

php,silex

There's an annotation, @Bind, that let you give a route a name. Example: use DDesrosiers\SilexAnnotations\Annotations as SLX; /** * @SLX\Controller */ class TestController { /** * @SLX\Route( * @SLX\Request(method="GET", uri="foo"), * @SLX\Bind(routeName="foo") * ) */ public function testMethod() ...