donglian4464 2013-06-10 14:29
浏览 33
已采纳

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

<?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');
        }
    }  
}

I appreciate any help.

  • 写回答

1条回答 默认 最新

  • dpl57372 2013-06-10 20:25
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看