cakephp sql日志正确,未返回数据

cakephp sql日志正确,未返回数据,sql,database,cakephp,Sql,Database,Cakephp,在检查sql日志是否正确后,我正在创建一个简单的视图函数,但是我的视图没有打印信息 SELECT `AccountsUser`.`id`, `AccountsUser`.`account_id` FROM `pra`.`accounts_users` AS `AccountsUser` WHERE `user_id` = 14 SELECT `Template`.`id`, `Template`.`name`, `Template`.`description`, `T

在检查sql日志是否正确后,我正在创建一个简单的视图函数,但是我的视图没有打印信息

SELECT `AccountsUser`.`id`, `AccountsUser`.`account_id`
  FROM `pra`.`accounts_users` AS `AccountsUser`
 WHERE `user_id` = 14   

SELECT `Template`.`id`, `Template`.`name`, `Template`.`description`,
       `Template`.`account_id`
  FROM `pra`.`templates` AS `Template`
 WHERE `Template`.`account_id` = (10)
account\u id=10
但是它没有打印出与
account.id

function view(){
    $this->set('title_for_layout', 'View Templates');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.jpg');
    $this->layout='home_layout';

     $this->Template->unbindModel(array('belongsTo'=>array('Account')));
    $templates = $this->Auth->user('name');
    $accounts=$this->User->AccountsUser->find('list', array('fields'=>array('id', 'account_id'),'conditions' =>  array('user_id' => $this->Auth->user('id'))));       
    $templates=$this->Template->find('all', array('conditions' => array('Template.account_id' => $accounts)));

    $this->set('template', $templates);
    $this->set('account'. $accounts);}
这里是风景

<table width="100%" border="1">

            <table width="100%" border="1">
                <tr>
                    <th>Template Name</th>
                    <th>Template Description</th>

                </tr>

                <?php foreach($template as $templates): ?>
                    <tr>
                        <td align='center'><?php echo $templates['templates']['id']; ?> </td>
                        <td align='center'><?php echo $templates['templates']['name']; ?> </td>

                    </tr>
                 <?php endforeach; ?>


            </table>

模板名称
模板描述

我希望它能够打印与
帐户相关的模板列表。id

您应该尝试以下操作:

function view(){
    $this->set('title_for_layout', 'View Templates');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.jpg');
    $this->layout='home_layout';

     $this->Template->unbindModel(array('belongsTo'=>array('Account')));
    $templates = $this->Auth->user('name');
    $accounts=$this->User->AccountsUser->find('list', array('fields'=>array('id', 'account_id'),'conditions' =>  array('user_id' => $this->Auth->user('id'))));       
    $templates=$this->Template->find('all', array('conditions' => array('Template.account_id' => $accounts)));

    $this->set('template', $templates);
    $this->set('account'. $accounts);}
        <table width="100%" border="1">
            <tr>
                <th>Template Name</th>
                <th>Template Description</th>

            </tr>

            <?php if(!empty($template))
                  {
                    foreach($template as $templates)
                    {?>
                        <tr>
                           <td align='center'><?php echo $templates['Template']['id']; ?> </td>
                           <td align='center'><?php echo $templates['Template']['name']; ?> </td>
                        </tr>
                 <?php 
                    }// end of foreach
                  }
                  else
                  {?>

                        <tr> <td>No Templates Found.</td></tr>

                  <?php
                  }?>
        </table>

模板名称
模板描述
找不到模板。

您有
$this->set('account'.$accounts')而不是
$this->set('account',$accounts)(逗号而不是句号)。这是否会阻止执行到达视图中的正确位置?此外,您是否使用
debug($templates)进行了验证在控制器中,查询返回什么?修复了它,但没有更改任何内容,调试也不会产生任何结果。just array(),这让我很困惑,因为sqllog打印出正确的语句,如果在phpMyAdmin中运行相同的查询,则会得到结果?如果不返回0个结果,则应该有1个resultstill未从数据库中获取模板:(我认为变量设置不正确,account.id设置正确,但此行工作不正常,$accounts的设置返回正确的信息$templates=$this->Template->find('all',array('conditions'=>array('Template.account_id'=>$accounts));让我们使用数组((int)3=>'10')3是accounts_users.id,10是account_id不允许我在聊天中键入给你