Guest User

Untitled

a guest
Oct 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2. // No direct access to this file
  3. defined('_JEXEC') or die('Restricted access');
  4.  
  5. // import Joomla modelform library
  6. jimport('joomla.application.component.modeladmin');
  7.  
  8. /**
  9.  * HelloWorld Model
  10.  */
  11. class HelloWorldModelHelloWorld extends JModelAdmin
  12. {
  13.    
  14.         /**
  15.      * Constructor that creates a connection to the database
  16.      *
  17.      * @return void
  18.      */
  19.         public function __construct(){
  20.         parent::__construct();
  21.        
  22.                 JLoader::register('HelloWorldHelperDatabase', JPATH_COMPONENT.'/helpers/mysql_database.php');
  23.                 $this->_db = HelloWorldHelperDatabase::getDatabase();
  24.                
  25.                 var_dump($this->_db);
  26.                 if ( JError::isError($this->_db) ) {
  27.                     jexit('Database Error: ' . $s->toString() );
  28.                 }
  29.  
  30.                 if ($this->_db->getErrorNum() > 0) {
  31.                         JError::raiseError(500, 'JDatabase::getInstance: Could not connect to database <br/>');
  32.                 }
  33.            
  34.         }
  35.    
  36.         /**
  37.      * Returns a reference to the a Table object, always creating it.
  38.      *
  39.      * @param   type    The table type to instantiate
  40.      * @param   string  A prefix for the table class name. Optional.
  41.      * @param   array   Configuration array for model. Optional.
  42.      * @return  JTable  A database object
  43.      * @since   1.6
  44.      */
  45.     public function getTable($type = 'HelloWorld', $prefix = 'HelloWorldTable', $config = array())
  46.     {
  47.         return JTable::getInstance($type, $prefix, $config);
  48.     }
  49.        
  50.     /**
  51.      * Method to get the record form.
  52.      *
  53.      * @param   array   $data       Data for the form.
  54.      * @param   boolean $loadData   True if the form is to load its own data (default case), false if not.
  55.      * @return  mixed   A JForm object on success, false on failure
  56.      * @since   1.6
  57.      */
  58.     public function getForm($data = array(), $loadData = true)
  59.     {
  60.         // Get the form.
  61.         $form = $this->loadForm('com_helloworld.helloworld', 'helloworld', array('control' => 'jform', 'load_data' => $loadData));
  62.         if (empty($form))
  63.         {
  64.             return false;
  65.         }
  66.         return $form;
  67.     }
  68.        
  69.     /**
  70.      * Method to get the data that should be injected in the form.
  71.      *
  72.      * @return  mixed   The data for the form.
  73.      * @since   1.6
  74.      */
  75.     protected function loadFormData()
  76.     {
  77.         // Check the session for previously entered form data.
  78.         $data = JFactory::getApplication()->getUserState('com_helloworld.edit.helloworld.data', array());
  79.  
  80.         if (empty($data))
  81.         {
  82.             $data = $this->getItem();
  83.         }
  84.                
  85.         return $data;
  86.     }
  87. }
Add Comment
Please, Sign In to add comment