Source for file database.php

Documentation is available at database.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Model
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Joomla Platform Database Model Class
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Model
  17.  * @since       12.1
  18.  */
  19. abstract class JModelDatabase extends JModelBase
  20. {
  21.     /**
  22.      * The database driver.
  23.      *
  24.      * @var    JDatabaseDriver 
  25.      * @since  12.1
  26.      */
  27.     protected $db;
  28.  
  29.     /**
  30.      * Instantiate the model.
  31.      *
  32.      * @param   JRegistry        $state  The model state.
  33.      * @param   JDatabaseDriver  $db     The database adpater.
  34.      *
  35.      * @since   12.1
  36.      */
  37.     public function __construct(JRegistry $state nullJDatabaseDriver $db null)
  38.     {
  39.         parent::__construct($state);
  40.  
  41.         // Setup the model.
  42.         $this->db = isset($db$db $this->loadDb();
  43.     }
  44.  
  45.     /**
  46.      * Get the database driver.
  47.      *
  48.      * @return  JDatabaseDriver  The database driver.
  49.      *
  50.      * @since   12.1
  51.      */
  52.     public function getDb()
  53.     {
  54.         return $this->db;
  55.     }
  56.  
  57.     /**
  58.      * Set the database driver.
  59.      *
  60.      * @param   JDatabaseDriver  $db  The database driver.
  61.      *
  62.      * @return  void 
  63.      *
  64.      * @since   12.1
  65.      */
  66.     public function setDb(JDatabaseDriver $db)
  67.     {
  68.         $this->db = $db;
  69.     }
  70.  
  71.     /**
  72.      * Load the database driver.
  73.      *
  74.      * @return  JDatabaseDriver  The database driver.
  75.      *
  76.      * @since   12.1
  77.      */
  78.     protected function loadDb()
  79.     {
  80.         return JFactory::getDbo();
  81.     }
  82. }

Documentation generated on Tue, 19 Nov 2013 14:57:46 +0100 by phpDocumentor 1.4.3