diff --git a/frm/Model.php b/frm/Model.php index bda3c27..2c13ab6 100644 --- a/frm/Model.php +++ b/frm/Model.php @@ -9,7 +9,6 @@ namespace PFRM; -use PTEST\M\AdModel; class Model { @@ -58,5 +57,19 @@ class Model { } static public function findFirst( $condition ) { + global $app; + $child_model_name = get_called_class(); + $model = new $child_model_name; + $stmt = $app->dbh->prepare( 'SELECT * FROM ' . $model->_table_name . ' WHERE ' . $condition); + $stmt->execute(); + $data = $stmt->fetchAll(\PDO::FETCH_ASSOC); + if (! empty($data) ) { + foreach ($data[0] as $key => $value ) { + $column_name = 'table_' . $key; + $model->$column_name = $value; + } + return $model; + } + return false; } } \ No newline at end of file