Skip to content

Commit

Permalink
Adding utility constructor to Model
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisJordan committed Dec 16, 2008
1 parent 6d37dd7 commit cd7f3b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions recess/lib/recess/database/orm/Model.class.php
Expand Up @@ -30,6 +30,21 @@
*/
abstract class Model extends RecessObject implements ISqlConditions {

/**
* Constructor can take either a keyed array or a string/int
* to set the primary key with;
*
* @param mixed $data
*/
public function __construct($data = null) {
if(is_numeric($data) || is_string($data)) {
$primaryKey = Model::primaryKeyName($this);
$this->$primaryKey = $data;
} else if (is_array($data)) {
$this->copy($data);
}
}

/**
* Get the datasource for a class.
*
Expand Down
10 changes: 10 additions & 0 deletions recess/lib/recess/http/Request.class.php
Expand Up @@ -40,6 +40,16 @@ public static function splitResourceString($resourceString) {
return $parts;
}
}

public function data($name) {
if(isset($this->post[$name])) {
return $this->post[$name];
} else if (isset($this->put[$name])) {
return $this->put[$name];
} else if (isset($this->get[$name])) {
return $this->get[$name];
}
}
}

class Meta extends RecessObject {}
Expand Down

0 comments on commit cd7f3b4

Please sign in to comment.