INCLUDE_DATA


Zend Form Element Radio and Default value

Code, Zend Framework

I setup a Zend Form object and needed radio buttons, but also needed a default value. Took me a few minutes to find, but here’s an example of use.

/**
 * Setting some values for our radio buttons.
 */
$options = array(
    '1' => 'Option 1',
    '2' => 'Option 2',
    '3' => 'Option 3'
);

/**
 * The array('value' => 2) below sets our default value.
 */
$radio = new Zend_Form_Element_Radio('elementName', array('value' => '2'));
$radio->addMultiOptions($options);
$this->addElement($radio);
No Comments

Upgrade Zend Framework in Zend Server CE

zend server ce

First off, this isn’t meant as a tutorial, but more of a general way of handling various libraries in this situation.

We’ve recently started to use Zend Server CE on our development machines at work.

With the release of Zend Framework 1.9, we wanted to upgrade but still maintain previous versions.

When I download the framework, I prefer to use svn and grab the tag, in this case: http://framework.zend.com/svn/framework/standard/tags/release-1.9.0/

The structure I chose was:

/usr/local/zend/shared/ZendFrameworkSource/<version>

I then created a symbolic link to the version I want and put that in my include_path.

Example: /usr/local/zend/shared/ZendFrameworkLibrary/ -> /usr/local/zend/shared/ZendFrameworkSource/1.9.0/library/

Now with each upgrade, I only update the symbolic link and each application is switched to the new version.

Have a better way? Let me know, I’m always interested in learning.

-Casey

No Comments

Old code.

Code, php

I love coming across old code *cough* garbage *cough*

The purpose of this was to take a title, and create something url safe and in the fashion a client was wanting. The first function was old code, so don’t blame me.

function cleanUrl($url)
{
  $find =        array('/--/', '/ - /','/ /', '/!/', '/"/', "/'/", '/--/');
  $replace =    array('-', '-', '-', '', '', '', '-');

  $result = strtr($url, "`~@#$%^&*()_=+|[]{};:,./<>?", "---------------------------");

  return strtolower(preg_replace($find, $replace, strip_tags(stripslashes(trim($result)))));
}

Isn’t it horrible?

I rewrote the function to…

function cleanUrl($url)
{
  $url = strtolower($url);

  $url = preg_replace("/[^a-z0-9\s+]/", '', $url);
  $url = preg_replace("/[\s]{1,}/", '-', $url);

  return $url;
}

That makes me happier.

1 Comment

Lazy day

Personal

Today is rainy and full of nastiness. (Thanks Ike!)

I should have gotten out to play disc golf while the weather was beautiful, I just didn’t feel too hot.

Called my sister Meagan a few times, her voicemail is picking up so I’m yelling in a demonic sounding voice and hanging up. Hopefully it freaks them out a bit. If not, well, no loss.

Work is going well, moving forward on some things and looking good.

Snapped a great picture of my brother in law, and his wifes brother being dorks. Put it up on my facebook in the mobile uploads.

This turned into more of a journal entry, rock on.

No Comments

Ewerl Function

Code

Ewerl is a new URL rewritting site with cool features.

Here’s a simple function to return the Ewerl url. It’s only being used for the main url, but could easily be adjusted to return an array. I just didn’t have a need for it in my case at this time.

/**
 * Returns an Ewerl url if available.
 * Otherwise the original that was passed in.
 * Returns false if..
 * 1. JSON extension isn't installed.
 * 2. No url was entered.
 * 3. No response from server.
 *
 * @todo Add URL validation.
 *
 * @param string $url
 * @return string URL, or false.
 * @author Casey Wilson 
 */
function getEwerl($url) {
	/**
	 * Verify JSON extension is loaded.
	 */
	if (!extension_loaded('JSON')) return false;

	/**
	 * Url wasn't passed
	 */
	if (!$url) return false;

	/**
	 * Assign / Prep vars.
	 */
	$postUrl = 'http://ewerl.com/api/v1/make/url=';
	$urlEncoded = base64_encode($url);

	$response = file_get_contents($postUrl . $urlEncoded);

	if (!$response) {
		return $url;
	}

	/**
	 * Should have returned a JSON object.
	 */
	$jsonObj = json_decode($response);

	/**
	 * If either Status not set, or status is false, return original url.
	 */
	if (!isset($jsonObj->status) || $jsonObj->status == 'FALSE') {
		return $url;
	}

	return $jsonObj->url_main;
}
No Comments

jQuery

jQuery

My expierence with jQuery thus far hasn’t been to bad. I’m starting to see the power and simplicity of it.

I’ve never been a JS guy, never been in a position to really need to do much with it since I’ve basically always been a backend coder. I need to really jump in there, get a good feel for both JS and jQuery. So far though, I can say I’m really starting to like it, only been at it a few days thus far so we’ll see here soon what the final say is.

Thanks to good friends, and long late night chats with people smarter than I.

The open source community as a whole rocks.

No Comments

Url to TinyUrl Function

Code

I needed to transform some long urls into tiny ones :p

Figured I’d post something up here that may be useful to someone else.

Code was updated.

/**
 * Get TinyUrl for $url
 *
 * @param string $url Must be a valid url
 */
function getTinyUrl($url) {
	if (! $url) {
		return false;
	}

	if (strlen ( $url ) < 30) {
		return $url;
	}

	$response = file_get_contents ( 'http://tinyurl.com/api-create.php?url=' . $url );

	return ($response) ? $response : $url;
}
No Comments

New blog.

Personal

I was talking to Elazar over at phpc, he said I should really get a blog. So here it goes.

I gave him a link in the blogroll, check out his site. He’s written some very nice articles on Web Scraping.

Night!

No Comments