Here is the general code pattern to build a form with a choice sub-object and use a custom repository in Symfony.  The data is stored in an “EAV” table (Entity, Attribute, Value) which is a scalable table modeled after Magento that stores different related data.  For instance, a list of all states and their abbreviations.  How about other choices you use throughout your website that you need to build form select lists from?  Use EAV tables.

I like to build different EAV tables that are basically the same except hold different type of values, so “eav_main_vc25” holds values only up to VARCHAR(25).  By separating EAVs into more manageable and like data units, you keep the tables clean and optimized.


//inside your form

$builder->add(‘general_list_of_things’,’choice’,
array(
‘choices’=>$this->em->getRepository(‘MainFormBundle:choiceListTable’)->getChoiceListTableElements($this->em),
‘attr’=>array(‘class’=>’col-xs-6 col-sm-3′),
‘label_attr’=>array(‘class’=>’col-xs-6 col-sm-3′)
));

Then in the custom repository function:


// Example for custom query inside “ChoiceListRepository", a custom function called "getChoiceList()"

This works here in repo, but you need to pass in the Entity Manager through DIC this way:
/*
$dql = “SELECT c.val from \Main\MainBundle\Entity\EavMainVc25 c
WHERE c.attr = ‘choice_list’ AND c.showLive=’1′ ORDER BY c.entityRef ASC”;
$results = $this->em->createQuery($dql)->getArrayResult();
*/

// This is better — no reason to pass the Entity Manager through DIC:

$dql = “SELECT c.val from \Main\MainBundle\Entity\EavMainVc25 c
WHERE c.attr = ‘choice_list’ AND c.showLive=’1′ ORDER BY c.entityRef ASC”;

$results=$this->_em->createQuery($dql)->getArrayResult();
return $results;

This is another pattern that is frequently accessed, so feel free to use this as a template for your own projects inside AND outside of Symfony.

– Aaron Belchamber


In a custom page you call as a template in WordPress, this is the standard way to access some of the information about the particular post or page being viewed.  This is possible by accessing the WordPress query object, which is already instantiated by WordPress in a global class called $wp_query.  There is much more information you can get from this object, by visiting WordPress.org.  Another interesting aspect of accessing the $wp_query object is that you can override many of the properties and methods within this class to alter the functions, data, and output of the containing page so you can tailor the page for further customization.


$query_vars=$wp_query->query_vars;

$pagename=$query_vars['pagename'];
$category_name=$query_vars['category_name'];

$post_arr=$wp_query->post;
$post_author=$post_arr->post_author;

$url= $url_arr['request_uri']=$_SERVER['REQUEST_URI'];

ob_start();
echo “Pagename: $pagename / Cat: $category_name / Url: $url / Author: $post_author”;
var_dump($wp_query);
$html=ob_get_clean();

echo $html;

For custom pages, do not ever close your files with closing PHP tags with scripts. Please note that different WordPress themes like Genesis may have different functions that will either alter how you can access the $wp_query object and in some instances do not allow accessing it.


This is a much more secure way to insert records and prevent MySQL injection.  This assumes that $this-conn is your MySQLi PDO database connection object that you’ve already initialized:


Please note that a lot of the PHP snippets on this site assume you have some level of PHP experience.  I use this site as a repository of many frequent code snippets and things I find I look up a lot as a central way to reference materials.  Feel free to use and share as you see fit!

- Aaron Belchamber


For those who have installed Ubuntu on VMWare, you have to DISABLE the “CD/DVD” drive from your options or it will boot to the install menu each time.

If you encounter the Ubuntu install menu after you install Ubuntu, you can bypass it by hitting the “Esc” key then move the arrows down and select “Boot from first hard disk” above.

Ubuntu-start-screen

 

Just go to your virtual machine and right click “Settings” then go to “System” and uncheck  .  This does not seem to be anywhere in the documentation and may seem obvious, but if you like to start your web server up then come back in a minute and expect it ready to go, you won’t have to wade through the Ubuntu start up menu.

VMware-Ubuntu

Ubuntu is the most popular Linux-based software platform.  It gives a Linux machine real legs.  It’s amazing what the open source community has encouraged in innovations in web technologies.  It will only exponentially increase as costs for computers and web access keep going down.  I can’t help but be grateful, and humbled, by the extraordinary efforts of those who provide these incredibly powerful tools, many at little or no cost.  So, support your open-source programmers and providers — donate and spread the word.  If you use open-source software, rave about it!

After all, it’s hard to complain when you get all this software and it only costs you time to learn it.  The things you can do, the tools and solutions you can provide.  It’s an amazing age we live in!

 

– Aaron Belchamber