简体   繁体   English

CodeIgniter从控制器传递动态数据到视图

[英]CodeIgniter passing dynamic data from controller to view

I am passing an array to a view from a controller. 我正在将数组传递给控制器​​的视图。 Simple stuff. 简单的东西。 Should work, but is behaving rather too strangely and I cannot figure out the bug. 应该可以工作,但是表现却很奇怪,我无法弄清楚该错误。

This is the controller- 这是控制器-

$link = "http://" . $server . ".something.com/uploads/" . $name;
$data = array(
    'name' =>$name,
    'server'=>$server,
    'link'=>$link,
    'username'=>$username
    );
$this->load->view('photo_edit', $data); //sending $data to view

This is the view - 这是视图-

<img src = "<?php echo $link; ?>"/>

When the view loads, the $link is just this - http://.something.com/uploads/ But when I echo the $link in the controller, its totally fine (with both the $server and $name showing correctly). 当视图加载时, $link就是这样http://.something.com/uploads/但是当我在控制器中回显$ link时,它是完全可以的( $server$name正确显示)。 There is some issue with passing the $link . 传递$link有一些问题。

You need to add $link to your $data array so the view can see it. 您需要将$ link添加到$ data数组中,以便视图可以看到它。

Do this instead: $data['link'] = "http://" . 而是这样做:$ data ['link'] =“ http://”。 $server . $ server。 ".something.com/uploads/" . “ .something.com / uploads /”。 $name; $ name;

You definitely need to double check the incoming values of those post variables. 您绝对需要仔细检查这些post变量的传入值。 Make sure your form is passing them correctly too. 确保您的表格也正确传递了它们。

the problem is somewhere else, the code is right. 问题出在别的地方,代码正确。 check if $server and $name are empty. 检查$server$name是否为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM