Check if the variable is defined in symfony twig

In twig, specially for the templates being used by many controllers, there might be variables set by one controller but not by others.

Well one way to address could be to have dummy data on each controller and either to check for that dummy value and do something or just to print it

But, symfony has a way to check if the variable has made it to the template or not

{% if some.variable is defined %} what a world {% endif %}

so the usage of defined can rescue us.

, , , ,

Leave a comment

XDebug connects but doesn’t stop on breakpoints

The first one would be just to double check if we have correct configuration for xdebug.
But the main and common culprit for this is using

extension=xdebug.so
inplace of
zend_exention=xdebug.so

in php.ini

, , , , ,

Leave a comment

Serve more than one site using virtualhosts on mac OSX

There would be a need for this or that reason to serve more than one site from apache. And this is quite possible using configuration inside the apache

First thing first
go to the apache config, by default it should be

/etch/apache2/apache.conf

And search for

#Include /private/etc/apache2/extra/httpd-vhosts.conf

Which, as you can see, is commented. Hence uncomment that by deleting the # infront of it.

The above task will allow us to mess around the httpd-vhosts.conf file that is in the extras directory.

Lets assume we have a site names siteVH which is residing in the directory /www/sitevh
and lets assume we have another site called siteAnother residing in director /www/siteanother

Now the goal is to access those sites independently. So we will create two different virtual hosts for each one and be able to access them independently


    ServerAdmin youreamil@domain.com
    DocumentRoot "/www/siteVH"
    ServerName sitevh.com
    ServerAlias local.site
    ErrorLog "/private/var/log/apache2/sitevh.log"
    CustomLog "/private/var/log/apache2/sitevh.com-access_log" common
    
        AllowOverride All
        Order allow,deny
        Allow from all
        Options Indexes FollowSymLinks
    

And the we will have the same duplicate values for the other one as well.

Then update the /etc/hosts to let know our local “DNS” :) to know what to do

127.0.0.1 sitevh.com siteanother.com

This shall take care of the whole thing.
One more thing, restart apache

sudo apachectl restart

, , , , ,

Leave a comment

Change the name of computer in Mac

When setting up a new mac, you will have the default lengthy name that would appear on your terminal. Here is how to change the computer name in mac
here

On your terminal:

sudo scutil HostName short-name 

Where ‘short-name’ is what ever you want to be your computer name

That is it!

, , , , ,

Leave a comment

Mommy look.. Upgrading jQuery breaks live :(

If you have upgraded jQuery to 1.9 then you would have dreaded Uncaught TypeError: undefined is not a function would be barking at you on your javascript console.

The fix
According to the jQuery site, you would need to replace live with on

Say if you have:

$('.selector-class-name').live('click', function(){console.log('
Applications programming is a race between software engineers, who strive to produce idiot-proof programs, and the universe which strives to produce bigger idiots. So far the Universe is winning.
Rick Cook
')});

Then you would have to change this to the new version using on as follows.
*The current on will be passed the event owner as a parameter so, we have to have a way to know the parent of the event owner, in this case the object with class selector-class-name.
If we don’t know the parent we can implement body tag

$('parent-of-object').on('click', '.selector-class-name', function(){
Applications programming is a race between software engineers, who strive to produce idiot-proof programs, and the universe which strives to produce bigger idiots. So far the Universe is winning.
Rick Cook
});

This shall take care of the problem.

, , , , , , , , ,

Leave a comment

View the raw sql created by Doctrine

For debugging you might want to see the final native query constructed by doctrine

$raw_sql = $query->getSQL();

the raw_sql variable would contain the sql constructed from entity objecs.

, , , , , , ,

Leave a comment

JSF App slow with JPA connection

If you are working on Java Persistence API JPA on tomcat or any other web server this would be happening if you have multiple threads going off for connections.

The rule of thumb shall be to have one EntityManagerFactory and get EntityManagers out of it. Hence we would have one factory but multiple products that would take care of closing and managing them selves.

What are the signs:

1. Do you instantiate Persistence.createEntityManagerFactory(“name”) from multiple places?
2. What do you see on Process when you run

ps -aux | grep tomcat

Do you see multiple instances

If either or both of the above have yes, then here is the solution.

The first thing have single instance of ManagerFactory


package com.enderase.persistence;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
* Singlton implementation for EntityManagerFactory
*
* @author Kaleb Woldearegay<kaleb@gullele.com>
*/
public class HibernateUtil {
private static final EntityManagerFactory entityManagerFactory;

static {
try {
entityManagerFactory = Persistence.createEntityManagerFactory("jpa");
} catch (Throwable exception) {
//log your error here
throw new ExceptionInInitializerError(exception);
}
}

public static EntityManagerFactory getEntityManager() {
return entityManagerFactory;
}
}

Then make sure you are taking care of the instances of the EntityManagers that are created from the factory using

EntityManagerFactory entityManagerFactory = HibernateUtil.getEntityManager();
EntityManager em = entityManagerFactory.createEntityManager();

Make sure to close them appropriately after using them

This should pretty much take care of the problem

 

, , , , , ,

Leave a comment

Follow

Get every new post delivered to your Inbox.