视图中的未定义变量错误 [英] Undefined Variable error in View

查看:64
本文介绍了视图中的未定义变量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器出现以下问题:
如何向其中添加分页

My controller is in this question: how to add pagination to this

但是现在,我在视图中得到的是未定义变量,
视图中有输入

But now, i'm getting undefined variable in my view, View has an input

<input name='query'/>

我在控制器中收到它,

$query = $this->input->get('query'); 

现在,我试图将相同的查询字符串传递回我的
内部视图中分页链接。

Now, i am trying to pass the same query string back into my view inside the link of pagination.

<a href="<php echo base_url(); ?>main/search/query=<?php echo $query; ?>&off=<?php echo $off=5;">1</a>

$ off 有效但 $ query 。但我没有将 $ query 保存到数据库。
因此,我也不能使用 $ data [’query']

$off works but not $query. But i'm NOT saving the $query to the database. so, i cant use $data['query'] as well. totally confused.

推荐答案

$ off不会抛出错误,因为您正在为其分配整数5。

$off is not throwing an error because you are assigning the integer 5 to it.

您需要通过将数据粘贴到

You need to pass data to the view from inside the controller by sticking it in an array like

 $data['query']= $query;
 $this->load->view('myview', $data);

然后$ query可用于视图。不知道为什么你不能这么做

Then $query is available to the view. Not sure why you say you can't do this

这篇关于视图中的未定义变量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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