dream3323 2013-05-20 10:14
浏览 41

来自控制器joomla 3.1的init模型

I try to call a model from one of my Joomla controller but that doesn't seem to work.

class TieraerzteControllerDatatable extends JControllerLegacy
{
        /**
         * display task
         *
         * @return void
         */

        function display($cachable = false) 
        {

                // set default view if not set

                $input = JFactory::getApplication()->input;

                $model = $this->getModel('datatable');

                $model->getTableData('grumpi_tieraerzte', 'id', array('id','name','strasse','telefon','fax'));

                die();

        }
}

In my model I placed a var_dump but it is not accessed. How can I debug my model call in controller?

I try to access the models return with the following url /administrator/index.php?option=com_tieraerzte&task=datatable.display&{arguments for the model}

trying to debug my codes piece by piece seems like the model is accessed and this code is causing the problem

 // Paging
 $sLimit = "";
 if (isset(JRequest::getVar('iDisplayStart')) && JRequest::getVar('iDisplayLength') != '-1')
 {
     $sLimit = "LIMIT " . intval(JRequest::getVar('iDisplayStart')) . ", " . intval(JRequest::getVar('iDisplayLength'));
 }

The whole method:

public function getTableData($table, $index_column, $columns)
{
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);

    // Paging
    $sLimit = "";
    if (isset(JRequest::getVar('iDisplayStart')) && JRequest::getVar('iDisplayLength') != '-1')
    {
        $sLimit = "LIMIT " . intval(JRequest::getVar('iDisplayStart')) . ", " . intval(JRequest::getVar('iDisplayLength'));
    }
    // Ordering

    $sOrder = "";
    if (isset(JRequest::getVar('iSortCol_0')))
    {
        $sOrder = "ORDER BY ";
        for ($i = 0; $i < intval(JRequest::getVar('iSortingCols')); $i++)
        {
            if (JRequest::getVar('bSortable_' . intval(JRequest::getVar('iSortCol_' . $i))) == "true")
            {
                $sortDir = (strcasecmp(JRequest::getVar('sSortDir_' . $i), 'ASC') == 0) ? 'ASC' : 'DESC';
                $sOrder .= "`" . $columns[intval(JRequest::getVar('iSortCol_' . $i))] . "` " . $sortDir . ", ";
            }
        }

        $sOrder = substr_replace($sOrder, "", -1);
        if ($sOrder == "ORDER BY") {
            $sOrder = "";
        }
    }

    /*

    * Filtering

    * NOTE this does not match the built-in DataTables filtering which does it

    * word by word on any field. It's possible to do here, but concerned about efficiency

    * on very large tables, and MySQL's regex functionality is very limited

    */

    $sWhere = "";

    if (isset(JRequest::getVar('sSearch')) && JRequest::getVar('sSearch') != "")
    {
        $like = '%' . JRequest::getVar('sSearch') . '%';
        $sWhere = "WHERE (";
        for ($i = 0; $i < count($columns); $i++)
        {
            if (isset(JRequest::getVar('bSearchable_' . $i)) && JRequest::getVar('bSearchable_' . $i) == "true")
            {
                $sWhere .= "`" . $columns[$i] . "` LIKE '" . $like . "' OR ";
            }
        }

        $sWhere = substr_replace($sWhere, "", -3);
        $sWhere .= ')';
    }

    // Individual column filtering

    for ($i = 0; $i < count($columns); $i++)
    {

        if (isset(JRequest::getVar('bSearchable_' . $i)) && JRequest::getVar('bSearchable_' . $i) == "true" && JRequest::getVar('sSearch_' . $i) != '')
        {
            if ($sWhere == "")
            {
                $sWhere = "WHERE ";
            } else {
                $sWhere .= " AND ";
            }
            $sWhere .= "`" . $columns[$i] . "` LIKE ? " . $i . " ";
        }
    }

    // SQL queries get data to display

    $sQuery = "SELECT SQL_CALC_FOUND_ROWS `" . str_replace(" , ", " ", implode("`, `", $columns)) . "` FROM `" . $table . "` " . $sWhere . " " . $sOrder . " " . $sLimit;
    $statement = $this->_db->prepare($sQuery);


    // Bind parameters
    if (isset(JRequest::getVar('sSearch')) && JRequest::getVar('sSearch') != "")
    {
        $statement->bind_param('s', $like);
    }

    for ($i = 0; $i < count($columns); $i++)
    {
        if (isset(JRequest::getVar('bSearchable_' . $i)) && JRequest::getVar('bSearchable_' . $i) == "true" && JRequest::getVar('sSearch_' . $i) != '')
        {
            $statement->bind_param('s' . $i, '%' . $_GET['sSearch_' . $i] . '%');
        }
    }

    $db->setQuery($sQuery);
    $res = $db->loadObjectList();
    $rResult = array();

    foreach ($res as $row)
    {
        $rResult[] = $row;
    }

    $iFilteredTotal = current($db->setQuery('SELECT FOUND_ROWS()')->loadResultArray());

    // Get total number of rows in table

    $sQuery = "SELECT COUNT(`" . $index_column . "`) FROM `" . $table . "`";

    $iTotal = current($db->setQuery($sQuery));

    // Output

    $output = array(
        "sEcho" => intval($_GET['sEcho']),
        "iTotalRecords" => $iTotal,
        "iTotalDisplayRecords" => $iFilteredTotal,
        "aaData" => array()
    );

    // Return array of values

    foreach ($rResult as $aRow)
    {
        $row = array();
        array_push($row, '<input type="checkbox" id="someCheckbox" name="someCheckbox" />');
        for ($i = 0; $i < count($columns); $i++)
        {
            //var_dump($aRow->$columns[$i]);    
            if ($columns[$i] != '')
            {
                $row[] = $aRow->$columns[$i];
            }
        }

        array_push($row, '    
        <div class="btn-group" id="status">
            <input type="button" class="btn b1" value="On">
            <input type="button" class="btn b0 btn-danger" value="Off">
        </div>
        ');

        array_push($row, '
         <div class="clearfix">
           <a href =""><div class="label label-important" style="padding:6px 9px; margin-right:5px"><span class="icon-trash"></span></div></a>
           <a href="index.php?option=com_tieraerzte&task=tieraerzt.edit&layout=edit&id=' . $aRow->id . '"><div class="label label-success" style="padding:6px 9px"><span class="icon-cog"></span></div></a>
         </div>
        ');
        $output['aaData'][] = $row;
    }
    echo json_encode($output);
}
  • 写回答

1条回答 默认 最新

  • dongyi6269 2013-05-22 18:07
    关注
    1. Make sure $model inside the controller is not null. If it's not null, than the problem is somewhere in the model's method called.

    2. if $model is null, somehow the model you are calling is not loaded. Temporary try just to include the file with require_once JPATH_COMPONENT . '/models/datatable.php'

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭