代码点火器数据传递控制器->库->视图 [英] codeigniter data passing controller->library->view

查看:50
本文介绍了代码点火器数据传递控制器->库->视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码点火器问题。我试图将数据从控制器发送到库,然后发送到视图。

I have a codeigniter problem. Im trying to send data from a controller , to a library , to a view.

我在视图中收到此错误:

i get this error in the view:

Message: Undefined variable: crimes

FileName :views / crime_view.php

FileName: views/crime_view.php

行:45

在调试时,我转储$ data变量,然后得到:

while debugging , i dump the $data variable, and get:

表示我的变量存在

在库中,通过使用以下命令获取控制器数据:

in the library , im getting the controller data by using:

$data[] = $componentData; 

在这种情况下不起作用。但是如果我在图书馆里这样做:

that would not work in this case. but if i in the library do:

$data['crimes'] = "test";

然后它将起作用。出于某种原因,它将无法处理来自控制器的传入数组。

then it will work. for some reason it wont process the incomming arrays from the controller.

我如何使其工作?

完整代码:

    function renderComponent($componentData = array())   
    {
        $data[] = $componentData; // stores controller variables.
        $data['rankDetails'] = $this->CI->user->rank_for_xp($userId);

        var_dump($data);

        $this->CI->load->view('components/crime/views/crime_view', $data);
    }

来自控制器的示例:

example from the controller:

问:如何解决此问题以使其传递所需的变量?这样我就可以在视图中使用$ wait变量了?

Q: How can i fix this to get it passing the variables needed? so i acually can get to use the $wait variable in the view?

推荐答案

您有一个二维数组。

我认为某个地方 $ data [] = ... 必须是 $ data = ...

I think somewhere $data[] = ... must be $data = ...

要调试阵列,您可以这样做:

to debug your arrays you could do like this:

echo '<pre>';
print_r($data);
echo '</pre>';

这清楚地表明您的数组在另一个数组中。

This shows clearly that your array is in another array...

这篇关于代码点火器数据传递控制器->库->视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆