PHP Classes

return obj

Recommend this page to a friend!

      Simple PHP Database Manager  >  All threads  >  return obj  >  (Un) Subscribe thread alerts  
Subject:return obj
Summary:can add sth to return objects
Messages:5
Author:alexandru traian
Date:2015-03-20 17:53:23
 

  1. return obj   Reply   Report abuse  
Picture of alexandru traian alexandru traian - 2015-03-20 17:53:23
if add this method

public function get_obj() {
return $this->_execute($this->query_builder(), $this->_data, 'obj');
}

and modify

private function _execute($query = null, $values = array(), $fetch = 'All') {

if ( is_null($query) )
return false;

$result = array();
$sth = $this->prepare($query);

if ( $sth->execute(array_values(array_filter($values, 'strlen'))) ){
if ( $this->_insert || $this->_update || $this->_delete ){
$this->clear();
return TRUE;
}

if ( $fetch == 'All' ){
$result = $sth->fetchAll();
}else if( $fetch == 'assoc' ){
$result = $sth->fetch(PDO::FETCH_ASSOC);
}else if( $fetch == 'obj' ){
$result = $sth->fetchAll(PDO::FETCH_OBJ);
}
}

if ( $result )
array_map(array($this, 'map_count'), $result);

$this->clear();

return $result;
}

I can extract obj from class.

in model i have

public function login_user() {

self::$instance = DB_Manager::get_instance($_POST)->database();
self::$instance->table = 'users';
$pwd = hash(............);
$log = self::$instance->select('*')->where('username', $this->data['user'])->where('password', $pwd)->get_obj();
if(self::$instance->get_result_count() == 1){
return $log;
}
return false;
}

the rest

public function login() {

if (........) {
...........
$row = $this->model('Users', 'login_user');
if(!$row){
...........
}
$this->session->auth_user($row);
URL::to(SITE_ROOT."/users/login_area");
exit;
}

public function auth_user($row){

foreach($row as $row):
$_SESSION['user'] = $row->username;
$_SESSION['user_id'] = $row->id_user;
..............
$_SESSION ['id'] = sha1(..........);
endforeach;
}

  2. Re: return obj   Reply   Report abuse  
Picture of Vagner vinicius bispo cantuares Vagner vinicius bispo cantuares - 2015-10-11 22:53:11 - In reply to message 1 from alexandru traian
I so sorry for the late reply, very thanks for your contribution.

  3. Re: return obj   Reply   Report abuse  
Picture of alexandru traian alexandru traian - 2015-10-12 02:45:35 - In reply to message 3 from Vagner vinicius bispo cantuares
No problem. I liked when I saw your class. I built a small framework and I used in. Nowadays no time to reinvent the wheel and we have to use established frameworks. But you did a good job. Good luck!

  4. Re: return obj   Reply   Report abuse  
Picture of Vagner vinicius bispo cantuares Vagner vinicius bispo cantuares - 2015-10-24 15:47:10 - In reply to message 4 from alexandru traian
I improved the class, check the latest changes.

  5. Re: return obj   Reply   Report abuse  
Picture of alexandru traian alexandru traian - 2015-10-25 02:23:44 - In reply to message 5 from Vagner vinicius bispo cantuares
Okay. I will check this out.