php - Best way for scripts in codeigniter -
in codeigniter many scripts inherent of project, example
<?php // illustration of script stackoverflow // load many things $this->load->model('news_model'); $this->load->helper('utility_helper'); $news = $this->news_model->get_basic_news(); // moment no news $view_datas['news']['check'] = false; if ($news) { $view_datas['news'] = array( 'check' => true, 'news' => _humanize_news($news) ); } ?>
this script utilize in different controllers, moment create scripts
folder , create include(apppath . 'scripts/last_news.php');
think not best way this. have got thought ?
edit :
a solution answers utilize helper
or library
imagine older code way :
class scripts { public function last_news() { // load many things utilize $ci =& get_instance(); $ci->load->model('news_model'); $ci->load->model('utility_helper'); $news = $ci->news_model->get_basic_news(); // avoid rest of code } }
so must create get_instance(), ... load super object ci slow (juste create var_dump()
of fun), solution ? help !
just create new library , load library whereever require? e.g.
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class newclass { public function get_news($limit) { //return news } } /* end of file newsclass.php */
in controllers
$this->load->library('newsclass'); $this->newsclass->get_news($limit);
or thought create helper functions.
php codeigniter scripting
No comments:
Post a Comment