Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查看can';调用控制器函数Zend Framework 2_Php_Zend Framework - Fatal编程技术网

Php 查看can';调用控制器函数Zend Framework 2

Php 查看can';调用控制器函数Zend Framework 2,php,zend-framework,Php,Zend Framework,我无法在查看页面中调用我的控制器。即使我在控制器中使用了print\r,但它没有显示。我有body\u产品。phtml查看代码: <table class="table table-hover table-condensed"> <tbody> <?php $i = 1; //print_r("lis

我无法在查看页面中调用我的控制器。即使我在控制器中使用了
print\r
,但它没有显示。我有
body\u产品。phtml
查看代码:

<table class="table table-hover table-condensed">
                <tbody>
                    <?php
                        $i = 1;
                        //print_r("list produk:".$this->productList);
                         foreach ($this->productList as $data) {
                            $desc=explode(",",$data['descriptions']);
                            ?>
                            <tr>
                                <th colspan="3">
                                    <input type="hidden" id="id_pack" name="id_pack" value="<?php echo $data['package_id']; ?>">
                                    <input type="hidden" id="nama_pack" name="nama_pack" value="<?php echo $data['package_name']; ?>">
                                    <h4 align="center" class="title-pack"><?php echo $data['package_name']; ?></h4>
                                </th>
                            </tr>
                            <tr id="dashe">
                                <td>
                                    <ul class="myul">
                                    <?php foreach($desc as $descriptions) { ?>
                                        <li class="myli"> <?php echo $descriptions; ?></li>
                                    <?php } ?>
                                    </ul>
                                </td>
                                <td>
                                    <h4 class="prize">
                                        <?php setlocale(LC_MONETARY, 'id_ID');
                                        echo money_format('%.2n', $data['package_price']); ?>
                                        / month
                                    </h4>
                                </td>
                                <td>
                                    <p id="btn-hrm" class="mybutton" data-toggle="modal" data-target=".mymodal">Order</p>
                                </td>
                            </tr>
                            <?php
                            $i++;
                        }
                    ?>
                </tbody>
            </table>
如果在视图中打开print\r,它将显示错误
警告:为…
中的foreach()提供的参数无效。我想这是因为视图无法调用控制器。
请帮帮我,谢谢。

首先,当您尝试使用print\r时,它需要一个数组。因此,它应该类似于打印($arr)。也可以尝试一下,看看是否有帮助

public function loadProductAction() {
        $storage = Product\Storage::factory($this->getDb());
        $productList = new Product($storage);
        $data = $productList->loadProduct();
        $arr = array();
        if (is_array($data) && !empty($data)) {
            foreach ($data as $val) {
                array_push($arr, $val);
            }
        } else {
            echo '$data is not an array or it is empty';
        }
        print_r($arr);
        return new ViewModel(array(
            'productList' => $arr
        ));
    }

错误消息的结尾是什么?这是来自视图中的foreach还是控制器中的foreach?您最终能否检查$data的变量类型?
public function loadProductAction() {
        $storage = Product\Storage::factory($this->getDb());
        $productList = new Product($storage);
        $data = $productList->loadProduct();
        $arr = array();
        if (is_array($data) && !empty($data)) {
            foreach ($data as $val) {
                array_push($arr, $val);
            }
        } else {
            echo '$data is not an array or it is empty';
        }
        print_r($arr);
        return new ViewModel(array(
            'productList' => $arr
        ));
    }