带有cakephp的jqgrid---调用非对象上的成员函数url()
这是我的控制器带有cakephp的jqgrid---调用非对象上的成员函数url(),php,cakephp,Php,Cakephp,这是我的控制器 <?php class PostsController extends AppController { var $name='Posts'; var $helpers=array('Html','Form'); var $components = array('Session','Paginator'); function beforeFilter() {
<?php
class PostsController extends AppController
{
var $name='Posts';
var $helpers=array('Html','Form');
var $components = array('Session','Paginator');
function beforeFilter()
{
parent::beforeFilter();
// $this->Auth->allow('index');
}
function index()
{
}
function getsites()
{
$this->layout= false;
$this->autoRender=false;
configure::write('debug',0);
// get no of rows
$limit= $this->params['url']['rows'];
//get the index row for sorting
$sidx= $this->params['url']['sidx'];
//get the sort order
$sord= $this->params['url']['sord'];
$page= $this->params['url']['page'];
//if sort collumn index not found then set it to 1
if(empty($sidx)) $sidx=1;
//calculate no of rows from query
$row=$this->Post->find('count');
$count=$row;
//if count is >0 then set total no of pages as per give limit
//else set total pages to 0
if($count>0)
$total_pages=ceil($count/$limit);
else
$total_pages=0;
//set start position of records
$start=$limit*$page-$limit;
if($start<0) $start=0;
//set range for data from database
$limitRange=$start.",".$limit;
$sortRange=$sidx.",".$sord;
//fetch only pure data avoiding unnecessay loading of related/associated data
$this->Post->recursive=-1;
$result=$this->Post->find('all',array('fields'=>array('id','title'),'order'=>$sortRange,'limit'=>$limitRange));
//setting the response object
$i=0;
$response->page=$page;
$response->total_pages=$total_pages;
$response->records=$count;
foreach($result as $row)
{
$response->rows[$i]['id']=$row['Post']['id'];
$response->rows[$i]['cell']=array($row['Post']['id'],$row['Post']['title'],$row['Post']['id']);
$i++;
}
echo json_encode($response);
exit;
}
}
this is the index.ctp
<h1>Blog posts</h1>
<script type="text/javascript">
$(document).ready(function(){
/* #id === id of the table */
$("#list").jqGid({
url:'<?php echo $html->url(array("controller"=>"Posts","action"=>"getsites")); ?>',
datatype:"json",
colNames:['Id','Title','IdHidden','Edit'],
colModel:[
{name:'id',index:'id',width:10},
{name:'title',index:'title',width:90},
{name:'idHidden',index:'idHidden',width:10,hidden:true},
{name:'Edit',index:'Edit',width:10,formatter : function(cellvalue,options,rowObject){return '<span class="editButtonSite ui-icon ui-icon-pencil" title="click to edit"></span>';}},
],
rowNum:2,
rowList:[2,4,6],
pager:jQuery("#pager"),
caption:'View Posts',
sortname:'id',
sortorder:'asc',
autowidth:true,
viewrecords:true,
loadcomplete:function(){
$("#content table tr td .editButtonSite").click(function(){
/*var ids = $(this).parent().prev().attr('title');
var editPage = '<?php echo $html->url(array("controller" => "sites", "action" => "edit"))?>';
editPage = editPage + "/" + ids;
window.location.href = editPage;*/
});
}
});
});
</script>
<table id="list" style="height:auto;"></table>
<div id="pager" style="height:auto;"></div>
帮我摆脱这一困境。使用Cake 2.x HtmlHelper更正您的代码
url:'<?php echo $this->Html->url(array("controller"=>"Posts","action"=>"getsites")); ?>',
在/app/View/Posts/index.ctp文件第6行,您不应该使用$html->url,而应该使用这个Router::url来更好地理解ind,请查看这个链接
Error: Call to a member function url() on a non-object
File: /var/www/html/jqgridtry.local/app/View/Posts/index.ctp Line: 6
url:'<?php echo $this->Html->url(array("controller"=>"Posts","action"=>"getsites")); ?>',