- Create your library, example “sample.php”
- Load your library in controller
- So, call function library in your views.
defined('BASEPATH') OR exit('No direct script access allowed'); class Sample { protected $ci; public function __construct() { $this->ci =& get_instance(); } public function debug($id) { $table = $this->ci->db->get_where('table', array('id' => $id))->num_rows(); if (empty($table)) { $result = 'table is empty'; } else { $result = $table; } return $result; } }
defined('BASEPATH') OR exit('No direct script access allowed'); class Testing extends READY_Controller { public $page = 'Training'; public function __construct() { parent::__construct(); //Load Dependencies $this->load->library('sample'); } public function index() { $data['result'] = $this->db->get('table')->result(); $this->load->view('sampleView', $data); } }
foreach ($result as $row) { echo $this->sample->debug($row->id) . “\n\n\n”; }
No comments:
Post a Comment