I'm new to Codeigniter. Now I want to set the character limit in the view. First, get the data from the database with $query_result->result(), and then show it in the view using foreach().
Here is my Controller, Model and View:
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);
}
And my Model:
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;
}
And I want to set the character limit in the View:
http://russelstore.mastersite.info echo character_limiter($result->product_title, 25);
First Load the helper class in either
autoload.php
or in thecontroller
class.For Global use , write in
Autoload.php
:OR If you want to use only in one
controller.php
class then:Then in your
view.php
:http://ellislab.com/codeigniter/user-guide/helpers/text_helper.html
You should import Text Helper
in your controller, it is a good practice to load helper, models and libraries in a constructor
at your view index.php
you can use my code there