【问题标题】:pass a variable to view being it a variable of an array of array传递一个变量来查看它是一个数组数组的变量
【发布时间】:2012-02-12 16:19:09
【问题描述】:

我在 codeigniter 中创建了一个控制器,并在其中创建了两个数组:

  $header_data['base_url'] = base_url();

  $templates['header'] = "/application/views/templates/header.php";
  $templates['auth_page'] = "/application/views/templates/auth_page.php";
  $templates['footer'] = "/application/views/templates/footer.php";

现在我创建了一个包含先前数组的唯一数组:

$page_data['data_header'] = $header_data;
$page_data['templates'] = $templates;

并将其传递给视图:

$this->load->view('main.php',$page_data);

现在,一旦我们在视图中,我如何调用变量 $base_url,因为它在 header_data 内,它在 $page_data 数组内?

【问题讨论】:

  • $page_data['data_header']['base_url']?

标签: php codeigniter


【解决方案1】:

在视图中,可以使用extract()

extract($data_header);

echo $base_url; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多