0

我正在创建一个简单的视图函数,在检查我的 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_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 喜欢打印与account.id

4

1 回答 1

0

您应该尝试以下方法:

        <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>
于 2012-08-07T08:54:50.593 回答