[英]codeigniter / groceryCRUD send data to view not working
I have a script that works, this one: 我有一个有效的脚本,这个:
$output = $crud->render();
$data = array();
$data['title'] = 'Invoice details';
$output->data = $data;
$this->output($output); /* crud render and extra fields */
the thing is that this script is opening a function in the controler: 问题是该脚本正在控制器中打开一个函数:
public function output($output = null) {
$this->load->view('template.php', $output);
}
and the template file as this: (and more) 和模板文件如下:(还有更多)
<title><?php echo ucfirst($data['title']); ?></title>
works like a charm. 奇迹般有效。
the template file is loading the header and footer and a bunch of css 模板文件正在加载页眉和页脚以及一堆CSS
when I want to open the invoice, I don't want to open the template, just invoice.php 当我想打开发票时,我不想打开模板,只需打开invoice.php
so I created this: 所以我创建了这个:
public function invoice_print() {
$data = array();
$data['company'] = 'test';
$this->load->view('invoice.php', $data);
}
when I open the page I get a error: 当我打开页面时出现错误:
A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: views/invoice.php Line Number: 16
遇到PHP错误严重性:注意消息:未定义的变量:数据文件名:views / invoice.php行号:16
invoice.php line 16 = this: invoice.php第16行=此:
<p class="bold"> <?php echo $data['company']; ?> </p>
how do I fix this? 我该如何解决?
regards, 问候,
Ralph 拉尔夫
When you pass the variable to the view, you call the variable by the index: 将变量传递给视图时,可以通过索引调用变量:
$data['company'] = 'test';
$this->load->view('invoice.php', $data);
view: 视图:
<p class="bold"> <?php echo $company; ?> </p>
http://ellislab.com/codeigniter%20/user-guide/general/views.html http://ellislab.com/codeigniter%20/user-guide/general/views.html
$output = $crud->render();
$misDatos = 'Invoice details';
$output->misDatos = $misDatos;
$this->_example_output($output);
And you print $misDatos
in your VIEW. 然后在视图中打印
$misDatos
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.