How to overload the constructor with new id

35 views
Skip to first unread message

Peter

unread,
Jan 7, 2012, 11:48:42 PM1/7/12
to Simple PHP Framework
I have a table with an id called 'number' instead of the preferred
name 'id' used by the dbobject class.

How would I overload the constructor to use 'number' as the id column?

Nils Lagerkvist

unread,
Jan 8, 2012, 1:57:04 PM1/8/12
to simple-php...@googlegroups.com
Hi

This is the constructor in class.dbobject.php

Drop this constructor in your class that is extending DBObject, and don't call parent::__construct

The best thing would to move "$this->idColumnName = 'id';" form the constructor to the definition of the object.

In that case one would only need to set $this->columnName before calling parent::__construct in the class extending DBObject.


protected function __construct($table_name, $columns, $id = null)
        {
            $this->className    = get_class($this);
            $this->tableName    = $table_name;

            // A note on hardcoding $this->idColumnName = 'id'...
            // In three years working with this framework, I've used
            // a different id name exactly once - so I've decided to
            // drop the option from the constructor. You can overload
            // the constructor yourself if you have the need.
            $this->idColumnName = 'id';

            foreach($columns as $col)
                $this->columns[$col] = null;

            if(!is_null($id))
                if (!$this->select($id))
                throw new Exception("Unknown ID");
        }

//Nils




--
You received this message because you are subscribed to the Google Groups "Simple PHP Framework" group.
To post to this group, send email to simple-php...@googlegroups.com.
To unsubscribe from this group, send email to simple-php-frame...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simple-php-framework?hl=en.


Reply all
Reply to author
Forward
0 new messages