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...
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.
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/
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... }); ...
@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...
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...
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...
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...
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....
To generate an absolute URL you have to do that : $app['url_generator']->generate('blog.posts.index', [], true); ...
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...
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...
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...
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....
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...
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...
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,...
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....
Solution: In your template replace your relative paths with: {{ app.request.basepath }}/your/path/js...
symfony2,templates,include,silex
Yes. They are called sub requests. Read the documentation here.
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...
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...
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...
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....
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...
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) {...
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 } ...
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...
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...
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...
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....
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...
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...
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...
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....
You need to specify the namespace of class you are trying to instantiate. use Ibsciss\Silex\Provider\ZendSoapServiceProvider; ...
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....
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)...
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", ".*"); ...
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...
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)...
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,...
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; /** *...
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...
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;...
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..."; } } ...
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...
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; } ...
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...
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...
php,symfony2,composer-php,silex
This was caused by a bug. No longer an issue. https://github.com/silexphp/Silex-WebProfiler/pull/38
php,composer-php,autoload,silex
Hello, The following line: $loader->add('App', __DIR__ . '/../App/'); Should be: $loader->add('App', __DIR__ . '/../'); ...
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...
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'] ) ); } ...
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) ...
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...
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...
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...
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/ -...
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() ...