dongpao1083
2018-03-26 20:29
浏览 42
已采纳

将数组数据传递给CodeIgniter中的控制器进行查看

Here is my controller function code:

         public function dispcp(){
            $data = array(
            'company' => $this->input->post("company"),
            'fyfrom' => $this->input->post("fyfrom"),
            'fyto' => $this->input->post("fyto"),
          );   

    $this->load->view('view',$data);
 }  

Here the data comes from a form from another view.

this is what my code in view.php looks like :
<?php print_r ($data[0]->fyfrom); ?>

Error:
Message: Undefined variable: data

Filename: views/view.php

Line Number: 14

Backtrace:

File: C:\wamp\www\admin\application\views\view.php Line: 14 Function: _error_handler

File: C:\wamp\www\admin\application\controllers\Dashboard.php Line: 586 Function: view

File: C:\wamp\www\admin\index.php Line: 263 Function: require_once

Works correctly in Controller, not in view.

图片转代码服务由CSDN问答提供 功能建议

这是我的控制器功能代码:

 <  code> public function dispcp(){
 $ data = array(
'company'=&gt; $ this-&gt; input-&gt; post(“company”),
'yy''=&gt; $ this-  &gt; input-&gt; post(“fyfrom”),
'fyto'=&gt; $ this-&gt; input-&gt; post(“fyto”),
);  
 
 $ this-&gt; load-&gt; view('view',$ data); 
} 
   
 
 

这里 数据来自另一个视图的表单。

这是我在view.php中的代码看起来像:
&lt;?php print_r($ data [0] - &gt; fyfrom); ?&gt;

错误:
消息:未定义的变量:数据

文件名:views / view.php

行号:14

Backtrace:

文件:C:\ wamp \ www \ admin \ application \ views \ view.php Line:14 功能:_error_handler

文件:C:\ wamp \ www \ admin \ application \ controllers \ Dashboard.php Line:586 功能:view < / p>

文件:C:\ wamp \ www \ admin \ index.php Line:263 功能:require_once

正常工作 在Controller中,不在视图中。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglu1881 2018-03-26 20:32
    已采纳

    Once the data is passed to the view you need to use the array keys are variables directly :

    <?php print_r($fyfrom); ?>
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题