簡體   English   中英

Joomla 2.5組件從管理員數據庫中獲取數據

[英]Joomla 2.5 component geting data from database on admin

我想從組件的admin部分的數據庫中獲取數據。 奇怪的是,相同的代碼在我組件的站點部分上有效,但在管理部分上不起作用。

型號/statistic_adm.php

<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.model');
jimport( 'joomla.database.database' );
jimport( 'joomla.database.table' );

class sblogModelstatistic_adm extends JModel
{
    public function getCode(){
        $db =& JFactory::getDBO();
        $query = 'SELECT `code` FROM `#__sblog_ustawienia`';
        $db->setQuery($query);
        return $db->loadRowList();
    }
}

views / statistic_adm / tmpl / default.php

<?php
// No direct access to this file
defined( '_JEXEC' ) or die('Restricted Access');
$document = JFactory::getDocument();
jimport( 'joomla.filter.output' );

$tabela = $this->get('getCode');
$code = $tabela[0][0];
?>

<form action="index.php?option=com_sblog&view=statistic_adm" method="post" name="adminForm">

<label>Kod bloga:</label> <input type='text' name='code' value="<?php echo $tabela[0][0]; ?>" />

<input type="hidden" name="task" value="" />

</form>

views / statistic_adm / tmpl / view.html.php

<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.view');

class sblogViewStatistic_adm extends JView
{
    function display($tpl = null)
    {
        JSubMenuHelper::addEntry(JText::_('Ustawienia'), 'index.php?option=com_sblog&amp;view=statistic_adm', true);
        JToolBarHelper::title( JText::_('System blogowy'), 'generic.png' );

        $task   = JRequest::getCmd('task');    
        $model = &$this->getModel('statistic_adm');

        //$model=JFactory::getDBO();
        $getCode = $model->getCode();
        $this->assignRef('getCode', $getCode);

        $this->addToolBar();
        parent::display($tpl);
    }
     protected function addToolBar() {          
        if (JRequest::getVar('layout') != 'edit')  
        {  
            JToolBarHelper::save('save','Zapisz');
        }
    }  
}

感謝您的幫助。

您無需定義模型即可直接將模型函數getcode調用到模板中。 另外,您已經在view.html.php分配了getcode函數的值,因此您可以直接將該變量調用到模板中,如下所示,

<?php
// No direct access to this file
defined( '_JEXEC' ) or die('Restricted Access');
$document = JFactory::getDocument();
jimport( 'joomla.filter.output' );

//get the value assigned in the view.html.php
$tabela = $this->getCode;
$code = $tabela[0][0];
?>

<form action="index.php?option=com_sblog&view=statistic_adm" method="post" name="adminForm">   
<label>Kod bloga:</label> <input type='text' name='code' value="<?php echo $code; ?>" />
<input type="hidden" name="task" value="" />
</form>

希望這會幫助你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM