【发布时间】:2013-04-17 01:14:08
【问题描述】:
我是 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);【问题讨论】:
-
character_limiter() 应该可以做到这一点。我对你的问题感到困惑。
-
@Ebrahim,在为 StackOverflow 格式化代码时,您不需要
标签或反引号。只需将所有行缩进四个空格。谢谢。
标签: php codeigniter character