Joomla 2.5组件从管理员数据库中获取数据 [英] Joomla 2.5 component geting data from database on admin

查看:59
本文介绍了Joomla 2.5组件从管理员数据库中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从组件的admin部分的数据库中获取数据. 奇怪的是,相同的代码在我组件的站点部分上起作用,而在管理部分上不起作用.

I want to get data from database in admin section of my component. The strange thing is that the same code works on site part of my component but does not work on the admin part.

models/statistic_adm.php

models/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

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

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函数的值,因此您可以像下面那样直接将该变量调用到模板中,

You are directly call your model function getcode into your template without defining the model. Also you already assign the value of getcode function in view.html.php ,so you can directly call that variable into your template like below,

<?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>

希望这会对您有所帮助.

Hope this will help you.

这篇关于Joomla 2.5组件从管理员数据库中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆