【问题标题】:Matrix of Controller to View - ZF要查看的控制器矩阵 - ZF
【发布时间】:2014-07-24 16:21:23
【问题描述】:

控制器

我的矩阵是$mes:

print_r($mes);


Array ( 
   [0] => Array ( 
          [0] => 0 
          [1] => 0 
          [2] => 0 
          [3] => 0 
          [4] => 0
          [5] => 0 
          [6] => 3 
          [7] => 1 
          [8] => 0 
          [9] => 0 
          [10] => 0 
          [11] => 0 
          [12] => 0 
      ) 
   ) 
 Array ( 
      [1] => Array ( 
            [0] => 0 
            [1] => 0 
            [2] => 0 
            [3] => 0 
            [4] => 0 
            [5] => 0 
            [6] => 2 
            [7] => 0 
            [8] => 0 
            [9] => 0 
            [10] => 0 
            [11] => 0 
            [12] => 0 
         ) 
     )

发送数据以查看:

$this->view->repMes = $mes;

在视图中

<?php print_r($this->repMes); ?>

Array ( 
  [0] => 0 
  [1] => 0
  [2] => 0 
  [3] => 0 
  [4] => 0 
  [5] => 0 
  [6] => 2
  [7] => 0 
  [8] => 0 
  [9] => 0 
  [10] => 0 
  [11] => 0 
  [12] => 0 
)

可以证明缺少矩阵的第一部分,因为它可以解决?

【问题讨论】:

  • 旧的 zend 1 库中可能存在一个错误,它两次处理一个动作(在某些浏览器中,我仍然不知道为什么!!),所以你会在 print_r.Update 之后看到两个数组输出你的 zend 库到最新的 zend 1.x.x

标签: php arrays zend-framework matrix


【解决方案1】:

我相信你想要一个二维数组,但是看着你的代码,我发现你有两个不同的数组。所以你 $mes 变量指向第二个数组,这就是为什么你在视图中只看到第二个数组。您应该将控制器中的数组设置为:

 $mes =   Array ( 
               [0] => Array ( 
                      [0] => 0 
                      [1] => 0 
                      [2] => 0 
                      [3] => 0 
                      [4] => 0
                      [5] => 0 
                      [6] => 3 
                      [7] => 1 
                      [8] => 0 
                      [9] => 0 
                      [10] => 0 
                      [11] => 0 
                      [12] => 0 
                  )
              [1] => Array ( 
                        [0] => 0 
                        [1] => 0 
                        [2] => 0 
                        [3] => 0 
                        [4] => 0 
                        [5] => 0 
                        [6] => 2 
                        [7] => 0 
                        [8] => 0 
                        [9] => 0 
                        [10] => 0 
                        [11] => 0 
                        [12] => 0 
                     )
            )

【讨论】:

    【解决方案2】:

    请注意,当您打印矩阵时,它显示为两个不同的数组,这是因为您的代码流未发送正确的数组。

    1. 你的数组“$mes”应该是这样的:
    Array ( 
        [0] => Array ( 
            [0] => 0, 
            [1] => 0, 
            [2] => 0, 
            [3] => 0, 
            [4] => 0,
            [5] => 0, 
            [6] => 3, 
            [7] => 1, 
            [8] => 0, 
            [9] => 0, 
            [10] => 0, 
            [11] => 0, 
            [12] => 0 ),
       [1] => Array ( // See here you should have the second subindex, and not the closing and reopening
            [0] => 0, // of "Array"
            [1] => 0, 
            [2] => 0, 
            [3] => 0, 
            [4] => 0, 
            [5] => 0, 
            [6] => 2, 
            [7] => 0, 
            [8] => 0, 
            [9] => 0, 
            [10] => 0, 
            [11] => 0, 
            [12] => 0) 
     )
    

    我建议使用临时计数器变量来检查您的“打印”是否重复

    有些喜欢:

    echo "<pre> Loop --> \n";
    print_r($mes);
    echo "End Loop\n</pre>";
    

    这样你就可以检查真正的数组了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      相关资源
      最近更新 更多