Advertisement
dragonbe

simple db access

Aug 22nd, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2. // file: application/models/DbTable/User.php
  3. class Application_Model_DbTable_User extends Zend_Db_Table_Abstract
  4. {
  5.     protected $_name = 'user';
  6.     protected $_primary = 'id';
  7. }
  8.  
  9. <?php
  10. //file: application/controllers/UserController.php
  11.  
  12. class UserController extends Zend_Controller_Action
  13. {
  14.  
  15.     public function init()
  16.     {
  17.         /* Initialize action controller here */
  18.     }
  19.  
  20.     public function indexAction()
  21.     {
  22.         $user = new Application_Model_DbTable_User();
  23.         $this->view->users = $user->fetchAll();
  24.     }
  25.  
  26.     public function oneAction()
  27.     {
  28.         $id = $this->getRequest()->getParam('id',0);
  29.         $user = new Application_Model_DbTable_User();
  30.         $this->view->user = $user->find($id);
  31.     }
  32. }
  33.  
  34. <?php //file: application/views/scripts/user/index.phtml ?>
  35. <?php if (!empty ($this->users)) : ?>
  36. <ul>
  37. <?php foreach ($this->user as $user): ?>
  38. <li><?php echo $this->escape($user->name); ?></li>
  39. <?php endforeach; ?>
  40. </ul>
  41. <?php else: ?>
  42. <p>No users found</p>
  43. <?php endif; ?>
  44.  
  45. <?php //file: application/views/scripts/user/one.phtml ?>
  46. <?php if (!empty ($this->user)) : ?>
  47. <p>The name you have found: <?php echo $this->escape($user->name); ?></p>
  48. <?php else: ?>
  49. <p>No user found</p>
  50. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement