codeigniter:已发送到模型

问题描述 投票:0回答:1

$(document).ready(function() { // admin contorller drop down ajax $("#catagoryDropDownList").change(function() { getCatagoriesItems(); }); // initiate table sort TableSorter.prepareTable($("#dataResultsTable")); }); // ajax request triggered by catagory drop down menu selection function getCatagoriesItems() { blockPage(); // get base url of current site var baseurl = $("#site_url_for_ajax").val(); // get adminType var adminType = $("#admin_type").val(); // get catagory id var catId = $("#catagoryDropDownList option:selected").attr("id"); var queryString = baseurl + "home/ajaxCatagorySelection/" + catId + "/" + adminType; $.get(queryString, function(data) { var obj = jQuery.parseJSON(data); // dump data into table when request is successful $("#dataResultsTable tbody").html(JSONParser.parseHomeDropDownSelectedJSON(obj)); // unblock page when done $.unblockUI(); }); }

我记录了两个值,即CATID和ADMINTYPE,它们都是整数,CATID将在1-10和AndIntype = 1之间。在数据库中,这两个都引用了INT值。 Catid引用了一个名为“ categoryId”的字段。 catid 6 =全部。 DB中的条目都没有6个作为其价值,因此确保您是否过滤了6个,您将获得全部。他们将传递到Controller File.home.php中的称为AjaxCatagorySelection的函数。到目前为止,一切都很好。这是该功能:

public function ajaxCatagorySelection($tableName, $id) { $vars = new DatabaseRetriever($id); $resultsArray = $vars->getDataForSpecifiedTable($tableName, $id); echo json_encode($resultsArray); }
该功能本身就是引用模型(database_retriever.php)和类databaseretriever的模型,并且我假设将变量传递到函数getDataforspecifiedtable。我之所以这样说,是因为变量名称从CATID到$ TableName和Admintype变为$ ID。这是getDataforspecifiedTable:

public function getDataForSpecifiedTable($catagoryInfo, $databaseID) { // connect to database $sql = $this->connect($databaseID); if ($catagoryInfo != 6) { // build SQL Query and query the database $result = $sql->query("SELECT fileId, fileTitle, filePath, fileTypeExt, fileDescription, fileModed from admin_files where catagoryId = '" . $catagoryInfo . "' and adminId = '" . $databaseID . "'"); } else { $result = $sql->query("SELECT fileId, fileTitle, filePath, fileTypeExt, fileDescription, fileModed from admin_files where catagoryId = '" . $catagoryInfo . "' and adminId = '" . $databaseID . "'"); } // declare array $items = array(); // retriever rows from database and build array while ($row = $result->fetch_row()) { array_push($items, $row); } // disconnect from database $this->disconnect(); // return data in array return $items; }
变量名称再次更改,但您可以说他们应该通过查看查询来做我上面写的事情。这是问题。我添加了有条件的“ if($ catagoryinfo!= 6)...”,如果我不将其他放置在其中,则CI会出现警告错误,没有返回数据。我返回$ categoryInfo,并在Firebug控制台中获得正确的整数。我尝试了有条件的整数和一个失败的字符串。有什么想法在这里可能发生什么? 

如果是模型,您应该这样称呼:

database_retriever.php
php codeigniter variables model
1个回答
2
投票
也要确保您的模型

$this->load->model('database_retriever'); $resultsArray = $this->Database_retriever->getDataForSpecifiedTable($tableName, $id);

(或在CodeIgniter 2中)。

注:

extends Model
,将为您自动自动json,因此您无需致电
extends CI_Model

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.