我是Codeigniter的新手,我正在尝试使用pagination.我的问题是出乎意料的,因为我的分页代码完美地工作,除了URI段总是作为布尔值返回.我的代码是:
/* pagination */
$this->load->library('pagination');
$destination = $data['destination'];
$config = array();
$config["base_url"] = SEARCHHOTELS.$this->uri->segment(3);
$total_row = $this->db->get('hotel')->num_rows();
$config["total_rows"] = $total_row;
$config["per_page"] = 30;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['cur_tag_open'] = '<a class="active">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$str_links = $this->pagination->create_links();
$this->db->select('*');
if(!empty($data['destination'])){
$destination = $data['destination'];
$this->db->like('name',$destination);
$this->db->or_like('regionName',$destination);
}
$hSearch['records'] = $this->db->get('hotel',$config['per_page'],$this->uri->segment(3))->result_array();
$hSearch["links"] = explode(' ',$str_links);
/* paginationEnd */
Run Code Online (Sandbox Code Playgroud)
其中SEARCHHOTELS常数为
define('SEARCHHOTELS', SITE_URL.'search/hotels/');
Run Code Online (Sandbox Code Playgroud)
在我的代码中:$this->uri->segment(3)始终返回布尔值.
当我点击我的分页时,URL值会改变:
http://localhost/holidays/search/hotels/
Run Code Online (Sandbox Code Playgroud)
至:
http://localhost/holidays/search/hotels/1 (or 2,3,4)
Run Code Online (Sandbox Code Playgroud)
URI段未设置偏移我的$this->db-get查询中的值.# …
我的用户表中有三种不同类型的用户,每次成功完全登录后,每个特定类型的用户需要根据用户表中分配的角色重定向到特定页面我阅读文档并尝试了不同的方法,如redirectTo受保护的属性.但他们不适合我.
如果有任何人有更好的解决方案来解决这个问题请分享.
注意:请不要提供路线解决方案.
我有一些我想从数据库中获取的动态数据并将其传递给所有视图。我试图从互联网上举一些例子,但它们似乎在我的情况下不起作用
public function boot(){}
Run Code Online (Sandbox Code Playgroud)
我无法对其进行数据库查询,只能传递硬编码值。我尝试过的另一种方法是使用基本控制器,但是在访问变量时视图给了我错误
$query = DB::table('users')->first();
\View::share('user', $query);
Run Code Online (Sandbox Code Playgroud)
任何人都有基于 BaseController 的解决方案将不胜感激,如果我错过了什么请提醒我