Как установить character_limiter () в Codeigniter

Я новичок в 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); 

http://ellislab.com/codeigniter/user-guide/helpers/text_helper.html

Вы должны импортировать Text Helper

в вашем контроллере, это хорошая практика для загрузки хелпера, моделей и библиотек в конструктор

 function __construct() { parent::__construct(); $this->load->helper('text'); $this->load->model('products_model'); //name of your model class } function index() { $data['products']=$this->products_model->selectAllProduct(); $this->load->view('index',$data); } 

на ваш взгляд index.php

 //This is an example from CI's home page //$string = "Here is a nice text string consisting of eleven words."; //$string = word_limiter($string, 4); foreach($products as $p) { $limited_word = word_limiter($p[product_title],25); echo $limited_word; }