Dropdown Country List with Code Igniter and Zend Framework

Note: This assumes you are using Code Igniter, have loaded the form helper, and have followed this guide to integrating Zend Framework with CodeIgniter.

This was so easy that it was scary!

public function country_list($field_name="country",$selected="US")
{
$this->load->library('zend');
$this->zend->load('Zend/Locale');
$locale = new Zend_Locale('en_US');
$countries = ($locale->getTranslationList('Territory','en',2));
asort($countries,SORT_LOCALE_STRING);

return form_dropdown($field_name,$countries,$selected);
}

This returns a nice list of countries with the 2-letter codes as the option values.

simple things make me happy

[Not even sure if that title makes sense but I just like theway it sounds]

I finally talked to BIL a bit today, exactly 10 months after we had our falling out. It wasn’t under the best of circumstances (we were all at a funeral/luncheon), and I didn’t confront him on the argument we had, but I finally did what I think I’ve really been wanting to do the whole time and that is to know that he and I (our friendship) is okay. And now I do. 🙂

I know that I will talk to him about the argument eventually, but I think this was truly the best way for me to do it since I don’t think I would ever have felt comfortable talking to him about that if I wasn’t talking to him at all.

The BEST Obama impersonator ever!

Don’t have much time to write about the debate right now, but I came across this video. SNL NEEDS to hire this guy; his Obama is dead on!!

Bullshit Quote of the Day

“..Rather than answer his critics, Sen. Obama will try to distract you from noticing that he never answers the serious and legitimate questions he has been asked..”
(Source)

Wow.

reprehensible

This afternoon I came across this video which shows some McCain supporters waiting in line for a rally and yelling nasty things to the Obama supporters across the street:

I think my favorite part was how they kept yelling for the Obama supporters to get a job or go to work….uhm, pot meet kettle?

I am totally disgusted. If the roles were reversed, and a video came out with Obama supporters shouting things like that at McCain supporters you can bet your ass the RNC would have an ad up that showed “the kind of people who support Barack Hussein Obama.”

Shit like this fucking terrifies me. I’m not even kidding. These Republicans regurgitating the exaggerated, toxic, thinly veiled incindiary statements Sarah “I’m-So-Gosh-Darn-Cute-You-Betcha” Palin has been spouting.  They seem to gobble up every word that comes out of their (McCain/Palin’s) mouths without ever taking a few minutes to do any fact checking.

Ugh. I need to go be sick now.

Mail Goggles FTW!

I “stumbled” across this today and had to share. 😀

How many times have you stumbled home after a long night out with friends, only to plop down in front of the computer and start sending e-mails that you would wake up regretting the next day? OK, maybe some of our older readers in the crowd have never moved beyond “drunk dialing,” but many of us are probably more familiar with the embarrassing phenomenon, a technological evolution of the drunk dial. Thanks to a new project out of Google Labs, however, you can at least stop yourself from sending “impaired” e-mails during certain hours.

Called “Mail Goggles,” the Gmail add-on makes sending e-mail from Gmail more difficult during certain times that you can set manually (while sober, that is). How does it do this? If you have Mail Goggles installed—which you can do by going to the “Labs” tab under your Gmail settings and turning them on—it will force you to answer a series of math questions before sending out any new messages….

(Source)

I’ve been known to stumble in after a night out (hey, moms need to have fun sometimes too!) and laugh hysterically at articles on Google News or really really dumb YouTube videos, but I’ve never “drunk-mailed”. I have some friends who have done it to me and the next day they’re always like “I don’t remember sending that. Are you sure it was from me?”

Yeah. I’m sure. 😉

People, seriously — calm down!

Everyone is up in arms about the “stock market plunging!!!” and “crisis on wall street!!” People act like they’re surprised the DJ dipped today, the first business day after the “bailout”. The media doesn’t help with their sensationalist headlines and dramatic stories. The idea should not be to rile people up; it should be to present things matter of factly, like

The stock market dipped today, the first day after the bailout was signed. While not unexpected, it does have the average American worried about the state of the U.S. economy, and by extension, the world economy.  Some shakiness should be expected until the government and banks begin working together to start implementing the bailout plan.

Now I’m not a financial expert, and I won’t claim to understand the intricacies of the economy or the stock market. I understand that people have stocks and they’re scared they’re going to lose everything. However, why not take a step back and look at the big picture here? Panicking and dumping your portfolio is reallllly not going to help the economy recover, is it?

I think we should all take a deep breath and try and retain a broader perspective instead of panicking and acting like sheep or lemmings.

Nifty time-saving form / validation function for CodeIgniter

Note: This needs to be seriously tweaked to work better with more complex model functions.  I am leaving this up but understand that for now it only handles one-variable model functions easily.

I’m lazy when I code. By lazy I mean I detest retyping the same several codes of line multiple times throughout an app. My motto is (usually) if I have to use a/several line(s) more than 3 times it becomes a function so I can use and re-use it.

If you’re like me, when you use the form features in CI you set up the controller part like so:


if($this->validation->run() == FALSE) {
$data["variable"] = "something";
$this->load->view("view_template",$data);
} else {
$process = $this->model_name->model_function($this->validation->variable);
//Success / error message here
}

That (extremely simple) example uses only 7 lines of code. However, if you have an add + edit function in each controller and you have 10 controllers, that’s (7+7)*10 = 140 lines that are really similar. I hear a function calling my name!

With the function I created I took those six lines of code and reduced them to this:
$this->library_name->validation_run("model_name","model_function",$this->validation->variable,"view_template",array("variable"=>"something");

Pretty sweet, no? 🙂

Below is the function. I am assuming you have a basic to intermediate understanding of CI, so I won’t go into a lot of depth explaining it. I placed validation_run in the custom forms library I use. You can use it in your own custom library or create a library out of it. If you put it in your own library, ensure that the method you are using to reference CI functions is reflected in validation_run ($this->obj,$ci,$this->ci, etc). Also ensure that the Validation and Model are loaded prior to calling validation_run.

function validation($model_name,$model_function,$model_function_variable,$layout_template,$data_array=NULL)
{

if($this->ci->validation->run() == FALSE) {
//This allows the view to be called with or without parameters.
if(!is_null($data_array)) {
$this->ci->load->view($layout_template,$data_array);
} else {
$this->ci->load->view($layout_template);
}
} else {
$process = $this->ci->$model_name->$model_function(
$model_function_variable);
//Use your favorite redirection method here
}
}

To use it, you’d simply call

$this->library_name->validation_run("model_name","model_function",$this->validation->variable,"view_template",array("variable"=>"something");

For better readability you could do alternatively do it this way:

$this->library_name->validation_run(
"model_name",
"model_function",
$this->validation->variable,
"view_template",
array("variable"=>"something"
);

Of course, you’d replace library_name with the library name you called it from.

Not everyone will have a use for this function; it’s really only good for simple validation “running” . However, it’s saved me so much time coding that I had to share it 🙂

Enjoy!

I've come to a realization…

I really happen to like cheesy 80’s movies! Ha ha ha – here I sit, a 29 year old geeky mother of two who has just realized her affinity for those made to boo at cheesy movies.

I like some of the more popular 80’s movies too, like

  • Dirty Dancing
  • Ferris Bueller’s Day Off
  • Sixteen Candles
  • The Breakfast Club
  • Revenge of the Nerds
  • Beetlejuice
  • Heathers
  • A Christmas Story
  • Back to the Future

When I say “cheesy” 80’s movies I mean gems such as

  • Beverly Hills Troopers
  • Can’t Buy Me Love
  • Once Bitten
  • Mannequin (this particular one has become a lot harder to watch)
  • Flight of the Navigator
  • Secret to my Success
  • Children of the Corn

You know, the movies that really highlighted 80’s hair or greed, or looked corny, or were just plain bad movies with a totally thin plot.

Making up this list has set me on a quest to eBay/Amazon. Damnit…