Php codeigniter中脚本的最佳方式
在CodeIgniter中,我的项目通常有许多固有的脚本,例如:Php codeigniter中脚本的最佳方式,php,codeigniter,scripting,Php,Codeigniter,Scripting,在CodeIgniter中,我的项目通常有许多固有的脚本,例如: <?php // Load many things $this->load->model('news_model'); $this->load->helper('utility_helper'); $news = $this->news_model->get_basic_news(); // For moment no news $view_datas['news']['che
<?php
// Load many things
$this->load->model('news_model');
$this->load->helper('utility_helper');
$news = $this->news_model->get_basic_news();
// For moment no news
$view_datas['news']['check'] = false;
if ($news) {
$view_datas['news'] = array(
'check' => true,
'news' => _humanize_news($news)
);
}
?>
只需创建一个新库,并根据需要加载该库即可? e、 g
或者另一个想法是创建助手函数。只需创建一个新库,并根据需要加载该库即可? e、 g
或者另一个想法是创建助手函数。我通常制作这些助手。。并将其包含在Autolodi中,通常使这些助手。。将它们包含在autoloadYes中这是一个解决方案,可以将所有的脚本都放在一个
类中,但是想象一下我有15/16个脚本,所以16个方法,对于speed exec来说是不可行的……还有一件事,如果我创建类或助手来实现这一点,通常我会加载许多模型或助手,所以解决方案是创建一个$CI=&get_instance()代码>以超级对象CI为例,这种方式很慢。我使用Codeigniter是因为我喜欢更快的执行时间,但我认为我们有一个问题…是的,这是一个解决方案,将所有的脚本都放在脚本类中,但是想象一下我有15/16个脚本,所以16个方法,对于speed exec来说是不可行的…还有一件事,如果我创建类或助手来实现这一点,通常我加载许多模型或助手,因此解决方案是创建一个$CI=&get_instance()代码>以超级对象CI为例,这种方式很慢。我使用Codeigniter是因为我喜欢更快的执行时间,但我认为我们有一个问题。。。
class Scripts {
public function last_news() {
// Load many things to use
$CI =& get_instance();
$CI->load->model('news_model');
$CI->load->model('utility_helper');
$news = $CI->news_model->get_basic_news();
// Avoid the rest of code
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Newclass {
public function get_news($limit)
{
//return news
}
}
/* End of file Newsclass.php */
$this->load->library('newsclass');
$this->newsclass->get_news($limit);