14 articles PHP

Rendering Twig templates from Symfony Repository without Using Dependency Injection (DIC)

Sometimes it's useful to access Twig templates from a Symfony repository, one could argue that this goes against a repository's role, but if you think of Twig template files or Twig strings perhaps grabbed from a database as data, then this coincides nicely with the function of a repo. These arguments aside, whatever your situation,…

PHP: Checking if a form was posted with “REQUEST_METHOD” server global

Something so simple, let's say even in a framework like Symfony which I use all the time you want to just check to see if the incoming request was initiated by an actual form post.  Here's the best way to check: I implement this switch in a lot of handlers where I deploy API…

General API interface with CURL: A simple way to access most APIs — use as is or extend as necessary

Since you likely interface with a lot of external APIs, there's no need to keep rewriting the same tool.  Just copy this and use the "apiBaseController" class as you need it.  It's a good, clean way to start any API accessing project!  

PHP Developers: Pre-made state pulldown lists for HTML forms

I like to reuse code as much as possible and if there's underyling data in something I'll use again, I'll put that data in some extractable form in an EAV (Entity, Attribute, Value) database table so I don't need to maintain the data anywhere except one place. So in the example below where the variable…

ZIP and password protect any file with simple script using PHP

"Rusty Padlock" artwork used with permission from ProlificFutility.com You may need to password protect a file before sending it to someone.  Yes, there are Windows utilities, some free, that do this but I found this script works surprisingly well as long as "zip" is installed on your server. Just simply save…