How to Use an ExpressionEngine Variable in PHP

If your stuck on how to use expression engine variables dynamically in a php script, you can assign the variable to a php variable using a certain syntax and from there conform it however you like.  First off, make sure the EE template has PHP enabled and then pass it to the php code segment in the following fashion:

...template code...
{if title}
<?php
$phpvar = "{title}";
echo $phpvar;
?>
{/if}
... more template code...

Putting Ext JS toolbar items on the right side

I wanted to add an item to a toolbar in one of my ExtJS panels but was having a little trouble. I could get them on the toolbar fine but I wanted them displayed on the right side of the panel. This was proven tricky, especially as I’m rather new to ExtJS

Then I found the “tbfill” xtype. This made it simpler than it ever could be:

var tb = new Ext.Toolbar({
        items: [{ xtype: 'tbfill' },
            {text: 'Compliment me', handler: function(){ alert('Nice...umm...hair?!'}}
        ]
    });

It’s quick tools like this that have really got me hooked on ExtJS.

How do I drop connections and detach a database in SQL Server

Frequently when moving or modifying databases, they need to be detached.  The problem with this is a database can’t be detached if there are active connections to it.

The following code snippet disconnects active sessions and detaches the database myDbName

USE master;
GO
ALTER DATABASE myDbName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
EXEC SP_DETACH_DB @dbname = 'myDbName', @skipchecks = 'true';
GO

I’m Speaking at IndieConf

Earlier this year I was selected to speak at IndieConf in North Carolina in a talk titled “Building a Business — Growing Beyond Indie Work.”  I’m excited for the opportunity and have put a lot of time into my talk.  An audio speaker spotlight was just released where conference organizer Michael Kimsal and I go into detail about what this talk is about, who the target audience is, and why anyone should attend.

What is this talk about?

I’m going to be speaking on what it means to grow a business and share some relevant experience around the people, marketing, strategy and finance aspects of a service related business.  Topics include stories from my own business as well as stories from associates and friends.  Stories are designed to get attendees over the hump of hiring your first employee, but to do it comfortably and successfully.

Who is the target Audience?

The target audience is anyone who currently has or intends to have a successful indie career.  It will get into the finer details of how things in an audience member’s life will change on a day to day basis as well as bigger picture changes after hiring one or more details.  It will give some tactics on how to keep risk low while building your business, how to position yourself for success and press forward without feeling like you are jumping off a cliff.

Why should anyone attend?

You should attend this talk because it will shed valuable insight into how things will change for better and for worse.  There are many things I wish I’d considered before I hired a full time employee, and this is my opportunity to share lessons learned and h0pefully accelerate others in the process.

Flash Builder: How to Add a Spark Group Background Color

Ideally, things would be a lot simpler if spark groups had a background color property that could be set.  But of course, that is not the case in Flex / Flash Builder.  However, there is a minor work around that one can follow to obtain background colors for spark groups.

<s:Group>
    <s:Rect width="100%" height="100%">
        <s:fill><s:SolidColor color="0x336699" /></s:fill>
    </s:Rect>
    <s:VGroup>
        <s:Label text="group content..." />
        <s:Label text="group content..." />
        <s:Label text="group content..." />
    </s:VGroup>
</s:Group>

Since vgroup doesn’t have a background color property, you can make a rectangle behind it to have desired background properties.  Flex also isn’t very functional with rectangles unless they are in a group of some kind. (i.e. in a scroller tag)  So that is why it’s best to wrap both the rectangle and the vgroup in a regular grouping segment. (same applies to hgroup, tilegroup, and other sparkgroups)

*NOTE: Put the rectangle first.  Otherwise the rectangle will be covering the spark group before it.  In flex, the last element being produced is placed in front of the previous item.

Getting and updating a wordpress post from permalink

We’ve been working on a plugin and we needed to get a wordpress page from a given permalink. This is actually done pretty easily since there is a function wordpress uses deep in their system.

$post_id = url_to_postid($permalink);

This will give you the post_id which you will able to use to retrieve the post object.

$post = get_post($post_id);

Now that we have the object its pretty simple to manipulate it.

$post->post_content = $new_page_content;
wp_update_post( $post );

So all together:

$post_id = url_to_postid($permalink);
$post = get_post($post_id);
$post->post_content = $new_page_content;
wp_update_post( $post );

Updated Freeform Module in Expression Engine 2 No Longer Creates Entries

Having started out with a lovely expression engine buildfound yourself needing to upgrade to the newest version of Freeform. A lot of the time this will update correctly with no errors.

However, in cases like mine, it has been perfectly described as:
“I’m getting no entries entered into my Freeform control panel, no notification email, and the redirect goes to the home page.” (source)

The solution is more than likely having to do with your htaccess file. Reading the above linked forum conversation, it appears that with this version of Freeform, your .htaccess cannot have a  rewrite command to redirect non ‘www’ requests to the ‘www’ version.  There is a work around that I used located here.  Cheers!

The difference between Decimal and Float SQL datatypes

What is the difference between Decimal and Float datatypes in SQL? Well you can accomplish the same with both but there are advantages to each.

First off the syntax is quite different.

Float(char_length)
Decimal(total_length, length_right_of_decimal)

So you can see with decimal you may get more precision as it will never round. If you need some major finance calculations, decimal is the preferred route.

However if extreme precision is not needed and you have varying lengths of decimals, floats certainly make it easier.

Visual Studio 2012 Google It! Feature

Visual Studio is one of the most comprehensive IDE’s on the market and the 2012 version adds a heap of features to be discussed.  The most interesting feature I’ve found was adding a “Google it!” button to visual studio error dialogs.

Clicking the Google It button launches a Google search in your default browser for the string of the error message.  From there, generally trimming down the error message yields better search results, but this frees developers from copying and pasting, washing out the current contents of their clipboard and saves from rekeying error messages which cannot be copied and pasted.

Another interesting note is the button is a “Google It!” button and not a “Bing It!” button.  Perhaps the Visual Studio team realizes that Google has better search than Microsoft; or, Bing hasn’t been around long enough to be used as a verb.

Upgrading ExpressionEngine 1.7 to 2.3.1 Notes

Updating to a new version of Expression Engine gets harder as the amount of version dependant Add-Ons increase. I just successfully updated an expression engine site that had version dependencies.

Tip:  In most cases, when you buy an add-on you will receive both versions. It is important that you keep the original files.  Just because your site is in EE1 now, doesn’t mean you will not need access to the EE2 files in the future…  So make sure the account you use to buy and access your site’s Add-Ons are continually transferred to someone that can access them.  If not, you will need to buy all the Add-Ons again, which can get pricey.


Some EE Add-ons that will not work with the update and my solutions:

1.) Field Frame Module  -  In EE1, this module was used to create custom fields for the data.  The functionality of this module is now part of the core functionality of EE2.
If you also have the Matrix module installed, I had a lot of errors showing up.  These were corrected by implementing the most recent versions of the Matrix Add On.

2.) Ngen field type  -  This was used together with the field frame module.  After updating to EE2, just change the ngen file types to be the EE2 “File” field type that automatically comes with your new EE2 installation.

3.) Find and replace  -  The EE2 version of this plugin is  Low Replace  (template tag usage must update to new plugin)

4.) In Segments  -  The EE2 version of this plugin is  Segment Search  (template tag usage must update to new plugin)

5.) SL Google map  -  The EE2 version of this plugin is  MX Google Maps.  This one is a little more tricky to convert as MX google maps stores the long/lat values in it’s own table.  This is unlike the SL google Map module that stores all data in one table field. The next version released will have more support in conversion steps, but until then you need to write your own script to update the tables.