Adding a table prefix to your Doctrine Entities in a Bundle

How to add table prefix to your database tables for all Doctrine entities in a Symfony2 bundle. Most of the information found on this article worked fine: Symfony2 Doctrine Table Prefix

Modifications for using XML format for services.xml.

    <parameters>
        <parameter key="acmebundle.db.table_prefix">prefix_</parameter>
    </parameters>
 
    <services>
        <service id="acmebundle.tblprefix_subscriber" class="AcmeBundle\Subscriber\TablePrefixSubscriber">
            <argument>%acmebundle.db.table_prefix%</argument>
            <tag name="doctrine.event_subscriber" />
        </service>
    </services>

Doctrine field type references for Symfony2

Taken from the Symfony2 cookbook for my quick reference. These are the possible data types for Symfony2 doctrine entity classes. I usually use the PHP annotation method of defining the data types.

Strings

  • string (used for shorter strings)
  • text (used for larger strings)

Numbers

  • integer
  • smallint
  • bigint
  • decimal
  • float

Dates and Times

(use a DateTime object for these fields in PHP)

  • date
  • time
  • datetime

Other Types

  • boolean
  • object (serialized and stored in a CLOB field)
  • array (serialized and stored in a CLOB field)

for further information see doctrine mapping types reference

Configure apache to forward to JBoss server using the proxy module

After trying unsuccessfully to compile mod_jk to run on OSX, I came across an alternative and much neater solution to get Apache to forward requests to JBoss.

Make sure proxy_module is enabled in your apache config, and add the following to your VirtualHost.

<Proxy *>
        Order deny,allow
        Deny from all
        Allow from all
</Proxy>
 
ProxyPass       /appcontext ajp://localhost:8009/appcontext 
ProxyPassReverse    /appcontext ajp://localhost:8009/appcontext

Replace appcontext with your actual application context. Retsart apache and everything should be working as expected.

Get Twitter Boostrap compiling on OSX with jshint error

I cloned bootsrap with Git, but ran into a problem when trying to run make to compile.

##################################################
Building Bootstrap...
##################################################
 
/bin/sh: jshint: command not found

To fix, use npm to install jshint.

sudo npm install -g jshint

Then edit the boostrap MakeFile to use it.

#
# BUILD DOCS
#
 
jshint   = $(shell npm bin)/jshint
 
build:
	@echo "\n${HR}"
	@echo "Building Bootstrap..."
	@echo "${HR}\n"
	@${jshint} js/*.js --config js/.jshintrc
	@${jshint} js/tests/unit/*.js --config js/.jshintrc
        ....

Finally, install the dependant locally with npm

sudo npm install -g

sources:
pull request
MakeFile edit

OSX version: 10.8.2

Symfony2 bundle CSS and JS resources with asset in template

Create your scripts in the Acme/DemoResources/public/js and AcmeBundle/Resources/public/css etc..

Publish the assets to your web directory using a symlink. Otherwise any changes must be published every time.

php app/console assets:install web --symlink

Include an asset from a template.

<link href="{{ asset('/bundles/acmedemo/css/main.css') }}" type="text/css" rel="stylesheet" />

Compile LessCSS with nodeJS during ANT build

This is how I got lessCSS to compile during an ANT build. This uses nodeJS for both windows and OSX. You need to ensure you have installed nodeJS and the less module. (See server-side usage)

Add platform detection code to your build file.

<condition property="os.osx">
	<os family="mac" />
</condition>
<condition property="os.windows">
	<os family="windows" />
</condition>

Next, define a target that will call both the windows and OSX compile targets. The idea is to use a conditional on the targets so the correct one executes depending on the platform you are using. The parameters are the directory path of the .less files, input is the name of the .less file to compile, and the output .css file.

<target name="compile-lesscss">
	<antcall target="compile-lesscss-windows" >
		<param name="directory" value="${directory}"/>
		<param name="input" value="${input}" />
		<param name="output" value="${output}" />
	</antcall>
	<antcall target="compile-lesscss-osx" >
		<param name="directory" value="${directory}"/>
		<param name="input" value="${input}" />
		<param name="output" value="${output}" />
	</antcall>
</target>

A target that compiles on the windows platform. The first argument is the path to the lessc node module. Note I have setup an environment variable that holds the path to my windows user directory.

<target name="compile-lesscss-windows" if="os.windows">
	<echo message="Compiling LessCSS to CSS (windows platform WITH NodeJS) - ${input} to ${output} " />
	<exec executable="cmd.exe" dir="${directory}">
		<arg value="${env.USER_HOME_DIRECTORY}/AppData/Roaming/npm/lessc"/>
		<arg value="${input}"/>
		<arg value="../css/${output}"/>
	</exec>
</target>

This target compiles on OSX. The pathToNode property is the directory where node is installed on your system.

<target name="compile-lesscss-osx" if="os.osx">
	<echo message="Compiling LessCSS to CSS (MacOSX platform) - ${input} to ${output} " />
	<property name="pathToNode" value="/usr/local/bin" />
	<exec executable="/usr/local/bin/lessc" dir="${directory}">
		<env key="PATH" value="${env.PATH}:${pathToNode}" />
		<arg value="${input}"/>
		<arg value="../css/${output}"/>
	</exec>
</target>

Setting the Eclipse environment variables on OSX

Find the eclipse icon in Finder, and ‘Show package contents’.

In /Applications/eclipse/Eclipse.app/Contents/MacOS

Open the eclipse.sh in a text editor an enter the following contents:

#!/bin/sh
 
// environment variables
export NAME=value
 
exec "`dirname \"$0\"`/eclipse" $@

chmod +x /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.sh

Open the Eclipse.app Info.plist and change the value for the key CFBundleExecutable from eclipse to eclipse.sh.

Refresh the launch service database:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app

Eclipse will now set the specified environment variables on launch.