Note that there are some explanatory texts on larger screens.

plurals
  1. POJoomla 2.5 variable global in components scope
    primarykey
    data
    text
    <p>Im developing custom Joomla 2.5 backend component. I would like to know best practice of making variable global in my components scope. Should I put declarations in components main controller? </p> <pre><code>class MyController extends JController { /** * * @var object External database object */ public $dbExternal; function __construct($config = array()) { $this-&gt;dbExternal = $this-&gt;_getDbInstance(); JTable::setDbo($this-&gt;dbExternal); parent::__construct($config); } /** * Display task * * @return void */ function display($cachable = false, $urlparams = false) { // set default view if not set JRequest::setVar('view', JRequest::getCmd('view', 'My')); // call parent behavior parent::display($cachable); // Set the submenu MyHelper::addSubmenu('messages'); } /** * Getting instance of the database * * @return instance $dbExternal Return db instance on success */ private function _getDbInstance() { $params = $this-&gt;_getDbParams(); $dbExternal = JDatabase::getInstance($params); if ($dbExternal-&gt;getErrorNum() &gt; 0) { JError::raiseWarning(500, 'JDatabase::getInstance: '. $dbExternal-&gt;getErrorMsg()); $this-&gt;isError = true; } return $dbExternal; } /** * Getting external db parameters * * @return array $dbParamsArr Return db params on success */ private function _getDbParams() { $dbParamsArr = array(); $params = JComponentHelper::getParams('com_my'); $dbParamsArr['host'] = $params-&gt;get('db_host'); $dbParamsArr['user'] = $params-&gt;get('db_user'); $dbParamsArr['password'] = $params-&gt;get('db_password'); $dbParamsArr['database'] = $params-&gt;get('db_database'); $dbParamsArr['driver'] = $params-&gt;get('db_driver'); return $dbParamsArr; } } </code></pre> <p>So I would like to reach $dbExternal in any other components controller or model. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload