Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // No direct access to this file
- defined('_JEXEC') or die('Restricted access');
- // import Joomla modelform library
- jimport('joomla.application.component.modeladmin');
- /**
- * HelloWorld Model
- */
- class HelloWorldModelHelloWorld extends JModelAdmin
- {
- /**
- * Constructor that creates a connection to the database
- *
- * @return void
- */
- public function __construct(){
- parent::__construct();
- JLoader::register('HelloWorldHelperDatabase', JPATH_COMPONENT.'/helpers/mysql_database.php');
- $this->_db = HelloWorldHelperDatabase::getDatabase();
- var_dump($this->_db);
- if ( JError::isError($this->_db) ) {
- jexit('Database Error: ' . $s->toString() );
- }
- if ($this->_db->getErrorNum() > 0) {
- JError::raiseError(500, 'JDatabase::getInstance: Could not connect to database <br/>');
- }
- }
- /**
- * Returns a reference to the a Table object, always creating it.
- *
- * @param type The table type to instantiate
- * @param string A prefix for the table class name. Optional.
- * @param array Configuration array for model. Optional.
- * @return JTable A database object
- * @since 1.6
- */
- public function getTable($type = 'HelloWorld', $prefix = 'HelloWorldTable', $config = array())
- {
- return JTable::getInstance($type, $prefix, $config);
- }
- /**
- * Method to get the record form.
- *
- * @param array $data Data for the form.
- * @param boolean $loadData True if the form is to load its own data (default case), false if not.
- * @return mixed A JForm object on success, false on failure
- * @since 1.6
- */
- public function getForm($data = array(), $loadData = true)
- {
- // Get the form.
- $form = $this->loadForm('com_helloworld.helloworld', 'helloworld', array('control' => 'jform', 'load_data' => $loadData));
- if (empty($form))
- {
- return false;
- }
- return $form;
- }
- /**
- * Method to get the data that should be injected in the form.
- *
- * @return mixed The data for the form.
- * @since 1.6
- */
- protected function loadFormData()
- {
- // Check the session for previously entered form data.
- $data = JFactory::getApplication()->getUserState('com_helloworld.edit.helloworld.data', array());
- if (empty($data))
- {
- $data = $this->getItem();
- }
- return $data;
- }
- }
Add Comment
Please, Sign In to add comment