0_0 发表于 2013-6-29 20:59:48

CI 视图接收不到控制器传送过去的数据

function testpage($id = null) {
    $data['mytitle'] = 'Welcome to this site';
    $data['mytext'] = "Hello, $name, now we're getting dynamic!";
    $this->load->view('testpage', $data);
}//控制器

//视图
<?php print_r($data);?>

然后视图就提示 $data 未定义

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: views/testpage.php

Line Number: 2

zpslyp680 发表于 2013-6-30 20:40:39

在在视图里这么打印<?php print_r($testpage);?>

kinwyb 发表于 2013-7-1 13:15:28

这样传递是不能获取到data这个变量的。
你只能获取到data数组下以标记为名称的变量
function testpage($id = null) {
    $data['mytitle'] = 'Welcome to this site';
    $data['mytext'] = "Hello, $name, now we're getting dynamic!";
    $this->load->view('testpage', $data);
}//控制器
在视图中能获取到的变量是
$mytitle 和 $mytext
页: [1]
查看完整版本: CI 视图接收不到控制器传送过去的数据