douda5227 2013-11-25 15:27
浏览 9
已采纳

codeigniter / groceryCRUD发送数据以查看不工作

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

when I want to open the invoice, I don't want to open the template, just 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

invoice.php line 16 = this:

<p class="bold"> <?php echo $data['company']; ?> </p>

how do I fix this?

regards,

Ralph

  • 写回答

2条回答 默认 最新

  • douao2000 2013-11-25 15:30
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 nrf52810-c三个a 程序
  • ¥15 lego-loam跑出来的roll误差很大
  • ¥50 求一个半透明没有锯齿的圆角窗体的实现例子
  • ¥15 STM32cubeMX里的FreeRTOS无法释放内存
  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对