I created this page as a running repository of useful, miscellaneous web notes for later reference.


Javascript & JQuery

How to get the latest version of JQuery:

alert('JQuery: '+$.fn.jquery);   // Outputs JQuery: x.x.x

Useful info about Javascript and JQuery source maps — an explanation about what they are and how they are used:

http://elijahmanor.com/the-magic-of-the-jquery-1-9-source-map/

Parsley — A reliable and easy Javascript form validation library:

http://parsleyjs.org/

Get hostname in Javascript:

// For the host name only, use:

window.location.hostname

Server Notes, LAMP/WAMP

Latest WAMP install instructions — in less than 5 minutes you can deploy WAMP with MySQL server on localhost.  Not bad for quick local dev server.

http://forum.wampserver.com/read.php?2,123606


Symfony

A utility for Symfony to convert those awful annotations to YML files:

https://packagist.org/packages/sed/route-exporter-bundle


Helpful Symfony 3.0 base commit, to start new PHP Symfony projects:

https://github.com/itrascastro/Symfony-3-Base-Project
https://github.com/keefekwan/symfony2_forms

Best example of a form collection at work I think is here (many thanks to the programmers making these publicly accessible!)

https://github.com/sevnekish/user_manager


Symfony 2 performance tips:

http://labs.octivi.com/mastering-symfony2-performance-internals/

Form Type setDefaultOptions weird error:

http://stackoverflow.com/questions/31659102/symfony2-error-on-submitting-form-with-a-collection-of-forms-warning-spl-obj?rq=1


General Web Notes & Utilities

Free OST file viewer worked well, allows you to save a person’s Microsoft Exchange mailbox email file and open and view the contents without messing with the .ost file in Outlook!

http://www.ostviewer.com/

Waka Time — Free web development time tracking utility:

https://wakatime.com

Websites that show the latest hiring trends in the tech industry:
https://news.ycombinator.com/item?id=11202954

https://whoishiring.io/#!/stats/

A good simplified explanation and list about HTTP 2:

https://www.keycdn.com/support/http2/

Good article about the anatomy of a URL:

http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/

Steps for setting up DNS on a Ubuntu server:

http://mixeduperic.com/ubuntu/seven-easy-steps-to-setting-up-an-interal-dns-server-on-ubuntu.html


PHP/MySQL

PHP SQL injection – good article:

http://phpdelusions.net/sql_injection



Aaron Belchamber
22 years experience in marketing and building businesses

Senior PHP & Symfony Web Developer, Business Analyst, Marketing Director
Belchamber.us / TopDocsTalk.com
(904) 294-0803 • Jacksonville, Florida


Strange how obscure it is to find a clear example of how to just access or show the value of a cookie in Twig, so here it is!

{{      app.request.cookies.get('yourCookieHere')  }}

Twig is the templating engine that powers Symfony views.  Symfony is the PHP framework from Sensio Labs.

If you are a company that uses open-source software and developers and you are not using a PHP framework, you should consider migrating your legacy “cowboy” code to a collaborative, scalable framework like Symfony before it becomes a necessity for your company.  I have overseen many migrations of systems and data over the years and am available for consultation at my business consulting site at Belchamber.us.

– Aaron Belchamber


In the newest versions of Symfony greater than 2.2 you can embed output from controller by calling it with this handy TWIG snippet:

{{ render(controller('PostBundle:Posts:recentPosts', { 'category': 'cool symfony tips' })) }}

Check out Sensio Lab’s documentation to learn more.

This is especially useful if you want to create a snippet that will deliver content independent of the controller you are calling the main content of the page — stuff around the periphery.  As long as you aren’t using any logic, this is an acceptable use of MVC and it decouples say content in a related widget on the page from the controller of the page’s main content.  This separation of concerns ensures the controller of the main content stays as lean and clean as possible!


Besides making sure your server is running PHP 5.4 or higher, after updating from Symfony 2.3 to 2.6.3, I had to roll back a few dependency packages I found were conflicting and weren’t tested and cleared to work with the newest version of Symfony.  Some of the latest compatibility requirements are found here.  The latest compatibility issues can be found here.

However, the only thing I found to break was something silly and small that never should have been part of my older Symfony project and that had to do with my routes’ controllers.  On occasion, I included “Action” after the method name in the controller declaration and Symfony was okay with it and it’d find the method it knew I meant to use.

However, upon upgrading to Symfony 2.6, the controller methods declared in routes looked for an “ActionAction”, meaning Symfony added the word “Action” at the end of the controller name.  No where in the docs did it ever say to add “Action” anyway, it was an oversight on my part that this newest version of Symfony does not allow.  So, check your routes to make sure you leave out “Action” at the end of the method name for the controller method the route is supposed to send the session to or you’ll get an error.

– Aaron Belchamber


At last, a framework has finally given the tilde (~) a little respect. Hash tag (#) usually gets all the glory, but not this time!  Not is in this case.  Granted, the tilde might be happy to be used at all and chances are, this obscure solution to another view issue doesn’t mean tilde’s ready for primetime, but let’s show some respect when respect is due.  After all, without the tilde, you wouldn’t be able to dynamically create field names with string concatenation.

Symfony’s TWIG uses the tilde to help dynamically address or declare form fields.  This is handy if you have a bunch of form fields with hideous serialized numbers appended to them like “field_name_1” and “field_name_2″….  Without addressing all 50 of these, you can loop through them dynamically like so.  In this example, I only loop from 0 to 4.  An added bonus?  I check if the form field name exists.  That’s helpful in case you’re receiving form fields that are dynamically added and you don’t know how many possible form fields your antiquated form made, probably through some Javascript or using JQuery.

{% for i in 0..4 %}
   {% if attribute(form,'field_name_'~i) is defined %}
       {% for formItem in attribute(form,'field_name_'~i) %}
            
            {{ form_row(formItem) }}

       {% endfor %}
  {% endif %}

{% endfor %}

The only question is…. why didn’t you just use an array for those form fields?!  field_name[0], field_name[1] is much easier, but who am I to judge?