0

我尝试从我的一个 Joomla 控制器调用模型,但这似乎不起作用。

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();

        }
}

在我的模型中,我放置了一个 var_dump 但它没有被访问。如何在控制器中调试模型调用?

我尝试使用以下 url /administrator 访问模型返回/index.php?option=com_tieraerzte&task=datatable.display&{arguments for the model}

尝试逐段调试我的代码似乎已访问模型并且此代码导致了问题

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

整个方法:

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);
}
4

1 回答 1

0
  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'

于 2013-05-22T18:07:05.113 回答