PHP codeigniter 变量未传递给 View

标签 php codeigniter

function create()
{
    $data['headline'] =" ";
    $this->load->module('site_security');
    $this->site_security->_make_sure_is_admin();

    $update_id = $this->uri->segment(3); 

    if(!is_numeric($update_id))
    {
        $data['headline'] = "Add New Product";
        //$data['headline'] = print_r($update_id)."if";
    }

    else
    {
        $data['headine'] = "Update Product Details";
        //$data['headline'] = print_r($update_id)."else";
    }

    $data['view_module'] = "store_products"; //passing module name 
    $data['view_file'] = "create";  //passing method name
    $this->load->module('templates'); // loads the template module
    $this->templates->admin($data); //calls the template controller method admin which loads the admin view

}

我正在传递标题文本以根据 url 中第三段的内容更改 View 中的标题。第一个 if 语句完美地设置了标题,但它不会进入 else 语句并且给我错误,因为 $headline 在 View 中未定义。奇怪的是,如果我使用注释的 print_r 语句,一切都会完美地显示在 View 中。

我认为它必须是行 $data['headine'] = "Update Product Details";在其他方面,但我不知道为什么。

最佳答案

在你的 else 语句中,

 else
 {
     $data['headine'] = "Update Product Details";
 }

这里有错别字。将 headine 更改为 headline

关于PHP codeigniter 变量未传递给 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40814100/

相关文章:

javascript - ajax从mysql加载数据

php - codeigniter where 子句中的数据库内置函数调用

codeigniter - 在Codeigniter中,如何将第三个参数传递给回调(表单验证)?

php - 使用多个 WHERE 子句在 Codeigniter 中更新批处理

javascript - Laravel/Croppie 2.6.2 : How to get output image in JPEG instead of default PNG?

php - 数组 - Orderby - 类型

php - CakePHP/mysql : select found_rows can't run in a loop?

php - 加入codeigniter

php - Controller 中的 Codeigniter 负载模型

php - 使用内部连接删除行