Categories
How-To php WebApps

Installing sfGuardPlugin in symfony 1.1 — A Guide for the Perplexed

Like the verbally creative barfly, who is a dead ringer for a 21+ Juno, that you picked up during last call on a Friday night, symfony 1.1 starts to grow on you. Nevermind your friends, who found Erlang in some higher-scale, hipster, hippy hang out. They tell you it’s time to leave symfony 1.1. You’re perversely drawn to this framework and don’t mind racking up the future therapy bills.

God is dead, and so everything is permitted, unless you can install something like symfony 1.1’s sfGuardPlugin to add logins and login protection to web pages. Like the initiation rites into the Eleusinian mysteries or the Freemasons, not everything is articulated on how to do the install. But below, for the first time, it is.

Note: I use psymfony as an alias which really just means ‘php symfony’.

  • psymfony generate:app backend

Now you can start following the guide written on the symfony website. Below is just from my shell’s history log:

  • psymfony plugin:install sfGuardPlugin
  • psymfony propel:build-model
  • psymfony propel:build-sql
  • psymfony propel:insert-sql — this didn’t work for me so I ended up just doing: mysql -uusername -p < data/sql/plugins.sfGuardPlugin.lib.model.schema.sql
  • follow the instructions in the guide above for fixtures
  • psymfony propel:data-load frontend
  • psymfony propel:data-load backend
  • vim apps/frontend/config/settings.yml
  • vim apps/backend/config/settings.yml
  • psymfony cc

But you’re not done yet. Are you running into a propel connection error? Then you might have to edit some yaml files based on this blog post.

In my case, I ended up having to edit config/databases.yaml by adding the following below:

   propel:
     class:          sfPropelDatabase
     param:
       phptype: mysql
       host: localhost
       database: dev_starster
       username: writes
       password: some_wicked_sick_password
       dsn:          mysql://writes@localhost/dev_starster
       datasource: propel

Are we out of the woods yet?

Unfortunately, symfony 1.1 has a signout bug, where sessions are not entirely cleared. Thanks to this blog post, I was able to hack something together.

In apps/yourapp/modules/sfGuardAuth/actions/actions.class.php write:

public function executeSignout()
{
if (sfConfig::get('sf_environment') != 'test')
{
session_destroy();
session_write_close();
session_regenerate_id();
}
parent::executeSignout();
}

You might have to link the sf_guard_user table to an account table, if you want the account table to do the authorization instead. If so edit apps/modulename/config/app.yml by adding something that looks like this:

  sf_guard_plugin:
    algorithm_callable: md5
    success_signin_url: @homepage
    profile_class: sfGuardUserProfile
    profile_field_name: account_id
    check_password_callable: [Account, checkPassword]

In the lib/model/Account.php you should add code that looks like this:

  public static function checkPassword($username, $password) {
  	$c = new Criteria();
  	$c->add(AccountPeer::EMAIL, $username);
  	$c->add(AccountPeer::PASSWORD, md5($password));
  	$rac = AccountPeer::doSelect($c);
  	//print_r($rac) ; die();
  	if ($rac == TRUE) {
  		return TRUE;
  	} else {
  		return FALSE;
  	}
  }

Here is a list of links that made getting the plugin working possible:

Categories
php WebApps

sfValidatorCompare Is Now sfValidatorSchemaCompare

I’ve been running into other folks that have been having trouble with symfony 1.1 on Twitter. One common stumbling block is sfValidatorSchemaCompare.

I’m just gonna paste code here, because I’m now a week behind schedule working with symfony 1.1 because I didn’t pad time for having to read a good chunk of the source of symfony 1.1:

<?php

    $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
	  new sfValidatorSchemaCompare('email', '==', 'email_confirm',
		    array(),
		    array('invalid' => 'The email adresses must match')
		  ),
	  new sfValidatorSchemaCompare('password', '==', 'password_confirm',
		    array(),
		    array('invalid' => 'The passwords must match')
		  ),
	    )));

?>

Anyway it’s been cool getting props for posting code like the above. 😀

Good luck!

Categories
php TechBiz WebApps

Does Core Developer Think Symfony 1.1 Alienates PHP Developers?

Have you ever coded in a framework and then woke up one day to find that all your code broke when you upgraded? That’s exactly what happened when symfony 1.1 was released without backwards compatibility. A core symfony developer, François Zaninotto, shares his thoughts about the non-launch of symfony 1.1.

A couple key phrases, that he uses to describe the symfony core developers attitude to us mortals, are pretty disturbing:

  • If you just used symfony for one project, and left if afterwards because it lacked some feature that you needed, then you don’t deserve to be informed that this new release does have this feature.
  • Symfony 1.1 is so good, that it should not be left in everybody’s hands. Think of it as a forbidden manuscript of the middle ages, that only a few copyists ever read and got a fair picture of.
  • …there is no “First Project tutorial” at all for symfony 1.1.

Caveat: Do not use symfony 1.1 unless you want to pour through source code.

Problem: You’re working on symfony 1.1 and it doesn’t work as advertised.

Solution: You have to pad your estimates on symfony based projects by at least a hundredfold. A form that should have taken me no more than an hour at Dogster ended up taking 4 days! Read this blog for important symfony 1.1 updates.

So does François think that PHP developers are being alienated? It’s strongly suggested through his use of irony, and analogy of symfony to a medieval text, but does he say abandon symfony?

Not at all. Rather his frustration noted in a follow up blog post has to do with the fact that he cares a great deal about symfony. If you were thinking about leaving symfony, François is enough reason to stay.

Categories
How-To php WebApps

Symfony 1.1 Validation — Gotchas

1. sfValidatorAnd requires a patch to work with Propel.

Get the patch here.

Read the trac ticket for more details.

2. A huge difference between 1.0 and 1.1 in form validation deals with error handling.

1.0 puts the error handling right in the action. In 1.1 you use code in a lib/forms file that looks like this for validation / error handling and corresponds usually to the object being validated. In the example below the code is in lib/forms/AccountForm.class.php

$this->setValidators(array(
    'username' => new sfValidatorString(array('max_length' => 30))
));

3. sfForm::setDefaults doesn’t work quite right with CSRF values.
you’ll need to patch up code based on this google groups post.

The documentation right now for 1.1 isn’t updated. E.G. The chapter on forms for the 1.1 documentation as of 12 August 2008 will lead you down the wrong path.

To keep up to date on what’s going on with symfony, I totally consider doing the following mandatory and not optional:

  • Join the google group, symfony-users
  • Join the irc channel in irc.freenode.net #symfony any time you’ve got a question that needs asking
  • Since the docs might be off, it’s best to just read the source.
Categories
TechBiz

Matt Knox Rocks The San Francisco Ruby Meetup

Ya, I’ve read Zed’s rant against Rails. I’ve felt the anger and alienation he’s felt, but in the San Francisco PHP Meetup community. After a core team PHP member used a racial epithet to describe something I wanted to do in PHP, the idea of coding web apps using Ruby on Rails began to have more and more appeal.

I went to the San Francisco Ruby Meetup today at Marakana, and although I was late, I quickly got Rails running and caught up. By the end of 4 hours of lecture and coding I had a working blog on my laptop, and learned a lot about coding in a totally fun way from Matt Knox. He teaches Ruby on Rails at Sermo in Boston.

Here are a few notes:

  1. To evaluate a technology Matt asks, “How fast can I set up a ‘Hello World!’ app?” and “How fast can I iterate through the development process?”
  2. Validation should happen in the model. The moment you put it in the controller bad things happen.
  3. To be an Internet Rockstar, you should do WRDD (pronounced word), which is Web Request Driven Development. Put the site up with zero features but a page that gives the users an idea of what the site will be. Code functionality as users ask for it.
  4. “Databases are a giant persistent hash in the sky.” (Matt Knox) What this means is that DBAs are constrained by tradition when it comes to scalable web apps. A database should be used as one big hashtable if it is to be scalable.
  5. Do not work for equity.
  6. Subversion cannot git-stash or git-unstash so use git

I was so happy just getting a blog working so quickly that I registered HipsterHookups today and want to see if I can get a site working by this weekend.

Categories
TechBiz

Coder Dudes, For Your Sanity Date Starbucks Barristas!

Since I’ve moved back from Italy, career has gone from unemployed, stacking candles at Planet Weavers in the Castro never believing there would be another tech boom, re-starting a Web 1.0 company, hacking password protected files from the hard drives of former Enron Employees for an Enron trial, and now having once again a successful tech career.

Since moving back from Italy 6 years ago I haven’t had a girlfriend. This sort of thing makes me shrug. This blog post is my meditation on being single. I asked around. I’m not the only guy in Silicon Valley who has been single for this long, and it’s not that I haven’t been dating or not putting myself out there.

As a coder, I make more than the median salary in San Francisco. There are men who are poorer than me and less intelligent than me that have girlfriends. There are some coders who make twice that which along with exercised stock options make them millionaires. Attraction (at least the kind worth having) should have nothing to do with money.

The kind of woman that has so graciously, kindly and flirtingly said yes to a date with me works in tech, knows a lot of the people that I work with, and is absolutely cute. I think what initially draws such a woman to me is how I handle myself in a lot of situations: calm, cool, collected. She also likes the fact that I have a reputation for discretion.

Yet, I have had a lot of frustrations in dating women in the tech industry. Something is not working out. I would really like to date someone with a lot of similar work interests because I am passionate about my work. But for one reason or another it just doesn’t work out. This has forced me outside of the box. My ideal date now is with a Starbucks Barrista with a degree in either philosophy or literature – definitely something humanities oriented.

Starbucks Barrista
WTF? Why?

  1. Unlike other women higher in the social strata your ambitions are not enough for a woman in the industry. Most women in tech see you as a lottery ticket and expect you to daytrade your way up to 7 figures and beyond. Your Starbucks barrista would be more than happy with your 5 figures and ecstatic about 6.
  2. Your Starbucks barrista with her liberal education gives her – duh? – liberal sensibilities. A lot of women in tech that are recruiters, marketers and designers read Cosmo and its ilk. These are magazines dedicated to the manipulation of straight men by women. This is not to say men aren’t guilty of this, too. They are, and the book, “The Game,” is the choicest example of this. My point is that I haven’t run into folks with degrees in liberal arts that are great manipulators like say the Enron folks or GW & company.
  3. You probably won’t have a chance with a cutie coder. Cutie coders get hit on all the time and are totally smarter than you and smarter than you think. Unless you’ve got the skills of Cal Henderson, forget it. Cutie coders are the buyer; you’re just the seller.
  4. Still not giving up? If you go to any tech party, the guys who really have a shot are the CEOs. It’s as if women divide men into 1st class and 2nd class citizens. Guess which class citizen a CEO is.
  5. The hard earned money of your Starbucks barrista is “worth more” because when she buys you a present it means more to her, it’s a bigger deal.
  6. A Starbucks barrista is trying to figure out her way out of her job. She has her own ambitions, and these are probably more modest than your cutie techie’s ambitions. You might even be able to bankroll one of her projects.
  7. Most Web 2.0 kids met on-line. You can tell your grandkids, how you manned-up and asked her out using this technology called face-to-face IRL. You certainly won’t be penciling yourself in her pbwiki page.
  8. She’ll be grateful that you fixed her computer.
  9. The techie cutie has some idea of your lived experience, including the occasional drudgerie of it. For the Starbucks barrista everything you do is awesome and new.
  10. She’ll round you out. Her liberal education gives her a mind that sees there’s more to life than just money, materialism and its shallow pleasures, that there’s a higher world of ideas and delights.
  11. If things do end, she will leave you better than she found you.
  12. After the break up, you won’t have to read about who she’s hooking up with now in Vallywag.
Categories
Social Media

NBCi4 loves Twitter

I think it’s really cool that NBCi4 got their news anchors onto twitter, especially given this graph detailing the Los Angeles earthquake yesterday:

Graph of twitter vs. ap

Maybe since these news anchors are on twitter, you can get your Mom on Twitter… or not.

Categories
Uncategorized

Hopes to Catch Up on His RSS Reading

I’ve got some reading to do. 2000+ more posts to go, and I’m done.

picture of rss feeds

Categories
How-To Uncategorized

Fun With GDB, Gnu’s Debugger

Here’s a pretty compact version of strcmp:

int bstrcmp(char *s1,char *s2) {
   while(*s1 == *s2++) {
      if(*s1++ == 0){ return 0; }
   }
   return (*(unsigned char *)s1 - *(unsigned char*)--s2);
}

The source that I used for compiling and calling this version of strcmp is here.

Compile that code using:
gcc -o strcmp -g strcmp.c

Fire up the debugger using:
gdb strcmp

You’ll get the gdb prompt:
(gdb)

Set a break point at the start:
b main

The debugger will echo something like:
Breakpoint 1 at 0x80483d5: file strcmp.c, line 6.
(gdb)

Then run the program:
run

The debugger will print out something like:
Starting program: /home/somedude/bin/strcmp

Breakpoint 1, main () at strcmp.c:6
6 {
(gdb)

If you type n a few times, you’ll eventually get to some variable assignments.

(gdb) n
8	char s1[] = "better";
(gdb) n
9	char s2[] = "better than"; /* than this";*/
(gdb) n
11	int i_result = 0;
(gdb) n
13	i_result = bstrcmp(s1,s2);

If you want to the values of these variables type:
p i_result

You get back:
(gdb) p i_result
$1 = 0

To step into a function, type s:

(gdb) s
bstrcmp (s1=0xbf86b469 "better", s2=0xbf86b474 "better than") at strcmp.c:26
26		while(*s1 == *s2++) { 
(gdb) n
27			if(*s1++ == 0){ return 0; } 
(gdb) n
26		while(*s1 == *s2++) { 
(gdb) n
27			if(*s1++ == 0){ return 0; } 
(gdb) n
26		while(*s1 == *s2++) { 
(gdb) 

At this point you can type things like:
p s1
p *s1
p s2
p *s2

And you’ll get back the value of the pointers and what’s in memory.

Next time we’ll go over how to do this with PHP running single threaded on debug mode on Apache.

Categories
TechBiz

The No-Tech Invite Birthday Celebration

If you had to plan your birthday celebration and used no technology, who would show up? I embarked on this experiment about a week before my birthday on the 13th. I would only invite people if we were face to face. I wouldn’t use email or snail mail… just simple, literal word of mouth.

I ran into 5 people before my birthday. 1 I didn’t want to invite because last year he had an unreasonable personal emergency (I have to be in the City for my girlfriend at 2pm) that forced me to cancel my birthday celebration in the forest. And ya, no cell coverage. 2 couldn’t make it because it wasn’t convenient for them. 2 made it because they’re my friends that I’ve been hanging out with at least on a weekly basis.

On the day of my birthday, I ran into 2 people I knew but hadn’t seen in ages, and they sang, “Happy Birthday” to me from a car while I was walking down the street.

I had an Evite inspired birthday bash two years ago on the roof top of a building on Carl and Cole. Over 40 people showed up.

Technology based birthday: 40 people
Just using physical word of mouth: 2 people

I don’t want to say one is more real than the other… after all what is reality? Out of the 40 people that were at my technology based birthday, only 1 person showed up to my word of mouth birthday.