2013-05-20 2 views
0

Я пытаюсь назвать модель с одного из моих контроллеров Joomla, но это, похоже, не работает.init модель от контроллера joomla 3.1

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/администратор /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); 
} 
+0

разместить getTableData функции вашей модели – Nagarjun

ответ

0
  1. Убедитесь, что модель $ model внутри контроллера не равна нулю. Если это не пустое, чем проблема, это где-то в вызванном методе модели.

  2. если $ model - null, то некоторая модель, которую вы вызываете, не загружается. Временная попытка просто включить файл с require_once JPATH_COMPONENT . '/models/datatable.php'

+0

поблагодарить Вас за отзыв, я был расширен мою тему, может быть, вы можете дать мне хороший совет, что я делаю неправильно. Заранее спасибо – fefe

Смежные вопросы