Undefined Variable error in View

孤街醉人 提交于 2019-12-11 10:13:52

问题


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'/>

which i receive it in controller as,

$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 works but not $query. But i'm NOT saving the $query to the database. so, i cant use $data['query'] as well. totally confused.


回答1:


$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);

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



来源:https://stackoverflow.com/questions/13597031/undefined-variable-error-in-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!