[thelist] PHP database application framework

Martin Burns martin at easyweb.co.uk
Wed Sep 10 13:41:13 CDT 2008


On 10 Sep 2008, at 17:19, John Corry wrote:

> Tell it what database to use, it looks at the tables and creates PHP
> classes for working with each one, forms/views for the users to
> browse...basically the barebones app that I can then modify to suit  
> the
> specific application.

How important is it that it's PHP? Because other than that, you've  
pretty much described the Python-based Django.

http://www.djangoproject.com/

To create the classes in the model from an existing db (once you've  
identified the db in a settings file)
python manage.py inspectdb > models.py
which will generate something like the following in models.py:

class Blog(models.Model):
     name = models.CharField(max_length=100)
     tagline = models.TextField()

class Author(models.Model):
     name = models.CharField(max_length=50)
     email = models.EmailField()

class Entry(models.Model):
     blog = models.ForeignKey(Blog)
     headline = models.CharField(max_length=255)
     body_text = models.TextField()
     pub_date = models.DateTimeField()
     authors = models.ManyToManyField(Author)


Updating the db is easy: create an object of the appropriate class and  
save it:

 >>> from mysite.blog.models import Blog
 >>> b = Blog(name='Beatles Blog', tagline='All the latest Beatles  
news.')
 >>> b.save()

Or to update eg an instance b5 of Blog:
 >> b5.name = 'New name'
 >> b5.save()

All with the power of Python:
http://xkcd.com/353/

Cheers
Martin

--
 > Spammers: Send me email -> yumyum at easyweb.co.uk to train my filter
 > http://dspam.nuclearelephant.com/








More information about the thelist mailing list