mysql - Zend Framework: Select query -
i'm newbie on zend framework, created dbtable , primary key id , , table name user:
<?php class application_model_dbtable_user extends zend_db_table_abstract { protected $_name = 'user'; protected $_primary = 'id'; }
after ,i reviewed abstract.php(db/table/abstract.php) , found out had use insert(array $data), created model: (register.php)
<?php class application_model_register { public function createuser($array) { $dbtableuser = new application_model_dbtable_user(); $dbtableuser -> insert($array); } }
and , in controllers , created indexcontroller.php
<?php class indexcontroller extends zend_controller_action { public function init() { /* initialize action controller here */ } public function indexaction() { $register = new application_model_register(); $register-> createuser(array( 'username'=>'test')); } }
it works correctly , have no idea select, how select query user table?
our controller should have below
<?php class indexcontroller extends zend_controller_action { public function getdataaction() { $register = new application_model_dbtable_register(); $register->getlistofuser(); } }
now model should have this,
<?php class application_model_dbtable_register extends zend_db_table_abstract { protected $_name = 'user'; protected $_primary = 'id'; public function getlistofuser() { $db = zend_db_table_abstract::getdefaultadapter(); $select = $db->select() ->from($_name,array('*')) ->where(1); $data = $db->query($select)->fetchall(); return $data; } }
Comments
Post a Comment