In Symfony using Doctrine, if no association is available for two entities, you can still join them and treat them like they have a relationship.  To do so, you have to use the “Join: WITH” method.  Here’s an example query to illustrate, notice the “a.user = u.id”.

public function getHistory($users) {

    $qb = $this->entityManager->createQueryBuilder();
    $qb ->select('a', 'u')
        ->from('Credit\Entity\UserHistory', 'a')
        ->leftJoin(
            'User\Entity\User',
            'u',
            \Doctrine\ORM\Query\Expr\Join::WITH,
            'a.user = u.id'
        )
        ->where('u = :user')
        ->setParameter('user', $users)
        ->orderBy('a.created_at', 'DESC');

    return $qb->getQuery()->getResult();
}

Some other helpful links on Stack Overflow:

http://stackoverflow.com/questions/15087933/how-to-do-left-join-in-doctrine

http://stackoverflow.com/questions/19185587/left-join-on-condition-and-other-condition-syntax-in-doctrine/19189240#19189240

Here’s a great reference for advanced Doctrine queries:

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html#high-level-api-methods


Integrating a WordPress user login with Symfony is pretty painless if you need to share user sessions.  Just don’t rely solely on that WordPress cookie, but cross reference a randomly assigned hash that can reference back to the WordPress user’s table.  When you get your system to authenticate a user and you find your FOS User Bundle session expired and forces the user to log back in, you can save them the trouble by “synchronizing” the WordPress user session by logging them in automatically in the FOS User Bundle like so:

$user=$userManager->findUserByEmail($userEmail);

if($user){
   $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
   $this->get('security.context')->setToken($token);
   $this->get('session')->set('_security_main',serialize($token));
}

Be sure to add this “use statement” up top in your controller/repo:

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

 


Accessing the Google Map API for your own in-form location input widget which allowss users to “pin” their location on a Google map and allow you to store their map location, latitude and longitude in your database is easy with this library.  It’s just like the JQuery calendar widget — it’s as simple, clean and reliable!

Here’s a sample of how to use this code.

<fieldset class=”gllpLatlonPicker”>
<div class=”gllpMap”>Google Maps</div>
<br/>
<input type=”hidden” class=”gllpLatitude”/>
<input type=”hidden” class=”gllpLongitude”/>
<input type=”hidden” class=”gllpZoom”/>
<input type=”text” class=”gllpLocationName” size=42/>
</fieldset>

To learn more, check this powerful library out and check out the demo here!


It’s amazing how much bloat your Windows machine can accumulate, it’s worse than eating too much over the holidays!

I ran Piriform CCleaner on my machine and it freed up over 2 GBs of unnecessary files.  Lots of small files added up really taxes your system.  Also, the registry tools worked superbly in improving my bootup speeds.

Download the free version of Piroform today!


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:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   //Do something unique here like redirect or  pass post data to another method
}

I implement this switch in a lot of handlers where I deploy API clients that deliver forms on a site but the forms aren’t actually built from the site — the API pulls the form from some centralized controller.