PHP/Zend Framework 2 - 无法在动态生成的表中显示表字段值

标签 php mysql model-view-controller zend-framework2

问题

我正在尝试使用 Zend Framework 2 和 PHP/MySQL 将字段值显示到表中。鉴于下表是动态生成的,我正在尝试获取如下所示的值。不幸的是,我只得到单元格位置的空值。

问题

我如何解决这个问题以将值填充到它们的单元格位置?

enter image description here

代码

Controller.php

   public function summaryAction()
    {
        return new ViewModel(array(
            'actionitems' => $this->getActionItemTable()->fetchAll(),
        ));
    }

Table.php

    public function fetchAll()
    {
        $select = new Select();
        $select->from('actionitems', array('*'))
               ->join('users', 'actionitems.OwnerID = users.UserID', array('OwnerLastName' => new Expression('users.lastName'),  'OwnerFirstName' =>  new Expression('users.firstName')));   
        $resultSet = $this->tableGateway->selectWith($select);
        return $resultSet;
    }

index.phtml

        <table class="actionitemsummary">
                <tr>
                    <th>
                        Team
                    </th>
                    <th>
                        Item #
                    </th>
                    <th>
                        Action Item Title
                    </th>
                    <th>
                        Criticality
                    </th>
                    <th>
                        Status
                    </th>
                    <th>
                        Assigned Date
                    </th>
                    <th>
                        Original Due Date
                    </th>
                    <th>
                        ECD
                    </th>
                    <th>
                        Closed Date
                    </th>
                    <th>
                        Owner
                    </th>
                    <th>
                        Actions
                    </th>
                </tr>
                <?php 
                    use Application\Model\ActionItem;

                    /* @var $actionItem ActionItem */
                ?>

                <?php foreach($actionitems as $actionItem): ?>
                <tr>
                    <td class="team">
                        <?php echo $actionItem->team; ?>
                    </td>
                    <td class="itemnum">
                        <?php echo $actionItem->actionItemID; ?>
                    </td>
                    <td class="actionitemtitle">
                        <?php echo $actionItem->actionItemTitle; ?>
                    </td>
                    <td class="criticality">
                        <?php echo $actionItem->criticality; ?>
                    </td>
                    <td class="status <?php echo $actionItem->status; ?> onschedule">
                        <?php echo $actionItem->status; ?>
                    </td>
                    <td class="assigneddate">
                        <?php echo $actionItem->assignedDate; ?>
                    </td>
                    <td class="originalduedate">
                        <?php echo $actionItem->dueDate; ?>
                    </td>
                    <td class="ecd">
                        <?php echo $actionItem->ecd; ?>
                    </td>
                    <td class="closeddate">
                        <?php echo $actionItem->closedDate; ?>
                    </td>
                    <td class="owner">
                        <?php echo $actionItem->ownerID; ?>
                    </td>
                    <td class="actions">
                        <a href="">View</a>
                    </td>
                </tr>
                <?php endforeach; ?>
            </table>

编辑:

var_dump($resultSet);

object(Zend\Db\ResultSet\ResultSet)[287]
  protected 'allowedReturnTypes' => 
    array (size=2)
      0 => string 'arrayobject' (length=11)
      1 => string 'array' (length=5)
  protected 'arrayObjectPrototype' => 
    object(Application\Model\ActionItem)[258]
      public 'actionItemID' => null
      public 'status' => null
      public 'actionItemTitle' => null
      public 'railName' => null
      public 'team' => null
      public 'criticality' => null
      public 'assignedDate' => null
      public 'ecd' => null
      public 'dueDate' => null
      public 'closedDate' => null
      public 'completionDate' => null
      public 'closureCriteria' => null
      public 'notes' => null
      public 'assignorID' => null
      public 'ownerID' => null
      public 'altOwnerID' => null
      public 'approverID' => null
      public 'rejectionJustification' => null
      public 'approvalStatement' => null
      public 'closureStatement' => null
      public 'actionItemStatement' => null
  protected 'returnType' => string 'arrayobject' (length=11)
  protected 'buffer' => 
    array (size=0)
      empty
  protected 'count' => int 15
  protected 'dataSource' => 
    object(Zend\Db\Adapter\Driver\Pdo\Result)[264]
      protected 'statementMode' => string 'forward' (length=7)
      protected 'fetchMode' => int 2
      protected 'resource' => 
        object(PDOStatement)[265]
          public 'queryString' => string 'SELECT `actionitems`.*, users.lastName AS `OwnerLastName`, users.firstName AS `OwnerFirstName` FROM `actionitems` INNER JOIN `users` ON `actionitems`.`OwnerID` = `users`.`UserID`' (length=178)
      protected 'options' => null
      protected 'currentComplete' => boolean true
      protected 'currentData' => 
        array (size=22)
          'ActionItemID' => string '1' (length=1)
          'Status' => null
          'Team' => null
          'Criticality' => string '1 - High' (length=8)
          'AssignedDate' => string '2015-06-11' (length=10)
          'DueDate' => string '2015-06-02' (length=10)
          'CompletionDate' => null
          'ECD' => string '2015-06-07' (length=10)
          'ClosedDate' => null
          'ActionItemTitle' => string 'test' (length=4)
          'ActionItemStatement' => string 'test' (length=4)
          'AssignorID' => string '1' (length=1)
          'OwnerID' => string '1' (length=1)
          'AltOwnerID' => string '1' (length=1)
          'ApproverID' => null
          'RejectionJustification' => null
          'ApprovalStatement' => null
          'ClosureCriteria' => string 'test' (length=4)
          'ClosureStatement' => null
          'Notes' => string 'test' (length=4)
          'OwnerLastName' => string 'TEST' (length=13)
          'OwnerFirstName' => string 'TEST' (length=4)
      protected 'position' => int 0
      protected 'generatedValue' => string '0' (length=1)
      protected 'rowCount' => int 15
  protected 'fieldCount' => int 22
  protected 'position' => int 0

以下返回所有记录如上:

for ($i = 0; $i <  $resultSet->count(COUNT_NORMAL); $i++)
        {
            var_dump($resultSet);
            $resultSet->next();
         }

最佳答案

您需要使用“foreach”从数据库中获取条目,这是 ResulSet 对象的最佳方式:

foreach($resultSet $result){
    var_dump($result);
}

试一试。

关于PHP/Zend Framework 2 - 无法在动态生成的表中显示表字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30746756/

相关文章:

php - 检查网站是否被 .htaccess 重定向

php - MYSQL 获取数组无法在 php 中捕获行的名称

mysql - 新用户拥有MySQL 5.6的所有权限

model-view-controller - 选择 ColdFusion MVC 框架

asp.net-mvc - 使用基于 SQL 的本地化提供程序时,如何本地化/国际化 MVC Controller ?

php - 使用 Laravel 更新 : created_at is updated when updating record

php - 指定非 JSON ajax 的内容类型

php - Ubuntu 更改 sudo php 路径

php - 如何以应用程序仍可读的方式安全地存储密码?

java - JSP MVC 模型 2 架构问题