Symfony sfException Call to undefined method BaseModel::__toString

Working on some projects in Symfony recently. I ran into a problem when I used the symfony admin generator to create a “backend” module for a table that has a foreign key relationship.

Symfony was looking for me to have a __toString() function in my model so it could create the drop down menu. So for instance, let’s say you have tables like countries and states in your schema.xml. Country_id in the states table is a foreign key to the Countries table like so:

Then you can do:

Symfony is going to create the edit and create actions of the States screens with a drop-down menu of countries that the state is a part of. The value of the country drop down is the country_id. the value needs to be set in a __toString() function in your Country propel model. The easiest thing is to just return a simple string name (if that’s in your db model):

That should solve the problem. It’s odd that this comes up. And I couldn’t find anything on it when googling.

Continue reading

Drupal 6 and new Apress Drupal book

I have been working on a couple of projects using Drupal lately that required creating some custom modules. So again, I flipped thru my well-worn copy of Pro Drupal Development. Here is my earlier review of Pro Drupal Development.

Drupal has released version 6 now. So I click to the Apress site and lo and behold, they’re already working on Pro Drupal Development, 2nd edition which will feature updates for Drupal 6. If it is as good as the first book, it will be a must have for any Drupal developer.

Continue reading

Using Subversion externals property for WordPress upgrades

I find that upgrading apps like WordPress, Drupal, Symfony and open source PHP apps is simple for less complicated environments, but once you start adding in things like new directories, custom themes/modules, source code control as well as separate development, test, and production systems, the upgrades start to get pretty hairy.

Take WordPress for example. A typical upgrade of WordPress involves copying the new WordPress files over your existing files. Then you have to copy back safe versions of things like wp-config.php, .htaccess (if you’re using it), as well as any custom themes/modules from the wp-content/ directory. Not to mention any of your own directories that should exist alongside your wp-includes/ and wp-content/ directories. After that you can run the upgrade.php file.

These upgrade steps aren’t terrible. They’re quite a bit better then most open source apps out there but they still suffer from a few problems:

  1. If you have your code, including your WordPress install, in Subversion or another source code control system, you have to commit all the files that change with each WordPress version. There may be files added, deleted, etc. You’ll have to keep combing thru “svn status” messages to figure out everything you need to do to get all the WordPress files into your repository. This can be painful. And take a long time.
  2. WordPress is specifically written so that you don’t ever have to muck with the guts of it. You create themes and plugins for added functionality. So, since you’re not maintaining the code that powers WordPress, do you really need all those deltas in your Subversion repository? I think not.
  3. What do you do with your own code in directories that sits alongside wp-includes/? What if it’s in a Subversion repo?

The WordPress site also has instructions for using Subversion with your site. Here, they advocate the use of “svn switch” to update your site. This is much more manageable and solves a few of the above problems. Most svn users can probably can get away with this method. But unfortunately not me.

I have additional directories on some of my sites that I need to add into my WordPress install. So I have to copy/move them into the WordPress dirs which gets tough. And then my “svn status” will get all wonky because my WordPress dir is under one repo and my code is under another. This was endlessly confusing for me.

So I found myself looking for a way to completely wall off my WordPress install from the rest of my files. I was reminded recently of the use of the Subversion externals property and my mind started buzzing with possibilities. With “externals,” I can say:

Pull the stable WordPress code from WordPress.org and put it into this directory named /docs/wp/

Then my other directories, which are under my own local subversion repo can exist at /docs/dir1, /docs/dir2, etc. Of course, some Apache Alias magic is needed to make all this work.

Here’s the way I set it up for my some of my projects. So far so good. This is a bit hairy to set up but subsequent upgrades are a breeze. I use this across development, testing, and production systems (how to get those environments to work with WordPress will be another entry)

First off, the previous Apache document root for domain1 was at /www/domain1/docs, so the WordPress files wound up like this:

/www/domain1/docs/wp-content/
/www/domain1/docs/wp-includes/

But I also have a lot of dirs that sit alongside of wordpress like this:

/www/domain1/docs/dir1

/www/domain1/docs/dir2

We’re going to wind up changing that.

Create an subversion external property in /www/domain1/docs for WordPress

vi starts up and you can add the following line:

Save and exit

This downloads the WordPress code from the above address into your wp/ directory. Now we are cooking.

  • Now, /www/domain1/docs/wp is where all your WordPress code lives.
  • Copy wp-config.php to /www/domain1/docs/wp/
  • Copy .htaccess to /www/domain1/docs/wp/
  • Create a link from the stock wp-content/ dir to your personal wp-content dir like this

  • In Apache config, set document root for this domain to /www/domain1/docs/wp
  • Put wp-content/ dir and any other non-WordPress dirs/files into /www/domain1/docs
  • Create an alias for wp-content/ and any other non-WordPress dirs/files in Apache config

This looks like a lot of work, but it’s really only a lot the first time around. Next time WordPress has an upgrade:

Everything after the propedit in this group can and should be scripted which will basically give you a 2 step process for upgrading WordPress, while keeping you wp-content/ dir under local source code control, as well as leaving room for any other directories or files your site might require.

This technique will probably also work with Symfony although I haven’t tried it yet.

Continue reading

People work with WS-* web services in PHP? Why?

I’d love to give ws02 a fair shake because they have an open source business model. They have a web services framework for PHP which seems interesting from an academic standpoint. But I think WS-* web services are WAY too complicated when compared to REST.

Just look at this new product description from ws02:

The WSO2 IS enables LAMP and Java websites to provide strong authentication based on the new interoperable Microsoft CardSpace technology, which is built on the open standards Security Assertion Mark-up Language (SAML) and WS-Trust.

Your life is now 1 minute shorter after trying to read and fully understand that paragraph. Nevermind how much time would be spent trying to actually get this stuff to work.

I spent a lot of time in 2001-2002 working with Amazon’s merchant program and the SOAP feeds required for putting client product on the Amazon site. I generally think that Amazon has a pretty good clue about how to do things technically and they seemed to make it as easy as possible while using SOAP. But it was still way too complicated for what we were trying to achieve (ie, send a list of available product to Amazon to sell ). And at the time, it was a nightmare in PHP. Now of course, we have the official PHP SOAP extension and some items in PEAR to work with too (does nusoap still exist?)

But I’ve run screaming from WS-anything since then, only getting caught in its claws a few times. It hasn’t gotten any easier. It’s gotten more difficult. And more pointless. I’m not alone in this thinking.

So I guess the ws02 folks are trying to solve the issue of authentication for web services. Hasn’t web services authentication been solved already in a much easier way too?

Continue reading

Open source twitter clone anyone?

Does anyone know of an open source twitter clone?  Preferably in PHP or Python.  Not a client mind you, but the server guts of receiving IMs and doing something with them, enabling followers, public viewing, etc.  I want to implement this on an intranet inside a corp network and obviously not display our tweets for public consumption, but only internal consumption.  If this doesn’t exist, what do you all think is the easiest way to create this?  An instance of jabber or something else?

Continue reading

Zend Studio for Eclipse Beta

As my part time job (for no pay) is spent being a shill for Zend, I thought I’d mention that the new Zend Studio for Eclipse Beta is out and ready to be test driven. I’ve got a few deadlines both professional and personal to take care of over the next few days but I’m hoping to kick the tires next week. Let me know of your experiences so far.

UPDATE – since the beta period is over, the new url is now http://www.zend.com/en/products/studio/downloads 

Continue reading

SECURITY ERROR: package in channel “pear.phpunit.de” retrieved another channel’s name for download!

Odd Pear error today. Trying to install PHPUnit3 on a newish server. Following the instructions at the PHPUnit Pocketguide. Here’s the steps I did and the error I received. I’m not sure at this point if this is a bug in the Pear installer or if there’s a problem with the way the PHPUnit channel is configured so I don’t know where to file this.

Installing the code manually (the second set of install instructions listed) works just fine however. On to my unit testing!

Continue reading

PRADO framework for PHP similar to ASP.NET

For Drew, the .NET fanboy who is just dying to release his app without having to shell out the big bucks for .NET hosting.  The PRADO framework for PHP is almost like ASP.NET.   From the homepage:

PRADO is a component-based and event-driven framework.

Look at that example on the homepage.  That’s .NET with a PHP5 wrapper on it, not literally of course, but you get the point.  And yes, it has user authentication built in as recently described in this PHP framework comparison chart.  Enjoy.  And I’ll take the first 1,000 shares at a discount when you go public.

Continue reading

Zend Framework, Google APIs, Google Reader issue

I’ve been playing around with the Zend Framework and the Google API. I’m pretty bummed out that there doesn’t seem to be any API for Google Reader. I was hoping to use Zend_GData_Query to suck in my starred and/or shared feeds. You can do this using getFeed() but I wanted to include the tags I’ve put on the entries. But I don’t see my tags anywhere in the data, only the original “category terms” if specified by the feed author.

I even tried to do a login authorization with Google using Zend_Gdata_ClientLogin, but the public and private Google Reader URIs threw a hissy fit on me.

Continue reading

Alpha WordPress Plugin for Delicious with Zend Framework’s Zend_Service_Delicious

I have WordPress set up on PHP5. While WordPress is largely a PHP4 entity, I wanted to see if it could play nicely with the Zend Framework, which is a PHP5-only entity. With some careful fiddling, it works pretty well.

With my Zend Framework code set up in my PHP include path, the first thing I needed to do to create a WordPress Plugin was to enable my plugin to call the Zend Framework classes. First I tried this towards the end of my wp-config.php file:

This caused WordPress to freak out like a chihuahua on speed. Not good. I figured we’d have to do something special because we don’t want ALL the classes to autoload, just the Zend ones. So I scrapped my previous __autoload and tried this instead:

Ahh, success. Sweeter then a brownie sundae with extra chocolate sauce.

From there, the rest is easy. Here’s some basic code for the rz_delicious plugin, a basic PHP file you can drop into your WordPress Plugins dir. It uses Zend_Cache and Zend_Service_Delicious to put your del.icio.us bookmarks onto your WordPress blog. It first checks to see if there’s a cached version already, if not, it uses the del.icio.us API to fetch your latest bookmarks. It does some list formatting there too because I didn’t feel like handling that in my theme.

 

Continue reading