我是Codeigniter的新手 . 现在我想在视图中设置字符限制 . 首先,使用$ query_result-> result()从数据库中获取数据,然后使用foreach()在视图中显示它 .
这是我的控制器,模型和视图:
public function index() {
$data = array();
$data['category'] = $this->product_model->selectAllcategory();
$data['randProduct'] = $this->product_model->selectRandomProduct();
$data['products'] = $this->product_model->selectAllProduct();
$data['maincontent'] = $this->load->view('home', $data, true);
$data['title'] = 'Welcome Russel Store';
$this->load->view('index', $data);
}
而我的模特:
public function selectAllProduct() {
$this->db->select('*');
$this->db->from('product');
$this->db->where('status', 1);
$this->db->order_by('product_id', 'desc');
$query_result = $this->db->get();
$result = $query_result->result();
return $result;
}
我想在视图中设置字符限制:
http://russelstore.mastersite.info
echo character_limiter($result->product_title, 25);
2 回答
http://ellislab.com/codeigniter/user-guide/helpers/text_helper.html
你应该导入 Text Helper
在您的控制器中,在 a constructor 中加载帮助程序,模型和库是一个好习惯 .
在你的视图index.php
你可以在那里使用我的代码