我authorcontroller文件蛋糕PHP沒有設置當從CTP文件調用函數
class AuthorController extends AppController {
public function author_quotes_list($author,$page="null")
{
$perpage=30;
$this->commen();
$author_data=$this->Author->query("select author.*,professions.professions_name from author,professions where author.professions_id=professions.id and author.author_name='$author' and author.status=1 ");
$this->set('author_data',$author_data);
//paging
$count=$quotes_data=$this->Author->query("select count(id) from quotes where author_id=".$author_data[0]['author']['id']." and status=1");
$limit=$this->paging($page,$count,$perpage);
$quotes_data=$this->Author->query("select id,quotes from quotes where author_id=".$author_data[0]['author']['id']." and status=1 limit $limit,$perpage");
//print_r($quotes_data);
$this->set('quotes_data',$quotes_data);
}
public function ratings($q_id)
{
//echo $quotes_id;
$tuser=$this->Author->query("select count(id) from user where status=1");
//print_r($tuser);
if($tuser==NULL)
{
$this->set('tuser',0);
}
else
{
$this->set('tuser',$tuser[0][0]['count(id)']);
}
$vusers=$this->Author->query("select * from totalrate where quoteid=$q_id");
print_r($vusers);
if($vusers==NULL)
{
$this->set('vuser',0);
$this->set('trate',0);
}
else
{
$this->set('vuser',$vusers[0]['totalrate']['totaluser']);
$this->set('trate',$vusers[0]['totalrate']['totalrate']);
}
}
我author_quotes_list.ctp文件
<?php $this->requestAction(array('controller' => 'Author', 'action' => 'ratings/'.$quotes['quotes']['id']));?>
<div class="star_txt">(<?php echo $trate; ?>/5, <?php echo $vuser; ?> votes) from <?php echo $tuser; ?> Users</div>
我的呼喚作者控制器的收視功能的價值調用此函數但不設置$ trate,$ vuser和$ tuser值的值。
題外話,但你似乎沒有使用你的CakePHP模型,因爲它們應該被使用。你幾乎不需要*寫你自己的查詢,這將完全跳過框架的功能。請閱讀本章[檢索數據](http://book.cakephp.org/2.0/en/models/retrieving-your-data.html) – thaJeztah 2013-03-23 13:03:10
另外,CakePHP在按照預期使用模型時提供了「分頁」盒子'。本章解釋了CakePHP中的分頁:[分頁](http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html) – thaJeztah 2013-03-23 13:06:12
看來英語正在成爲一種解釋障礙這適當。我在我的評論中包含了一些鏈接,其中包含有關如何在CakePHP中使用模型和分頁的示例。但是,這些僅僅是改善代碼和優化CakePHP的建議。這不是直接問題的答案,但至少爲您的應用程序提供了進一步開發的堅實「起點」 – thaJeztah 2013-03-23 13:30:02