diff --git a/frm/Model.php b/frm/Model.php index 2c13ab6..d3b0d40 100644 --- a/frm/Model.php +++ b/frm/Model.php @@ -70,6 +70,31 @@ class Model { } return $model; } + $model = null; + return false; + } + + static public function find( $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); + $model = null; + $stmt->execute(); + $data = $stmt->fetchAll(\PDO::FETCH_ASSOC); + if (! empty($data) ) { + $out = []; + foreach ( $data as $data_single ) { + $model = new $child_model_name; + foreach ($data_single as $key => $value ) { + $column_name = 'table_' . $key; + $model->$column_name = $value; + } + $out[]=$model; + $model = null; + } + return $out; + } return false; } } \ No newline at end of file