Codeigniter 3.0 相关文档 part one
分页配置项
相关工具
google搜索"codeigniter generator",会有几个自动化的工具
http://crudigniter.com/
https://bitbucket.org/harviacode/codeigniter-crud-generator
增加全局变量
config/constants.php
增加站点配置项
在config目录下新建site_settings.php,在里面添加配置项:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['site_name'] = 'site name goes heere';
$config['site_description'] = 'site description';
$config['author'] = 'matt';
$config['author_site'] = 'matt';
在controller里加载配置并调用配置项
$this->config->load('site_settings',TRUE);
$site_name = $this->config->item('site_name');
如果你在使用 $this->config->load 方法时使用了第二个参数,每个配置文件中的配置 被存储到以该配置文件名为索引的数组中,要获取该配置项,你可以将 $this->config->item() 方法的第二个参数设置为这个索引名(也就是配置文件名)。
Config Class
增加全局函数
如果是系统层面已有,做补充的,可以在system/helpers/xxx_helper.php添加
如果是完全自定义的,可以application/helpers/添加
记得在autoload.php里引入
$autoload['helpers'] = array('your-global-function-file.php');
全字段查询工具
https://datatables.net/examples/api/
为当前链接添加active样式
增加一个menu_helper的工具
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
if(!function_exists('active_link')) {
function activate_menu($controller) {
// Getting CI class instance.
$CI = get_instance();
// Getting router class to active.
$class = $CI->router->fetch_class();
return ($class == $controller) ? 'active' : '';
}
}
在链接中使用
<li class="<?php echo activate_menu('login'); ?>">
<?php echo anchor('login', 'Login'); ?>
</li>
参考资料
http://stackoverflow.com/questions/10831213/where-to-place-global-functions-in-codeigniter
http://codeigniter.org.cn/user_guide/general/index.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述