如何调用控制器传输中的数据(数组)到查看页面 [英] How can I call data (array) which is in controller transfer to view page

查看:61
本文介绍了如何调用控制器传输中的数据(数组)到查看页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从控制器传输数据数组以查看页面,但我已经声明了一个变量($ data),该变量将传输到查看页面。

I want to transfer data array from the controller to view the page but I already declared a variable ($data) that transfer to the view page.

如何我在控制器中传输了2个或更多变量

How can I transfer 2 or more variable in the controller

这是我的代码

控制器

public function manifest() {
    $this->Auth->authCheck();
    $data = $this->template();

    $data_array = array(

    'voyage_info' => $this->PortManifestModel->get_voyage()->result(),

    );

    // your code here
    $this->load->view("port/client/manifest", $data);
}

查看页面

 <a class="btn btn-primary primary-bg btn-lg  col-md-4 m-2 btn-cus" href="#">

       <?php foreach($voyage_info as $voyage) {  ?>
           <h3>Voyage <?=$voyage->voyage_number?></h3>
           <small>Schedule</small>                                                     
     <?php }  ?>                                                              
  </a>

我想获取 voyage_info 或更多数据在查看页面中,而不仅仅是 $ data
顺便说一下,$ data是用于模板的,因此我也需要它。

I want to get voyage_info or more data in view page, not just $data. By the way, $data is for the template so I need it as well.

推荐答案

做到这一点

在控制器中

$data['template'] = $this->template();
$data['voyage_info'] = $this->PortManifestModel->get_voyage()->result();

$this->load->view("port/client/manifest", $data);

可见的

$template # -> have your template data
$voyage_info # -> has your model data

这篇关于如何调用控制器传输中的数据(数组)到查看页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆