【问题标题】:Joomla 2.5 component geting data from database on adminJoomla 2.5 组件在管理员上从数据库中获取数据
【发布时间】:2013-06-06 06:01:32
【问题描述】:

我想从组件管理部分的数据库中获取数据。 奇怪的是,相同的代码在我的组件的站点部分有效,但在管理部分无效。

模型/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');
        }
    }  
}

感谢您的帮助。

【问题讨论】:

  • doesn't work 时会发生什么?错误信息?只是一个空白页?
  • 只是不显示数据库中的变量

标签: php database components joomla2.5 admin


【解决方案1】:

您直接将模型函数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>

希望这会对你有所帮助。

【讨论】:

  • 帮助了 :D 非常感谢 :*
猜你喜欢
  • 1970-01-01
  • 2013-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-13
  • 1970-01-01
  • 2012-07-24
  • 1970-01-01
相关资源
最近更新 更多