├── cilexer ├── cilexer │ ├── __init__.py │ └── cilexer.py ├── setup.py └── README ├── source ├── images │ ├── file.gif │ ├── arrow.gif │ ├── folder.gif │ ├── smile.gif │ ├── ci-icon.ico │ ├── ci_logo.jpg │ ├── appflowchart.gif │ └── ci_logo_flame.jpg ├── libraries │ ├── index.rst │ ├── typography.rst │ └── benchmark.rst ├── helpers │ ├── index.rst │ ├── language_helper.rst │ ├── xml_helper.rst │ ├── download_helper.rst │ ├── number_helper.rst │ ├── path_helper.rst │ ├── email_helper.rst │ ├── typography_helper.rst │ ├── directory_helper.rst │ ├── inflector_helper.rst │ ├── security_helper.rst │ ├── cookie_helper.rst │ ├── array_helper.rst │ ├── smiley_helper.rst │ └── captcha_helper.rst ├── documentation │ └── ELDocs.tmbundle.zip ├── _themes │ └── sphinx_rtd_theme │ │ ├── static │ │ ├── fonts │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ ├── 1YwB1sO8YE1Lyjf12WNiUA.woff2 │ │ │ ├── H2DMvhDLycM56KNuAtbJYA.woff2 │ │ │ ├── PLygLKRVCQnA5fhu3qk5fQ.woff2 │ │ │ ├── UyBMtLsHKBKXelqf4x7VRQ.woff2 │ │ │ ├── AIed271kqQlcIRSOnQH0yYlIZu-HDpmDIZMigmsroc4.woff2 │ │ │ ├── AIed271kqQlcIRSOnQH0yejkDdvhIIFj_YMdgqpnSB0.woff2 │ │ │ ├── AcvTq8Q0lyKKNxRlL28RnxJtnKITppOI_IvcXXDNrsc.woff2 │ │ │ ├── BjAYBlHtW3CJxDcjzrnZCCYE0-AqJ3nfInTTiDXDjU4.woff2 │ │ │ ├── BjAYBlHtW3CJxDcjzrnZCI4P5ICox8Kq3LLUNMylGO4.woff2 │ │ │ ├── HkF_qI1x_noxlxhrhMQYEFtXRa8TVwTICgirnJhmVJw.woff2 │ │ │ ├── ObQr5XYcoH0WBoUxiaYK3_Y6323mHUZFJMgTvxaG2iE.woff2 │ │ │ ├── YMOYVM-eg6Qs9YzV9OSqZfesZW2xOQ-xsNqO47m55DA.woff2 │ │ │ ├── dazS1PrQQuCxC3iOAJFEJQalQocB-__pDVGhF3uS2Ks.woff2 │ │ │ ├── dazS1PrQQuCxC3iOAJFEJSFaMxiho_5XQnyRZzQsrZs.woff2 │ │ │ ├── dazS1PrQQuCxC3iOAJFEJS_vZmeiCMnoWNN9rHBYaTc.woff2 │ │ │ ├── dazS1PrQQuCxC3iOAJFEJWhQUTDJGru-0vvUpABgH8I.woff2 │ │ │ ├── dazS1PrQQuCxC3iOAJFEJYlIZu-HDpmDIZMigmsroc4.woff2 │ │ │ ├── dazS1PrQQuCxC3iOAJFEJZ6iIh_FvlUHQwED9Yt5Kbw.woff2 │ │ │ ├── dazS1PrQQuCxC3iOAJFEJejkDdvhIIFj_YMdgqpnSB0.woff2 │ │ │ ├── y7lebkjgREBJK96VQi37ZiYE0-AqJ3nfInTTiDXDjU4.woff2 │ │ │ ├── y7lebkjgREBJK96VQi37ZjTOQ_MqJVwkKsUn0wKzc2I.woff2 │ │ │ ├── y7lebkjgREBJK96VQi37ZjUj_cnvWIuuBMVgbX098Mw.woff2 │ │ │ ├── y7lebkjgREBJK96VQi37ZkbcKLIaa1LC45dFaAfauRA.woff2 │ │ │ ├── y7lebkjgREBJK96VQi37Zmo_sUJ8uO4YLWRInS22T3Y.woff2 │ │ │ ├── y7lebkjgREBJK96VQi37Zo4P5ICox8Kq3LLUNMylGO4.woff2 │ │ │ └── y7lebkjgREBJK96VQi37Zr6up8jxqWt8HVA3mDhkV_0.woff2 │ │ ├── css │ │ │ ├── theme_cn.css │ │ │ └── badge_only.css │ │ └── js │ │ │ └── oldtheme.js │ │ ├── theme.conf │ │ ├── searchbox.html │ │ ├── __init__.py │ │ ├── breadcrumbs.html │ │ ├── LICENSE │ │ ├── versions.html │ │ ├── search.html │ │ └── footer.html ├── overview │ ├── index.rst │ ├── appflow.rst │ ├── getting_started.rst │ ├── mvc.rst │ ├── goals.rst │ ├── features.rst │ └── at_a_glance.rst ├── installation │ ├── troubleshooting.rst │ ├── upgrade_214.rst │ ├── upgrade_221.rst │ ├── upgrade_120.rst │ ├── upgrade_212.rst │ ├── upgrade_213.rst │ ├── upgrade_161.rst │ ├── upgrade_163.rst │ ├── upgrade_171.rst │ ├── upgrade_210.rst │ ├── upgrade_220.rst │ ├── upgrade_153.rst │ ├── upgrade_132.rst │ ├── upgrade_131.rst │ ├── upgrade_211.rst │ ├── downloads.rst │ ├── upgrade_202.rst │ ├── upgrading.rst │ ├── upgrade_162.rst │ ├── index.rst │ ├── upgrade_152.rst │ ├── upgrade_172.rst │ ├── upgrade_133.rst │ ├── upgrade_201.rst │ ├── upgrade_154.rst │ ├── upgrade_170.rst │ ├── upgrade_160.rst │ ├── upgrade_203.rst │ ├── upgrade_140.rst │ ├── upgrade_141.rst │ ├── upgrade_b11.rst │ ├── upgrade_150.rst │ └── upgrade_130.rst ├── general │ ├── index.rst │ ├── welcome.rst │ ├── credits.rst │ ├── libraries.rst │ ├── requirements.rst │ ├── autoloader.rst │ ├── drivers.rst │ ├── creating_drivers.rst │ ├── environments.rst │ ├── caching.rst │ ├── managing_apps.rst │ ├── alternative_php.rst │ ├── cli.rst │ ├── ancillary_classes.rst │ ├── reserved_names.rst │ ├── urls.rst │ ├── core_classes.rst │ ├── profiling.rst │ ├── errors.rst │ ├── hooks.rst │ ├── helpers.rst │ ├── models.rst │ ├── views.rst │ ├── security.rst │ └── routing.rst ├── database │ ├── index.rst │ ├── call_function.rst │ ├── helpers.rst │ ├── metadata.rst │ ├── transactions.rst │ ├── examples.rst │ ├── connecting.rst │ ├── caching.rst │ └── queries.rst ├── tutorial │ ├── conclusion.rst │ ├── index.rst │ ├── static_pages.rst │ └── create_news_items.rst ├── DCO.rst ├── license.rst ├── index.rst └── contributing │ └── index.rst ├── .travis.yml └── README.rst /cilexer/cilexer/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /source/images/file.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/file.gif -------------------------------------------------------------------------------- /source/images/arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/arrow.gif -------------------------------------------------------------------------------- /source/images/folder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/folder.gif -------------------------------------------------------------------------------- /source/images/smile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/smile.gif -------------------------------------------------------------------------------- /source/images/ci-icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/ci-icon.ico -------------------------------------------------------------------------------- /source/images/ci_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/ci_logo.jpg -------------------------------------------------------------------------------- /source/images/appflowchart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/appflowchart.gif -------------------------------------------------------------------------------- /source/images/ci_logo_flame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/images/ci_logo_flame.jpg -------------------------------------------------------------------------------- /source/libraries/index.rst: -------------------------------------------------------------------------------- 1 | ########## 2 | 类库参考 3 | ########## 4 | 5 | .. toctree:: 6 | :glob: 7 | :titlesonly: 8 | 9 | * -------------------------------------------------------------------------------- /source/helpers/index.rst: -------------------------------------------------------------------------------- 1 | ############## 2 | 辅助类库参考 3 | ############## 4 | 5 | .. toctree:: 6 | :glob: 7 | :titlesonly: 8 | 9 | * -------------------------------------------------------------------------------- /source/documentation/ELDocs.tmbundle.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/documentation/ELDocs.tmbundle.zip -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = css/theme.css 4 | 5 | [options] 6 | typekit_id = hiw1hhg 7 | analytics_id = 8 | sticky_navigation = False 9 | -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/1YwB1sO8YE1Lyjf12WNiUA.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/1YwB1sO8YE1Lyjf12WNiUA.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/H2DMvhDLycM56KNuAtbJYA.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/H2DMvhDLycM56KNuAtbJYA.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/PLygLKRVCQnA5fhu3qk5fQ.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/PLygLKRVCQnA5fhu3qk5fQ.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/UyBMtLsHKBKXelqf4x7VRQ.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/UyBMtLsHKBKXelqf4x7VRQ.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yYlIZu-HDpmDIZMigmsroc4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yYlIZu-HDpmDIZMigmsroc4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yejkDdvhIIFj_YMdgqpnSB0.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yejkDdvhIIFj_YMdgqpnSB0.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/AcvTq8Q0lyKKNxRlL28RnxJtnKITppOI_IvcXXDNrsc.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/AcvTq8Q0lyKKNxRlL28RnxJtnKITppOI_IvcXXDNrsc.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCCYE0-AqJ3nfInTTiDXDjU4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCCYE0-AqJ3nfInTTiDXDjU4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCI4P5ICox8Kq3LLUNMylGO4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCI4P5ICox8Kq3LLUNMylGO4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/HkF_qI1x_noxlxhrhMQYEFtXRa8TVwTICgirnJhmVJw.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/HkF_qI1x_noxlxhrhMQYEFtXRa8TVwTICgirnJhmVJw.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/ObQr5XYcoH0WBoUxiaYK3_Y6323mHUZFJMgTvxaG2iE.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/ObQr5XYcoH0WBoUxiaYK3_Y6323mHUZFJMgTvxaG2iE.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/YMOYVM-eg6Qs9YzV9OSqZfesZW2xOQ-xsNqO47m55DA.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/YMOYVM-eg6Qs9YzV9OSqZfesZW2xOQ-xsNqO47m55DA.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJQalQocB-__pDVGhF3uS2Ks.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJQalQocB-__pDVGhF3uS2Ks.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJSFaMxiho_5XQnyRZzQsrZs.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJSFaMxiho_5XQnyRZzQsrZs.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJS_vZmeiCMnoWNN9rHBYaTc.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJS_vZmeiCMnoWNN9rHBYaTc.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJWhQUTDJGru-0vvUpABgH8I.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJWhQUTDJGru-0vvUpABgH8I.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJYlIZu-HDpmDIZMigmsroc4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJYlIZu-HDpmDIZMigmsroc4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJZ6iIh_FvlUHQwED9Yt5Kbw.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJZ6iIh_FvlUHQwED9Yt5Kbw.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJejkDdvhIIFj_YMdgqpnSB0.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJejkDdvhIIFj_YMdgqpnSB0.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZiYE0-AqJ3nfInTTiDXDjU4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZiYE0-AqJ3nfInTTiDXDjU4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjTOQ_MqJVwkKsUn0wKzc2I.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjTOQ_MqJVwkKsUn0wKzc2I.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjUj_cnvWIuuBMVgbX098Mw.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjUj_cnvWIuuBMVgbX098Mw.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZkbcKLIaa1LC45dFaAfauRA.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZkbcKLIaa1LC45dFaAfauRA.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zmo_sUJ8uO4YLWRInS22T3Y.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zmo_sUJ8uO4YLWRInS22T3Y.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zo4P5ICox8Kq3LLUNMylGO4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zo4P5ICox8Kq3LLUNMylGO4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zr6up8jxqWt8HVA3mDhkV_0.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneasystone/ci-doc-chinese/master/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zr6up8jxqWt8HVA3mDhkV_0.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/css/theme_cn.css: -------------------------------------------------------------------------------- 1 | .rst-footer-buttons .fa-arrow-circle-left { 2 | margin-right: 5px; 3 | } 4 | 5 | .rst-footer-buttons .fa-arrow-circle-right { 6 | margin-left: 5px; 7 | } 8 | 9 | #notes { 10 | margin-top: 40px; 11 | margin-bottom: 40px; 12 | } -------------------------------------------------------------------------------- /source/overview/index.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | CodeIgniter 概览 3 | #################### 4 | 5 | 以下内容大概的介绍了什么是 CodeIgniter,帮你快速的了解 CodeIgniter: 6 | 7 | .. toctree:: 8 | :titlesonly: 9 | 10 | 开始 11 | CodeIgniter 是什么? 12 | 支持特性 13 | 应用程序流程图 14 | 模型 - 视图 - 控制器 15 | 架构目标 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/searchbox.html: -------------------------------------------------------------------------------- 1 | {%- if builder != 'singlehtml' %} 2 |
3 |
4 | 5 | 6 | 7 |
8 |
9 | {%- endif %} 10 | -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/__init__.py: -------------------------------------------------------------------------------- 1 | """Sphinx ReadTheDocs theme. 2 | 3 | From https://github.com/ryan-roemer/sphinx-bootstrap-theme. 4 | 5 | """ 6 | import os 7 | 8 | VERSION = (0, 1, 5) 9 | 10 | __version__ = ".".join(str(v) for v in VERSION) 11 | __version_full__ = __version__ 12 | 13 | 14 | def get_html_theme_path(): 15 | """Return list of HTML theme paths.""" 16 | cur_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 17 | return cur_dir 18 | -------------------------------------------------------------------------------- /source/overview/appflow.rst: -------------------------------------------------------------------------------- 1 | ###################### 2 | 应用程序流程图 3 | ###################### 4 | 5 | 下图说明了整个系统的数据流程: 6 | 7 | |CodeIgniter 程序流程| 8 | 9 | #. index.php 文件作为前端控制器,初始化运行 CodeIgniter 所需的基本资源; 10 | #. Router 检查 HTTP 请求,以确定如何处理该请求; 11 | #. 如果存在缓存文件,将直接输出到浏览器,不用走下面正常的系统流程; 12 | #. 在加载应用程序控制器之前,对 HTTP 请求以及任何用户提交的数据进行安全检查; 13 | #. 控制器加载模型、核心类库、辅助函数以及其他所有处理请求所需的资源; 14 | #. 最后一步,渲染视图并发送至浏览器,如果开启了缓存,视图被会先缓存起来用于 15 | 后续的请求。 16 | 17 | .. |CodeIgniter 程序流程| image:: ../images/appflowchart.gif 18 | -------------------------------------------------------------------------------- /source/installation/troubleshooting.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | 疑难解答 3 | ############### 4 | 5 | 如果你发现无论你输入什么 URL 都只能显示默认页,那么可能是你的服务器 6 | 不支持 REQUEST_URI 变量,该变量用来提供搜索引擎友好的 URL 。 7 | 解决这个问题的第一步是打开 application/config/config.php 文件,找到 8 | URI Protocol 信息,根据注释提示,该值可以有几种不同的设置方式,你可以 9 | 逐个尝试一下。 10 | 如果还是不起作用,你需要让 CodeIgniter 强制在你的 URL 中添加一个问号, 11 | 要做到这点,你可以打开 **application/config/config.php** 文件,然后 12 | 将下面的代码:: 13 | 14 | $config['index_page'] = "index.php"; 15 | 16 | 修改为这样:: 17 | 18 | $config['index_page'] = "index.php?"; 19 | -------------------------------------------------------------------------------- /source/installation/upgrade_214.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.1.3 to 2.1.4 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder. 12 | 13 | .. note:: If you have any custom developed files in these folders please 14 | make copies of them first. -------------------------------------------------------------------------------- /source/installation/upgrade_221.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.2.0 to 2.2.1 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder. 12 | 13 | .. note:: If you have any custom developed files in these folders please 14 | make copies of them first. -------------------------------------------------------------------------------- /source/general/index.rst: -------------------------------------------------------------------------------- 1 | ############## 2 | 常规主题 3 | ############## 4 | 5 | .. toctree:: 6 | :titlesonly: 7 | 8 | urls 9 | controllers 10 | reserved_names 11 | views 12 | models 13 | helpers 14 | libraries 15 | creating_libraries 16 | drivers 17 | creating_drivers 18 | core_classes 19 | ancillary_classes 20 | hooks 21 | autoloader 22 | common_functions 23 | compatibility_functions 24 | routing 25 | errors 26 | caching 27 | profiling 28 | cli 29 | managing_apps 30 | environments 31 | alternative_php 32 | security 33 | styleguide -------------------------------------------------------------------------------- /cilexer/setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | Install and setup CodeIgniter highlighting for Pygments. 3 | """ 4 | 5 | from setuptools import setup 6 | 7 | entry_points = """ 8 | [pygments.lexers] 9 | cilexer = cilexer.cilexer:CodeIgniterLexer 10 | """ 11 | 12 | setup( 13 | name='pycilexer', 14 | version='0.1', 15 | description=__doc__, 16 | author="EllisLab, Inc.", 17 | packages=['cilexer'], 18 | install_requires=( 19 | 'sphinx >= 1.0.7', 20 | 'sphinxcontrib-phpdomain >= 0.1.3-1' 21 | ), 22 | entry_points=entry_points 23 | ) 24 | -------------------------------------------------------------------------------- /source/database/index.rst: -------------------------------------------------------------------------------- 1 | ################## 2 | 数据库参考 3 | ################## 4 | 5 | CodeIgniter 内置了一个快速强大的数据库抽象类,支持传统的查询架构以及查询构造器模式。 6 | 数据库方法的语法简单明了。 7 | 8 | .. toctree:: 9 | :titlesonly: 10 | 11 | 数据库快速入门: 示例代码 12 | 数据库配置 13 | 连接数据库 14 | 查询 15 | 生成查询结果 16 | 查询辅助函数 17 | 查询构造器类 18 | 事务 19 | 获取元数据 20 | 自定义函数调用 21 | 查询缓存 22 | 使用 Database Forge 维护数据库 23 | 数据库工具类 24 | 数据库驱动器参考 25 | -------------------------------------------------------------------------------- /source/installation/upgrade_120.rst: -------------------------------------------------------------------------------- 1 | #################################### 2 | Upgrading From Beta 1.0 to Final 1.2 3 | #################################### 4 | 5 | To upgrade to Version 1.2 please replace the following directories with 6 | the new versions: 7 | 8 | .. note:: If you have any custom developed files in these folders please 9 | make copies of them first. 10 | 11 | - drivers 12 | - helpers 13 | - init 14 | - language 15 | - libraries 16 | - plugins 17 | - scaffolding 18 | 19 | Please also replace your local copy of the user guide with the new 20 | version. 21 | -------------------------------------------------------------------------------- /source/overview/getting_started.rst: -------------------------------------------------------------------------------- 1 | ################################ 2 | 开始学习 CodeIgniter 3 | ################################ 4 | 5 | 任何应用程序的学习都需要花费一定的精力。我们尽自己最大的努力使大家在学习中少走弯路,并且充满乐趣。 6 | 7 | 第一步就是 :doc:`安装 <../installation/index>` CodeIgniter,然后阅读目录中 **介绍部分** 的所有主题。 8 | 9 | 接下来,按顺序阅读 **常规主题** 里面的每一篇内容,那里每一篇的内容都是承接前一篇的, 10 | 并且提供了样例代码,你可以尝试一下。 11 | 12 | 一旦你掌握了这些基础概念,你就可以去看看 **类库参考** 和 **辅助函数参考**, 13 | 去学习如何使用 CodeIgniter 原生的类库和辅助函数文件。 14 | 15 | 如果遇到了问题可以到我们的 `开发者社区 `_ 寻找解答,另外, 16 | 也可以去我们的 `维基页面 `_,里面有其他用户分享的例子代码。 -------------------------------------------------------------------------------- /source/overview/mvc.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | 模型-视图-控制器 3 | ######################### 4 | 5 | CodeIgniter 的开发基于 MVC(模型-视图-控制器)设计模式。MVC 是一种 6 | 用于将应用程序的逻辑层和表现层分离出来的软件方法。在实践中,由于这种分离 7 | 所以你的页面中只包含很少的 PHP 脚本。 8 | 9 | - **模型** 代表你的数据结构。通常来说,模型类将包含帮助你对数据库进行增删改查的方法。 10 | - **视图** 是要展现给用户的信息。一个视图通常就是一个网页,但是在 CodeIgniter 中, 11 | 一个视图也可以是一部分页面(譬如页头、页尾),它也可以是一个 RSS 页面, 12 | 或其他任何类型的页面。 13 | - **控制器** 是模型、视图以及其他任何处理 HTTP 请求所必须的资源之间的中介,并生成网页。 14 | 15 | CodeIgniter 在 MVC 使用上非常宽松,因为模型不是必需的。如果你不需要使用模型这一层,或是 16 | 认为维护模型比你想象中的复杂很多,那么你可以忽略它,而只使用控制器和视图创建你的应用程序。 17 | CodeIgniter 可以让你直接调用你现有的脚本,甚至你也可以为系统开发核心类,总之, 18 | CodeIgniter 让你以你感觉最舒适的方式进行开发。 19 | -------------------------------------------------------------------------------- /source/general/welcome.rst: -------------------------------------------------------------------------------- 1 | ###################### 2 | 欢迎使用 CodeIgniter 3 | ###################### 4 | 5 | CodeIgniter 是一套给 PHP 网站开发者使用的应用程序开发框架和工具包。 6 | 它的目标是让你能够更快速的开发,它提供了日常任务中所需的大量类库, 7 | 以及简单的接口和逻辑结构。通过减少代码量,CodeIgniter 让你更加专注 8 | 于你的创造性工作。 9 | 10 | ******************************** 11 | CodeIgniter 是为谁准备的? 12 | ******************************** 13 | 14 | CodeIgniter 就是你所需要的,如果... 15 | 16 | - 你想要一个小巧的框架; 17 | - 你需要出色的性能; 18 | - 你需要广泛兼容标准主机上的各种 PHP 版本和配置; 19 | - 你想要一个几乎零配置的框架; 20 | - 你想要一个不需使用命令行的框架; 21 | - 你想要一个不想被编码规则的条条框框限制住的框架; 22 | - 你对 PEAR 这种庞然大物不感兴趣; 23 | - 你不想被迫学习一种新的模板语言(当然如果你喜欢,你可以选择一个模板解析器); 24 | - 你不喜欢复杂,追求简单; 25 | - 你需要清晰、完整的文档。 -------------------------------------------------------------------------------- /source/tutorial/conclusion.rst: -------------------------------------------------------------------------------- 1 | ########## 2 | 结束语 3 | ########## 4 | 5 | 这篇教程可能并非如你所愿,希望能涵盖一个内容管理系统的方方面面, 6 | 但是它至少带你了解了一些最为关键的知识点,包括路由、控制器、模型 7 | 等等。我们希望这篇教程可以帮助你了解一些 CodeIgniter 的基本设计模式, 8 | 在这个基础上你可以做更为深入的研究。 9 | 10 | 现在,你已经完成了这篇教程,我们推荐你再继续看看文档的其余部分。 11 | CodeIgniter 常常以文档全面而被称赞,你应该使用这个优势,通篇阅读 12 | “概览” 和 “常规主题” 这两个部分,当你需要时查阅类库和辅助函数参考。 13 | 14 | 任何一个中级 PHP 程序员应该都可以在几天内的时间里上手 CodeIgniter。 15 | 16 | 如果你对框架或者你自己的 CodeIgniter 代码仍有疑问,你可以: 17 | 18 | - 访问我们的 `社区论坛 `_ 19 | - 或访问我们的 `IRC 聊天室 `_ 20 | - 或浏览我们的 `Wiki `_ 21 | 22 | -------------------------------------------------------------------------------- /source/general/credits.rst: -------------------------------------------------------------------------------- 1 | ####################### 2 | 关于 CodeIgniter 3 | ####################### 4 | 5 | CodeIgniter 最早是由 `Rick Ellis `_ 开发( `EllisLab 公司 `_ 的 CEO )的。这个框架为真实应用而编写,集成了很多类库,辅助 6 | 函数,以及从 `ExpressionEngine `_ 的代码中 7 | 借鉴过来的子系统。 8 | 9 | 在之前的很多年里,CodeIgniter 一直都是由 EllisLab 公司、ExpressionEngine 开发团队、 10 | 以及一群叫做 Reactor 团队的社区成员开发并维护。 11 | 12 | 2014 年,CodeIgniter 由 `不列颠哥伦比亚理工学院 `_ 接手,之后 13 | 正式宣布 CodeIgniter 成为一个由社区维护的项目。 14 | 15 | CodeIgniter 的最新发展是由 Reactor 团队中的一部分精英带头推动的。 16 | 17 | 来自 Ruby on Rails 的灵感启发我们去开发一个 PHP 框架,然后将框架的概念和意识 18 | 带到 Web 开发社区中去。 -------------------------------------------------------------------------------- /source/general/libraries.rst: -------------------------------------------------------------------------------- 1 | ########################### 2 | 使用 CodeIgniter 类库 3 | ########################### 4 | 5 | 所有的系统类库都位于 *system/libraries/* 目录下,大多数情况下,在使用之前, 6 | 你要先在 :doc:`控制器 ` 中初始化它,使用下面的方法:: 7 | 8 | $this->load->library('class_name'); 9 | 10 | 'class_name' 是你想要调用的类库名称,譬如,要加载 :doc:`表单验证类库 11 | <../libraries/form_validation>`,你可以这样做:: 12 | 13 | $this->load->library('form_validation'); 14 | 15 | 一旦类库被载入,你就可以根据该类库的用户指南中介绍的方法去使用它了。 16 | 17 | 另外,多个类库可以通过一个数组来同时加载。 18 | 19 | 譬如:: 20 | 21 | $this->load->library(array('email', 'table')); 22 | 23 | 创建你自己的类库 24 | =========================== 25 | 26 | 请阅读用户指南中关于 :doc:`创建你自己的类库 ` 部分。 -------------------------------------------------------------------------------- /source/general/requirements.rst: -------------------------------------------------------------------------------- 1 | ################### 2 | 服务器要求 3 | ################### 4 | 5 | 推荐使用 `PHP `_ 5.4 或更新版本。 6 | 7 | 虽然 CodeIgniter 也可以在 PHP 5.2.4 上运行,但是出于潜在的安全和性能问题, 8 | 我们强烈建议你不要使用这么老版本的 PHP,而且老版本的 PHP 也会缺少很多特性。 9 | 10 | 大多数的 Web 应用程序应该都需要一个数据库。当前 CodeIgniter 支持下列数据库: 11 | 12 | - MySQL (5.1+),驱动有:*mysql* (已废弃),*mysqli* 和 *pdo* 13 | - Oracle,驱动有:*oci8* 和 *pdo* 14 | - PostgreSQL,驱动有:*postgre* 和 *pdo* 15 | - MS SQL,驱动有:*mssql*,*sqlsrv* (2005及以上版本)和 *pdo* 16 | - SQLite,驱动有:*sqlite* (版本2),*sqlite3* (版本3)和 *pdo* 17 | - CUBRID,驱动有:*cubrid* 和 *pdo* 18 | - Interbase/Firebird,驱动有:*ibase* 和 *pdo* 19 | - ODBC:驱动有:*odbc* 和 *pdo* (需要知道的是,ODBC 其实只是数据库抽象层) -------------------------------------------------------------------------------- /cilexer/README: -------------------------------------------------------------------------------- 1 | To install the CodeIgniter Lexer to Pygments, run: 2 | 3 | sudo python setup.py install 4 | 5 | Confirm with 6 | 7 | pygmentize -L 8 | 9 | 10 | You should see in the lexer output: 11 | 12 | * ci, codeigniter: 13 | CodeIgniter (filenames *.html, *.css, *.php, *.xml, *.static) 14 | 15 | You will need to run setup.py and install the cilexer package anytime after cilexer/cilexer.py is updated 16 | 17 | NOTE: Depending on how you installed Sphinx and Pygments, 18 | you may be installing to the wrong version. 19 | If you need to install to a different version of python 20 | specify its path when using setup.py, e.g.: 21 | 22 | sudo /usr/bin/python2.5 setup.py install -------------------------------------------------------------------------------- /source/installation/upgrade_212.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.1.1 to 2.1.2 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder. 12 | 13 | .. note:: If you have any custom developed files in these folders please 14 | make copies of them first. 15 | 16 | Step 2: Update your user guide 17 | ============================== 18 | 19 | Please also replace your local copy of the user guide with the new 20 | version. -------------------------------------------------------------------------------- /source/installation/upgrade_213.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.1.2 to 2.1.3 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder. 12 | 13 | .. note:: If you have any custom developed files in these folders please 14 | make copies of them first. 15 | 16 | Step 2: Update your user guide 17 | ============================== 18 | 19 | Please also replace your local copy of the user guide with the new 20 | version. -------------------------------------------------------------------------------- /source/overview/goals.rst: -------------------------------------------------------------------------------- 1 | ############################## 2 | 设计与架构目标 3 | ############################## 4 | 5 | CodeIgniter 的目标是在最小化,最轻量级的开发包中得到最大的执行效率、功能和灵活性。 6 | 7 | 为了达到这个目标,我们在开发过程的每一步都致力于基准测试、重构和简化工作, 8 | 拒绝加入任何对实现目标没有帮助的东西。 9 | 10 | 从技术和架构角度看,CodeIgniter 按照下列目标创建: 11 | 12 | - **动态实例化。** 在 CodeIgniter 中,组件的导入和函数的执行都是在被请求的时候 13 | 才执行,而不是全局的。除核心资源外,系统不需要任何其他资源,因此系统默认是 14 | 非常轻量级的。HTTP 请求所触发的事件以及你设计的控制器和视图将决定哪些资源是 15 | 需要加载的。 16 | - **松耦合。** 耦合是指一个系统中组件之间的依赖程度。组件之间的依赖程度越低, 17 | 系统的重用性和灵活性就越好。我们的目标就是打造一个松耦合的系统。 18 | - **组件专一性** 专一性指的是组件对某个目标的专注程度。在 CodeIgniter 中, 19 | 每一个类和方法都是高度独立的,从而可以最大程序的被复用。 20 | 21 | CodeIgniter 是一个动态实例化,高度组件专一性的松耦合系统。它在小巧的基础上力求做到 22 | 简单、灵活和高性能。 23 | -------------------------------------------------------------------------------- /source/general/autoloader.rst: -------------------------------------------------------------------------------- 1 | ###################### 2 | 自动加载资源 3 | ###################### 4 | 5 | CodeIgniter 的"自动加载"特性可以允许系统每次运行时自动初始化类库、辅助函数和模型。 6 | 如果你需要在整个应用程序中全局使用某些资源,为方便起见可以考虑自动加载它们。 7 | 8 | 支持自动加载的有下面这些: 9 | 10 | - *libraries/* 目录下的核心类 11 | - *helpers/* 目录下的辅助函数 12 | - *config/* 目录下的用户自定义配置文件 13 | - *system/language/* 目录下的语言文件 14 | - *models/* 目录下的模型类 15 | 16 | 要实现自动加载资源,你可以打开 **application/config/autoload.php** 文件,然后将 17 | 你需要自动加载的项添加到 autoload 数组中。你可以在该文件中的每种类型的 autoload 18 | 数组的注释中找到相应的提示。 19 | 20 | .. note:: 添加 autoload 数组时不用包含文件扩展名(.php) 21 | 22 | 另外,如果你想让 CodeIgniter 使用 `Composer `_ 的自动加载, 23 | 只需将 **application/config/config.php** 配置文件中的 ``$config['composer_autoload']`` 24 | 设置为 ``TRUE`` 或者设置为你自定义的路径。 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | 5 | env: 6 | global: 7 | - GH_REF: github.com/aneasystone/ci-doc-chinese.git 8 | - secure: "" 9 | 10 | cache: 11 | directories: 12 | - $HOME/.cache/pip 13 | 14 | sudo: false 15 | 16 | install: 17 | - pip install --upgrade pip 18 | - pip install "Sphinx==1.2.3" 19 | - pip install "sphinxcontrib-phpdomain" 20 | - cd cilexer && python setup.py install && cd .. 21 | 22 | script: 23 | - make html 24 | 25 | # Flags used here, not in `make html`: 26 | # -n Run in nit-picky mode. Currently, this generates warnings for all missing references. 27 | # -W Turn warnings into errors. This means that the build stops at the first warning and sphinx-build exits with exit status 1. 28 | -------------------------------------------------------------------------------- /source/installation/upgrade_161.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.6.0 to 1.6.1 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/codeigniter 15 | - system/database 16 | - system/helpers 17 | - system/language 18 | - system/libraries 19 | 20 | .. note:: If you have any custom developed files in these folders please 21 | make copies of them first. 22 | 23 | Step 2: Update your user guide 24 | ============================== 25 | 26 | Please also replace your local copy of the user guide with the new 27 | version. 28 | -------------------------------------------------------------------------------- /source/installation/upgrade_163.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.6.2 to 1.6.3 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/codeigniter 15 | - system/database 16 | - system/helpers 17 | - system/language 18 | - system/libraries 19 | 20 | .. note:: If you have any custom developed files in these folders please 21 | make copies of them first. 22 | 23 | Step 2: Update your user guide 24 | ============================== 25 | 26 | Please also replace your local copy of the user guide with the new 27 | version. 28 | -------------------------------------------------------------------------------- /source/database/call_function.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 自定义函数调用 3 | ##################### 4 | 5 | $this->db->call_function(); 6 | ============================ 7 | 8 | 这个方法用于执行一些 CodeIgniter 中没有定义的 PHP 数据库函数,而且 9 | 使用了一种平台独立的方式。举个例子,假设你要调用 mysql_get_client_info() 10 | 函数,这个函数 CodeIgniter 并不是原生支持的,你可以这样做:: 11 | 12 | $this->db->call_function('get_client_info'); 13 | 14 | 你必须提供一个不带 mysql\_ 前缀的函数名来作为第一个参数,这个前缀 15 | 会根据当前所使用的数据库驱动自动添加。这让你可以在不同的数据库平台 16 | 执行相同的函数。但是很显然,并不是所有的数据库平台函数都是一样的, 17 | 所以就可移植性而言,它的作用非常有限。 18 | 19 | 任何你需要的其它参数都放在第一个参数后面。 20 | 21 | :: 22 | 23 | $this->db->call_function('some_function', $param1, $param2, etc..); 24 | 25 | 经常的,你会需要提供一个数据库的 connection ID 或是一个 result ID, 26 | connection ID 可以这样来获得:: 27 | 28 | $this->db->conn_id; 29 | 30 | result ID 可以从查询返回的结果对象获取,像这样:: 31 | 32 | $query = $this->db->query("SOME QUERY"); 33 | 34 | $query->result_id; -------------------------------------------------------------------------------- /source/installation/upgrade_171.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.7.0 to 1.7.1 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/codeigniter 15 | - system/database 16 | - system/helpers 17 | - system/language 18 | - system/libraries 19 | 20 | .. note:: If you have any custom developed files in these folders please 21 | make copies of them first. 22 | 23 | Step 2: Update your user guide 24 | ============================== 25 | 26 | Please replace your local copy of the user guide with the new version, 27 | including the image files. 28 | -------------------------------------------------------------------------------- /source/overview/features.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | CodeIgniter 特性 3 | #################### 4 | 5 | 通过一个程序支持的特性并不能断定一个程序的好坏,因为特性 6 | 不能体现出它良好的用户体验,不能体现出它优雅的设计,也不能 7 | 显示出它代码质量如何,性能如何,细节处理的如何,安全性如何。 8 | 判断程序好坏唯一的方法是体验一下并深入研究下它的代码。 9 | 10 | :doc:`安装 <../installation/index>` CodeIgniter 非常简单,所以 11 | 我们鼓励你去安装它,同时,这里是一份 CodeIgniter 支持的主要 12 | 特性列表。 13 | 14 | - 基于 MVC 体系 15 | - 超轻量级 16 | - 对数种数据库平台的全特性支持 17 | - 支持查询构造器 18 | - 表单与数据验证 19 | - 安全性与 XSS 过滤 20 | - 会话管理 21 | - 发送邮件类,支持附件、HTML 或文本邮件、多协议(sendmail、SMTP、Mail)及更多 22 | - 图像处理库(裁剪、缩放、旋转等),支持 GD、ImageMagick 和 NetPBM 23 | - 文件上传类 24 | - FTP 类 25 | - 本地化 26 | - 分页 27 | - 数据加密 28 | - 基准测试 29 | - 全页面缓存 30 | - 错误日志 31 | - 应用程序评测 32 | - 日历类 33 | - User-Agent 类 34 | - Zip 编码类 35 | - 模板引擎类 36 | - Trackback 类 37 | - XML-RPC 类 38 | - 单元测试类 39 | - 搜索引擎友好的 URL 40 | - 灵活的 URL 路由 41 | - 支持钩子和类扩展 42 | - 大量的辅助函数 43 | 44 | -------------------------------------------------------------------------------- /source/general/drivers.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | 使用 CodeIgniter 驱动器 3 | ######################### 4 | 5 | 驱动器是一种特殊类型的类库,它有一个父类和任意多个子类。子类可以访问父类, 6 | 但不能访问兄弟类。在你的 :doc:`控制器 ` 中,驱动器为你的类库提供了 7 | 一种优雅的语法,从而不用将它们拆成很多离散的类。 8 | 9 | 驱动器位于 *system/libraries/* 目录,每个驱动器都有一个独立的目录,目录名和 10 | 驱动器父类的类名一致,在该目录下还有一个子目录,命名为 drivers,用于存放 11 | 所有子类的文件。 12 | 13 | 要使用一个驱动器,你可以在控制器中使用下面的方法来进行初始化:: 14 | 15 | $this->load->driver('class_name'); 16 | 17 | class_name 是你想要调用的驱动器类名,譬如,你要加载名为 Some_parent 的驱动器, 18 | 可以这样:: 19 | 20 | $this->load->driver('some_parent'); 21 | 22 | 然后就可以像下面这样调用该类的方法:: 23 | 24 | $this->some_parent->some_method(); 25 | 26 | 而对于那些子类,我们不用初始化,可以直接通过父类调用了:: 27 | 28 | $this->some_parent->child_one->some_method(); 29 | $this->some_parent->child_two->another_method(); 30 | 31 | 创建你自己的驱动器 32 | ========================= 33 | 34 | 请阅读用户指南中关于如何 :doc:`创建你自己的驱动器 ` 部分。 35 | -------------------------------------------------------------------------------- /source/installation/upgrade_210.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.0.3 to 2.1.0 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder. 12 | 13 | .. note:: If you have any custom developed files in these folders please 14 | make copies of them first. 15 | 16 | Step 2: Replace config/user_agents.php 17 | ====================================== 18 | 19 | This config file has been updated to contain more user agent types, 20 | please copy it to _application/config/user_agents.php*. 21 | 22 | Step 3: Update your user guide 23 | ============================== 24 | 25 | Please also replace your local copy of the user guide with the new 26 | version. -------------------------------------------------------------------------------- /source/installation/upgrade_220.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.1.4 to 2.2.0 3 | ############################# 4 | 5 | .. note:: The :doc:`Encrypt Class ` now requires the 6 | Mcrypt extension. If you were previously using the Encrypt Class 7 | without Mcrypt, then this is a breaking change. You must install 8 | the Mcrypt extension in order to upgrade. For information on 9 | installing Mcrypt please see the PHP `documentation 10 | `. 11 | 12 | Before performing an update you should take your site offline by 13 | replacing the index.php file with a static one. 14 | 15 | Step 1: Update your CodeIgniter files 16 | ===================================== 17 | 18 | Replace all files and directories in your "system" folder. 19 | 20 | .. note:: If you have any custom developed files in these folders please 21 | make copies of them first. -------------------------------------------------------------------------------- /source/installation/upgrade_153.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.5.2 to 1.5.3 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/database/drivers 15 | - system/helpers 16 | - system/libraries/Input.php 17 | - system/libraries/Loader.php 18 | - system/libraries/Profiler.php 19 | - system/libraries/Table.php 20 | 21 | .. note:: If you have any custom developed files in these folders please 22 | make copies of them first. 23 | 24 | Step 2: Update your user guide 25 | ============================== 26 | 27 | Please also replace your local copy of the user guide with the new 28 | version. 29 | -------------------------------------------------------------------------------- /source/installation/upgrade_132.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.3.1 to 1.3.2 3 | ############################# 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.3.1. If you have not upgraded to that version please do so first. 7 | 8 | Before performing an update you should take your site offline by 9 | replacing the index.php file with a static one. 10 | 11 | Step 1: Update your CodeIgniter files 12 | ===================================== 13 | 14 | Replace the following directories in your "system" folder with the new 15 | versions: 16 | 17 | .. note:: If you have any custom developed files in these folders please 18 | make copies of them first. 19 | 20 | - drivers 21 | - init 22 | - libraries 23 | 24 | Step 2: Update your user guide 25 | ============================== 26 | 27 | Please also replace your local copy of the user guide with the new 28 | version. 29 | -------------------------------------------------------------------------------- /source/installation/upgrade_131.rst: -------------------------------------------------------------------------------- 1 | ########################### 2 | Upgrading from 1.3 to 1.3.1 3 | ########################### 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.3. If you have not upgraded to that version please do so first. 7 | 8 | Before performing an update you should take your site offline by 9 | replacing the index.php file with a static one. 10 | 11 | Step 1: Update your CodeIgniter files 12 | ===================================== 13 | 14 | Replace the following directories in your "system" folder with the new 15 | versions: 16 | 17 | .. note:: If you have any custom developed files in these folders please 18 | make copies of them first. 19 | 20 | - drivers 21 | - init/init_unit_test.php (new for 1.3.1) 22 | - language/ 23 | - libraries 24 | - scaffolding 25 | 26 | Step 2: Update your user guide 27 | ============================== 28 | 29 | Please also replace your local copy of the user guide with the new 30 | version. 31 | -------------------------------------------------------------------------------- /source/general/creating_drivers.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 创建驱动器 3 | ################ 4 | 5 | 驱动器目录及文件结构 6 | =================================== 7 | 8 | 下面是驱动器目录和文件结构布局的简单例子: 9 | 10 | - /application/libraries/Driver_name 11 | 12 | - Driver_name.php 13 | - drivers 14 | 15 | - Driver_name_subclass_1.php 16 | - Driver_name_subclass_2.php 17 | - Driver_name_subclass_3.php 18 | 19 | .. note:: 为了在大小写敏感的文件系统下保证兼容性,Driver_name 目录必须以 20 | ``ucfirst()`` 函数返回的结果格式进行命名。 21 | 22 | .. note:: 由于驱动器的架构是子驱动器并不继承主驱动器,因此在子驱动器里 23 | 无法访问主驱动器中的属性或方法。 24 | 25 | 译者补充 26 | ------------------------------------------------- 27 | 28 | 鉴于这篇文档并没有详细介绍什么是驱动器(driver),驱动器的用途,以及如何 29 | 创建驱动器,下面列出一些外部资源供参考: 30 | 31 | - `Usage of drivers in CodeIgniter `_ 32 | - `Guide to CodeIgniter Drivers `_ 33 | - `Codeigniter Drivers Tutorial `_ -------------------------------------------------------------------------------- /source/helpers/language_helper.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | 语言辅助库 3 | ############### 4 | 5 | 语言辅助库文件包含了用于处理语言文件的一些函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('language'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: lang($line[, $for = ''[, $attributes = array()]]) 27 | 28 | :param string $line: Language line key 29 | :param string $for: HTML "for" attribute (ID of the element we're creating a label for) 30 | :param array $attributes: Any additional HTML attributes 31 | :returns: HTML-formatted language line label 32 | :rtype: string 33 | 34 | 此函数使用简单的语法从已加载的语言文件中返回一行文本。 35 | 这种简单的写法在视图文件中可能比调用 ``CI_Lang::line()`` 更顺手。 36 | 37 | Example:: 38 | 39 | echo lang('language_key', 'form_item_id', array('class' => 'myClass')); 40 | // Outputs: -------------------------------------------------------------------------------- /source/tutorial/index.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 教程 - 内容提要 3 | ################ 4 | 5 | 通过由浅入深,前后连贯的章节安排,本教程将向你介绍 CodeIgniter 6 | 框架基础以及MVC程序架构的基本理论。 7 | 8 | 在这篇教程中,你将创建一个 **简单新闻系统**。首先,你将学会: 9 | 如何编写代码让程序能够加载静态内容页面;紧接着,你将学会: 10 | 从数据库中读取新闻条目并将其显示出来;最后,你将学会: 11 | 通过创建表单将新闻条目添加进数据库中。 12 | 13 | 教程将主要介绍以下技术要点: 14 | 15 | - 模型-视图-控制器(Model-View-Controller)基础知识 16 | - URI 路由基础 17 | - 表单验证 18 | - 使用 "查询构造器" 执行基本的数据库操作 19 | 20 | 整个教程会被分拆成多个章节,每个章节会介绍涉及到 CodeIgniter 21 | 的不同功能点。具体章节安排如下: 22 | 23 | - 内容提要(本页面):介绍教程将覆盖的内容要点。 24 | - :doc:`加载静态内容 `:此节主要介绍控制器(Controllers), 25 | 视图(Views)和路由(Routing)的基础知识。 26 | - :doc:`读取新闻条目 `:此节开始介绍模型(Models)的相关知识, 27 | 以及在模型中执行一些基本的数据库操作。 28 | - :doc:`创建新闻条目 `:此节主要介绍在 CodeIgniter 29 | 中执行高级数据库操作,以及表单验证的相关知识。 30 | - :doc:`结束语 `:总结整个教程,给出深入学习 CodeIgniter 31 | 框架的一些建议和参考资源链接。 32 | 33 | 开始你的 CodeIgniter 框架探索之旅吧。 34 | 35 | .. toctree:: 36 | :glob: 37 | :hidden: 38 | :titlesonly: 39 | 40 | static_pages 41 | news_section 42 | create_news_items 43 | conclusion -------------------------------------------------------------------------------- /source/installation/upgrade_211.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.1.0 to 2.1.1 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder. 12 | 13 | .. note:: If you have any custom developed files in these folders please 14 | make copies of them first. 15 | 16 | Step 2: Replace config/mimes.php 17 | ================================ 18 | 19 | This config file has been updated to contain more user mime-types, please copy 20 | it to _application/config/mimes.php*. 21 | 22 | Step 3: Update your IP address tables 23 | ===================================== 24 | 25 | This upgrade adds support for IPv6 IP addresses. In order to store them, you need 26 | to enlarge your ip_address columns to 45 characters. For example, CodeIgniter's 27 | session table will need to change 28 | 29 | :: 30 | 31 | ALTER TABLE ci_sessions CHANGE ip_address ip_address varchar(45) default '0' NOT NULL -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/breadcrumbs.html: -------------------------------------------------------------------------------- 1 |
2 |
    3 |
  • 首页 »
  • 4 | {% for doc in parents %} 5 |
  • {{ doc.title }} »
  • 6 | {% endfor %} 7 |
  • {% if pagename == 'search' %}搜索{% else %}{{ title }}{% endif %}
  • 8 |
  • 9 | {% if display_github %} 10 | Edit on GitHub 11 | {% elif display_bitbucket %} 12 | Edit on Bitbucket 13 | {% elif show_source and has_source and sourcename %} 14 | View page source 15 | {% endif %} 16 |
  • 17 |
18 |
19 |
-------------------------------------------------------------------------------- /source/helpers/xml_helper.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | XML 辅助库 3 | ############ 4 | 5 | XML 辅助库文件包含了用于处理 XML 数据的一些函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('xml'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: xml_convert($str[, $protect_all = FALSE]) 27 | 28 | :param string $str: the text string to convert 29 | :param bool $protect_all: Whether to protect all content that looks like a potential entity instead of just numbered entities, e.g. &foo; 30 | :returns: XML-converted string 31 | :rtype: string 32 | 33 | 将输入字符串中的下列 XML 保留字符转换为实体(Entity): 34 | 35 | - 和号:& 36 | - 小于号和大于号:< > 37 | - 单引号和双引号:' " 38 | - 减号:- 39 | 40 | 如果 & 符号是作为实体编号的一部分,譬如: ``{`` ,该函数将不予处理。 41 | 举例:: 42 | 43 | $string = '

Here is a paragraph & an entity ({).

'; 44 | $string = xml_convert($string); 45 | echo $string; 46 | 47 | 输出结果: 48 | 49 | .. code-block:: html 50 | 51 | <p>Here is a paragraph & an entity ({).</p> -------------------------------------------------------------------------------- /source/installation/downloads.rst: -------------------------------------------------------------------------------- 1 | ####################### 2 | 下载 CodeIgniter 3 | ####################### 4 | 5 | - `CodeIgniter v3.0.0 (当前版本) `_ 6 | - `CodeIgniter v2.2.1 `_ 7 | - `CodeIgniter v2.2.0 `_ 8 | - `CodeIgniter v2.1.4 `_ 9 | - `CodeIgniter v2.1.3 `_ 10 | - `CodeIgniter v2.1.2 `_ 11 | - `CodeIgniter v2.1.1 `_ 12 | - `CodeIgniter v2.1.0 `_ 13 | 14 | ****** 15 | GitHub 16 | ****** 17 | 18 | `Git `_ 是一个分布式版本控制系统。 19 | 20 | CodeIgniter 可以在 `GitHub `_ 上公开访问。 21 | 请注意,尽管我们在保持代码的基础功能上做出了大量的努力,但是我们并不能为开发分支 22 | 的代码中的功能作担保。 23 | 24 | 从 2.0.3 版本开始,每个版本的稳定版都可以从 `GitHub Releases `_ 获取。 -------------------------------------------------------------------------------- /source/helpers/download_helper.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | 下载辅助库 3 | ############### 4 | 5 | 下载辅助库文件包含了下载相关的一些函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('download'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: force_download([$filename = ''[, $data = ''[, $set_mime = FALSE]]]) 27 | 28 | :param string $filename: Filename 29 | :param mixed $data: File contents 30 | :param bool $set_mime: Whether to try to send the actual MIME type 31 | :rtype: void 32 | 33 | 生成 HTTP 头强制下载数据到客户端,这在实现文件下载时很有用。 34 | 第一个参数为下载文件名称,第二个参数为文件数据。 35 | 36 | 如果第二个参数为空,并且 ``$filename`` 参数是一个存在并可读的文件路径, 37 | 那么这个文件的内容将被下载。 38 | 39 | 如果第三个参数设置为 TRUE,那么将发送文件实际的 MIME 类型(根据文件的扩展名), 40 | 这样你的浏览器会根据该 MIME 类型来处理。 41 | 42 | Example:: 43 | 44 | $data = 'Here is some text!'; 45 | $name = 'mytext.txt'; 46 | force_download($name, $data); 47 | 48 | 下载一个服务器上已存在的文件的例子如下:: 49 | 50 | // Contents of photo.jpg will be automatically read 51 | force_download('/path/to/photo.jpg', NULL); -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Dave Snider 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /source/helpers/number_helper.rst: -------------------------------------------------------------------------------- 1 | ############# 2 | 数字辅助库 3 | ############# 4 | 5 | 数字辅助库文件包含了用于处理数字的一些函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('number'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: byte_format($num[, $precision = 1]) 27 | 28 | :param mixed $num: Number of bytes 29 | :param int $precision: Floating point precision 30 | :returns: Formatted data size string 31 | :rtype: string 32 | 33 | 根据数值大小以字节的形式格式化,并添加适合的缩写单位。 34 | 譬如:: 35 | 36 | echo byte_format(456); // Returns 456 Bytes 37 | echo byte_format(4567); // Returns 4.5 KB 38 | echo byte_format(45678); // Returns 44.6 KB 39 | echo byte_format(456789); // Returns 447.8 KB 40 | echo byte_format(3456789); // Returns 3.3 MB 41 | echo byte_format(12345678912345); // Returns 1.8 GB 42 | echo byte_format(123456789123456789); // Returns 11,228.3 TB 43 | 44 | 可选的第二个参数允许你设置结果的精度:: 45 | 46 | echo byte_format(45678, 2); // Returns 44.61 KB 47 | 48 | .. note:: 这个函数生成的缩写单位可以在 *language//number_lang.php* 语言文件中找到。 -------------------------------------------------------------------------------- /source/DCO.rst: -------------------------------------------------------------------------------- 1 | ##################################### 2 | Developer's Certificate of Origin 1.1 3 | ##################################### 4 | 5 | By making a contribution to this project, I certify that: 6 | 7 | (1) The contribution was created in whole or in part by me and I 8 | have the right to submit it under the open source license 9 | indicated in the file; or 10 | 11 | (2) The contribution is based upon previous work that, to the best 12 | of my knowledge, is covered under an appropriate open source 13 | license and I have the right under that license to submit that 14 | work with modifications, whether created in whole or in part 15 | by me, under the same open source license (unless I am 16 | permitted to submit under a different license), as indicated 17 | in the file; or 18 | 19 | (3) The contribution was provided directly to me by some other 20 | person who certified (1), (2) or (3) and I have not modified 21 | it. 22 | 23 | (4) I understand and agree that this project and the contribution 24 | are public and that a record of the contribution (including all 25 | personal information I submit with it, including my sign-off) is 26 | maintained indefinitely and may be redistributed consistent with 27 | this project or the open source license(s) involved. 28 | -------------------------------------------------------------------------------- /source/installation/upgrade_202.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.0.1 to 2.0.2 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder and replace 12 | your index.php file. If any modifications were made to your index.php 13 | they will need to be made fresh in this new one. 14 | 15 | .. note:: If you have any custom developed files in these folders please 16 | make copies of them first. 17 | 18 | Step 2: Remove loading calls for the Security Library 19 | ===================================================== 20 | 21 | Security has been moved to the core and is now always loaded 22 | automatically. Make sure you remove any loading calls as they will 23 | result in PHP errors. 24 | 25 | Step 3: Move MY_Security 26 | ========================= 27 | 28 | If you are overriding or extending the Security library, you will need 29 | to move it to application/core. 30 | 31 | csrf_token_name and csrf_hash have changed to protected class 32 | properties. Please use security->get_csrf_hash() and 33 | security->get_csrf_token_name() to access those values. 34 | -------------------------------------------------------------------------------- /source/general/environments.rst: -------------------------------------------------------------------------------- 1 | ############################## 2 | 处理多环境 3 | ############################## 4 | 5 | 开发者常常希望当系统运行在开发环境或生产环境中时能有不同的行为, 6 | 譬如,在开发环境如果程序能输出详细的错误信息将非常有用,但是在 7 | 生产环境这将造成一些安全问题。 8 | 9 | ENVIRONMENT 常量 10 | ======================== 11 | 12 | CodeIgniter 默认使用 ``$_SERVER['CI_ENV']`` 的值作为 ENVIRONMENT 常量, 13 | 如果 $_SERVER['CI_ENV'] 的值没有设置,则设置为 'development'。在 index.php 14 | 文件的顶部,你可以看到:: 15 | 16 | define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); 17 | 18 | $_SERVER['CI_ENV'] 的值可以在 .htaccess 文件或 Apache 的配置文件中 19 | 使用 `SetEnv `_ 20 | 命令进行设置,Nginx 或其他 Web 服务器也有类似的设置方法。 21 | 或者你可以直接删掉这个逻辑,根据服务器的 IP 地址来设置该常量。 22 | 23 | 使用这个常量,除了会影响到一些基本的框架行为外(见下一节), 24 | 你还可以在开发过程中使用它来区分当前运行的是什么环境。 25 | 26 | 对默认框架行为的影响 27 | ===================================== 28 | 29 | CodeIgniter 系统中有几个地方用到了 ENVIRONMENT 常量。这一节将描述 30 | 它对框架行为有哪些影响。 31 | 32 | 错误报告 33 | --------------- 34 | 35 | 如果将 ENVIRONMENT 常量设置为 'development' ,当发生 PHP 36 | 错误时错误信息会显示到浏览器上。与之相对的,如果将常量设置为 37 | 'production' 错误输出则会被禁用。在生产环境禁用错误输出是个 38 | :doc:`不错的安全实践 `。 39 | 40 | 配置文件 41 | ------------------- 42 | 43 | 另外,CodeIgniter 还可以根据不同的环境加载不同的配置文件, 44 | 这在处理譬如不同环境下有着不同的 API key 的情况时相当有用。 45 | 这在 :doc:`配置类 <../libraries/config>` 文档中的“环境”这一节 46 | 有着更详细的介绍。 47 | -------------------------------------------------------------------------------- /source/installation/upgrading.rst: -------------------------------------------------------------------------------- 1 | ################################# 2 | 从老版本升级 3 | ################################# 4 | 5 | 请根据你要升级的版本阅读相应的升级注意事项。 6 | 7 | .. toctree:: 8 | :titlesonly: 9 | 10 | 从 2.2.x 升级到 3.0.0 11 | 从 2.2.0 升级到 2.2.1 12 | 从 2.1.4 升级到 2.2.0 13 | 从 2.1.3 升级到 2.1.4 14 | 从 2.1.2 升级到 2.1.3 15 | 从 2.1.1 升级到 2.1.2 16 | 从 2.1.0 升级到 2.1.1 17 | 从 2.0.3 升级到 2.1.0 18 | 从 2.0.2 升级到 2.0.3 19 | 从 2.0.1 升级到 2.0.2 20 | 从 2.0 升级到 2.0.1 21 | 从 1.7.2 升级到 2.0 22 | 从 1.7.1 升级到 1.7.2 23 | 从 1.7.0 升级到 1.7.1 24 | 从 1.6.3 升级到 1.7.0 25 | 从 1.6.2 升级到 1.6.3 26 | 从 1.6.1 升级到 1.6.2 27 | 从 1.6.0 升级到 1.6.1 28 | 从 1.5.4 升级到 1.6.0 29 | 从 1.5.3 升级到 1.5.4 30 | 从 1.5.2 升级到 1.5.3 31 | 从 1.5.0 or 1.5.1 升级到 1.5.2 32 | 从 1.4.1 升级到 1.5.0 33 | 从 1.4.0 升级到 1.4.1 34 | 从 1.3.3 升级到 1.4.0 35 | 从 1.3.2 升级到 1.3.3 36 | 从 1.3.1 升级到 1.3.2 37 | 从 1.3 升级到 1.3.1 38 | 从 1.2 升级到 1.3 39 | 从 1.1 升级到 1.2 40 | 从 Beta 1.0 升级到 Beta 1.1 41 | -------------------------------------------------------------------------------- /source/general/caching.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 网页缓存 3 | ################ 4 | 5 | CodeIgniter 可以让你通过缓存页面来达到更好的性能。 6 | 7 | 尽管 CodeIgniter 已经相当高效了,但是网页中的动态内容、主机的内存 8 | CPU 和数据库读取速度等因素直接影响了网页的加载速度。 依靠网页缓存, 9 | 你的网页可以达到近乎静态网页的加载速度,因为程序的输出结果 10 | 已经保存下来了。 11 | 12 | 缓存是如何工作的? 13 | ====================== 14 | 15 | 可以针对到每个独立的页面进行缓存,并且你可以设置每个页面缓存的更新时间。 16 | 当页面第一次加载时,缓存将被写入到 application/cache 目录下的文件中去。 17 | 之后请求这个页面时,就可以直接从缓存文件中读取内容并输出到用户的浏览器。 18 | 如果缓存过期,会在输出之前被删除并重新刷新。 19 | 20 | .. note: 基准测试标签不会被缓存,所以在开启缓存的情况下基准测试仍然可以用。 21 | 22 | 开启缓存 23 | ================ 24 | 25 | 将下面的代码放到任何一个控制器的方法内,你就可以开启缓存了:: 26 | 27 | $this->output->cache($n); 28 | 29 | 其中 ``$n`` 是缓存更新的时间(单位分钟)。 30 | 31 | 上面的代码可以放在方法的任何位置,它出现的顺序对缓存没有影响, 32 | 所以你可以把它放到任何你认为合理的地方。一旦该代码被放在方法内, 33 | 你的页面就开始被缓存了。 34 | 35 | .. important:: 由于 CodeIgniter 存储缓存的方式,只有通过 :doc:`view <./views>` 36 | 输出的页面才能缓存。 37 | 38 | .. important:: 如果你修改了可能影响页面输出的配置,你需要手工删除掉 39 | 你的缓存文件。 40 | 41 | .. note:: 在写入缓存文件之前,你需要把 *application/cache/* 目录的权限 42 | 设置为可写。 43 | 44 | 删除缓存 45 | =============== 46 | 47 | 如果你不再需要缓存某个页面,你可以删除掉该页面上的缓存代码, 48 | 这样它在过期之后就不会刷新了。 49 | 50 | .. note:: 删除缓存代码之后并不是立即生效,必须等到缓存过期才会生效。 51 | 52 | 如果你需要手工删除缓存,你可以使用 ``delete_cache()`` 方法:: 53 | 54 | // Deletes cache for the currently requested URI 55 | $this->output->delete_cache(); 56 | 57 | // Deletes cache for /foo/bar 58 | $this->output->delete_cache('/foo/bar'); -------------------------------------------------------------------------------- /source/installation/upgrade_162.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.6.1 to 1.6.2 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/codeigniter 15 | - system/database 16 | - system/helpers 17 | - system/language 18 | - system/libraries 19 | 20 | .. note:: If you have any custom developed files in these folders please 21 | make copies of them first. 22 | 23 | Step 2: Encryption Key 24 | ====================== 25 | 26 | If you are using sessions, open up application/config/config.php and 27 | verify you've set an encryption key. 28 | 29 | Step 3: Constants File 30 | ====================== 31 | 32 | Copy /application/config/constants.php to your installation, and modify 33 | if necessary. 34 | 35 | Step 4: Mimes File 36 | ================== 37 | 38 | Replace /application/config/mimes.php with the dowloaded version. If 39 | you've added custom mime types, you'll need to re-add them. 40 | 41 | Step 5: Update your user guide 42 | ============================== 43 | 44 | Please also replace your local copy of the user guide with the new 45 | version. 46 | -------------------------------------------------------------------------------- /source/installation/index.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | 安装说明 3 | ######################### 4 | 5 | 通过下面四步来安装 CodeIgniter: 6 | 7 | #. 解压缩安装包; 8 | #. 将 CodeIgniter 文件夹及里面的文件上传到服务器,通常 index.php 9 | 文件将位于网站的根目录; 10 | #. 使用文本编辑器打开 application/config/config.php 文件设置你网站的 11 | 根 URL,如果你想使用加密或会话,在这里设置上你的加密密钥; 12 | #. 如果你打算使用数据库,打开 application/config/database.php 文件 13 | 设置数据库参数。 14 | 15 | 如果你想通过隐藏 CodeIgniter 的文件位置来增加安全性,你可以将 system 16 | 和 application 目录修改为其他的名字,然后打开主目录下的 index.php 文件 17 | 将 $system_path 和 $application_folder 两个变量设置为你修改的名字。 18 | 19 | 为了达到更好的安全性,system 和 application 目录都应该放置在 Web 20 | 根目录之外,这样它们就不能通过浏览器直接访问。CodeIgniter 21 | 默认在每个目录下都包含了一个 .htaccess 文件,用于阻止直接访问, 22 | 但是最好还是将它们移出能公开访问的地方,防止出现 Web 服务器配置 23 | 更改或者 .htaccess 文件不被支持这些情况。 24 | 25 | 如果你想让 views 目录保持公开,也可以将你的 views 目录移出 application 26 | 目录。 27 | 28 | 移动完目录之后,打开 index.php 文件,分别设置好 $system_path、 29 | $application_folder 和 $view_folder 三个变量的值,最好设置成绝对路径, 30 | 譬如:'/www/MyUser/system' 。 31 | 32 | 在生产环境还要额外再多一步,就是禁用 PHP 错误报告以及所有其他仅在 33 | 开发环境使用的功能。在 CodeIgniter 中,可以通过设置 ENVIRONMENT 34 | 常量来做到这一点,这在 :doc:`安全 <../general/security>` 35 | 这篇指南中有着更详细的介绍。 36 | 37 | 以上就是全部安装过程! 38 | 39 | 如果你刚刚接触 CodeIgniter,请阅读用户指南的 :doc`开始 <../overview/getting_started>` 40 | 部分,学习如何构造动态的 PHP 应用,开始享受吧! 41 | 42 | .. toctree:: 43 | :hidden: 44 | :titlesonly: 45 | 46 | downloads 47 | self 48 | upgrading 49 | troubleshooting 50 | 51 | -------------------------------------------------------------------------------- /source/installation/upgrade_152.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.5.0 to 1.5.2 3 | ############################# 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.5.0 or 1.5.1. If you have not upgraded to that version please do so 7 | first. 8 | 9 | Before performing an update you should take your site offline by 10 | replacing the index.php file with a static one. 11 | 12 | Step 1: Update your CodeIgniter files 13 | ===================================== 14 | 15 | Replace these files and directories in your "system" folder with the new 16 | versions: 17 | 18 | - system/helpers/download_helper.php 19 | - system/helpers/form_helper.php 20 | - system/libraries/Table.php 21 | - system/libraries/User_agent.php 22 | - system/libraries/Exceptions.php 23 | - system/libraries/Input.php 24 | - system/libraries/Router.php 25 | - system/libraries/Loader.php 26 | - system/libraries/Image_lib.php 27 | - system/language/english/unit_test_lang.php 28 | - system/database/DB_active_rec.php 29 | - system/database/drivers/mysqli/mysqli_driver.php 30 | - codeigniter/ 31 | 32 | .. note:: If you have any custom developed files in these folders please 33 | make copies of them first. 34 | 35 | Step 2: Update your user guide 36 | ============================== 37 | 38 | Please also replace your local copy of the user guide with the new 39 | version. 40 | -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/versions.html: -------------------------------------------------------------------------------- 1 | {% if READTHEDOCS %} 2 | {# Add rst-badge after rst-versions for small badge style. #} 3 |
4 | 5 | Read the Docs 6 | v: {{ current_version }} 7 | 8 | 9 |
10 |
11 |
Versions
12 | {% for slug, url in versions %} 13 |
{{ slug }}
14 | {% endfor %} 15 |
16 |
17 |
Downloads
18 | {% for type, url in downloads %} 19 |
{{ type }}
20 | {% endfor %} 21 |
22 |
23 |
On Read the Docs
24 |
25 | Project Home 26 |
27 |
28 | Builds 29 |
30 |
31 |
32 | Free document hosting provided by Read the Docs. 33 | 34 |
35 |
36 | {% endif %} 37 | -------------------------------------------------------------------------------- /source/helpers/path_helper.rst: -------------------------------------------------------------------------------- 1 | ########### 2 | 路径辅助库 3 | ########### 4 | 5 | 路径辅助库文件包含了用于处理服务端文件路径的一些函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('path'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: set_realpath($path[, $check_existance = FALSE]) 27 | 28 | :param string $path: Path 29 | :param bool $check_existance: Whether to check if the path actually exists 30 | :returns: An absolute path 31 | :rtype: string 32 | 33 | 该函数返回指定路径在服务端的绝对路径(不是符号路径或相对路径), 34 | 可选的第二个参数用于指定当文件路径不存在时是否报错。 35 | 36 | Examples:: 37 | 38 | $file = '/etc/php5/apache2/php.ini'; 39 | echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini' 40 | 41 | $non_existent_file = '/path/to/non-exist-file.txt'; 42 | echo set_realpath($non_existent_file, TRUE); // Shows an error, as the path cannot be resolved 43 | echo set_realpath($non_existent_file, FALSE); // Prints '/path/to/non-exist-file.txt' 44 | 45 | $directory = '/etc/php5'; 46 | echo set_realpath($directory); // Prints '/etc/php5/' 47 | 48 | $non_existent_directory = '/path/to/nowhere'; 49 | echo set_realpath($non_existent_directory, TRUE); // Shows an error, as the path cannot be resolved 50 | echo set_realpath($non_existent_directory, FALSE); // Prints '/path/to/nowhere' -------------------------------------------------------------------------------- /source/installation/upgrade_172.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.7.1 to 1.7.2 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/codeigniter 15 | - system/database 16 | - system/helpers 17 | - system/language 18 | - system/libraries 19 | - index.php 20 | 21 | .. note:: If you have any custom developed files in these folders please 22 | make copies of them first. 23 | 24 | Step 2: Remove header() from 404 error template 25 | =============================================== 26 | 27 | If you are using header() in your 404 error template, such as the case 28 | with the default error_404.php template shown below, remove that line 29 | of code. 30 | 31 | :: 32 | 33 | 34 | 35 | 404 status headers are now properly handled in the show_404() method 36 | itself. 37 | 38 | Step 3: Confirm your system_path 39 | ================================= 40 | 41 | In your updated index.php file, confirm that the $system_path variable 42 | is set to your application's system folder. 43 | 44 | Step 4: Update your user guide 45 | ============================== 46 | 47 | Please replace your local copy of the user guide with the new version, 48 | including the image files. 49 | -------------------------------------------------------------------------------- /source/general/managing_apps.rst: -------------------------------------------------------------------------------- 1 | ########################## 2 | 管理你的应用程序 3 | ########################## 4 | 5 | 默认情况下,CodeIgniter 假设你只有一个应用程序,被放置在 6 | *application/* 目录下。但是,你完全可以拥有多个程序并让 7 | 它们共享一份 CodeIgniter 。你甚至也可以对你的应用程序目录 8 | 改名,或将其移到其他的位置。 9 | 10 | 重命名应用程序目录 11 | ================================== 12 | 13 | 如果你想重命名应用程序目录,你只需在重命名之后打开 index.php 14 | 文件将 ``$application_folder`` 变量改成新的名字:: 15 | 16 | $application_folder = 'application'; 17 | 18 | 移动应用程序目录 19 | ===================================== 20 | 21 | 你可以将你的应用程序目录移动到除 Web 根目录之外的其他位置, 22 | 移到之后你需要打开 index.php 文件将 ``$application_folder`` 23 | 变量改成新的位置(使用**绝对路径**):: 24 | 25 | $application_folder = '/path/to/your/application'; 26 | 27 | 在一个 CodeIgniter 下运行多个应用程序 28 | =============================================================== 29 | 30 | 如果你希望在一个 CodeIgniter 下管理多个不同的应用程序,只需简单的 31 | 将 application 目录下的所有文件放置到每个应用程序独立的子目录下即可。 32 | 33 | 譬如,你要创建两个应用程序:"foo" 和 "bar",你可以像下面这样组织你的目录结构:: 34 | 35 | applications/foo/ 36 | applications/foo/config/ 37 | applications/foo/controllers/ 38 | applications/foo/libraries/ 39 | applications/foo/models/ 40 | applications/foo/views/ 41 | applications/bar/ 42 | applications/bar/config/ 43 | applications/bar/controllers/ 44 | applications/bar/libraries/ 45 | applications/bar/models/ 46 | applications/bar/views/ 47 | 48 | 要选择使用某个应用程序时,你需要打开 index.php 文件然后设置 ``$application_folder`` 49 | 变量。譬如,选择使用 "foo" 这个应用,你可以这样:: 50 | 51 | $application_folder = 'applications/foo'; 52 | 53 | .. note:: 你的每一个应用程序都需要一个它自己的 index.php 文件来调用它, 54 | 你可以随便对 index.php 文件进行命名。 -------------------------------------------------------------------------------- /source/installation/upgrade_133.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.3.2 to 1.3.3 3 | ############################# 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.3.2. If you have not upgraded to that version please do so first. 7 | 8 | Before performing an update you should take your site offline by 9 | replacing the index.php file with a static one. 10 | 11 | Step 1: Update your CodeIgniter files 12 | ===================================== 13 | 14 | Replace the following directories in your "system" folder with the new 15 | versions: 16 | 17 | .. note:: If you have any custom developed files in these folders please 18 | make copies of them first. 19 | 20 | - codeigniter 21 | - drivers 22 | - helpers 23 | - init 24 | - libraries 25 | 26 | Step 2: Update your Models 27 | ========================== 28 | 29 | If you are **NOT** using CodeIgniter's 30 | :doc:`Models <../general/models>` feature disregard this step. 31 | 32 | As of version 1.3.3, CodeIgniter does **not** connect automatically to 33 | your database when a model is loaded. This allows you greater 34 | flexibility in determining which databases you would like used with your 35 | models. If your application is not connecting to your database prior to 36 | a model being loaded you will have to update your code. There are 37 | several options for connecting, :doc:`as described 38 | here <../general/models>`. 39 | 40 | Step 3: Update your user guide 41 | ============================== 42 | 43 | Please also replace your local copy of the user guide with the new 44 | version. 45 | -------------------------------------------------------------------------------- /source/general/alternative_php.rst: -------------------------------------------------------------------------------- 1 | ################################### 2 | 在视图文件中使用 PHP 替代语法 3 | ################################### 4 | 5 | 如果你不使用 CodeIgniter 的 :doc:`模板引擎 <../libraries/parser>`, 6 | 那么你就只能在视图文件中使用纯 PHP 语法了。为了精简视图文件, 7 | 使其更可读,建议你在写控制结构或 echo 语句时使用 PHP 的替代语法。 8 | 如果你还不熟悉这个语法,下面将介绍如何通过这个语法来消灭你代码 9 | 中的大括号和 echo 语句。 10 | 11 | 自动短标记支持 12 | =========================== 13 | 14 | .. note:: 如果你发现本页所介绍的语法在你的服务器上行不通,那么有可能是 15 | 你的 PHP.ini 文件中禁用了 “短标记”。CodeIgniter 可以动态的重写 16 | 所有的短标记,这样即使你的服务器不支持你也可以使用短标记语法。 17 | 这个特性可以在 *config/config.php* 文件中启用。 18 | 19 | 请注意,如果你使用了这个特性,当你的视图文件发生 PHP 错误时, 20 | 错误信息和行号将无法准确显示,因为所有的错误都显示成 ``eval()`` 错误。 21 | 22 | Echo 替代语法 23 | ================= 24 | 25 | 通常情况,你会使用下面的方法来打印一个变量:: 26 | 27 | 28 | 29 | 使用替代语法,你可以写成这样:: 30 | 31 | 32 | 33 | 控制结构的替代语法 34 | ============================== 35 | 36 | 像 if、for、foreach、while 这样的控制结构也可以写成精简的格式。 37 | 下面以 ``foreach`` 举例:: 38 | 39 |
    40 | 41 | 42 | 43 |
  • 44 | 45 | 46 | 47 |
48 | 49 | 注意这里没有任何括号。所有的结束括号被替换成了 ``endforeach`` 。 50 | 上面说的那些控制结构也都有这相似的结束标志:``endif`` 、 51 | ``endfor`` 、 ``endforeach`` 和 ``endwhile`` 。 52 | 53 | 另外要注意的一点是,每个分支结构的后面都要跟一个冒号,而不是分号 54 | (除最后一个),这是非常重要的一点! 55 | 56 | 这里是另一个例子,使用了 ``if``/``elseif``/``else`` ,注意看冒号的位置:: 57 | 58 | 59 | 60 |

Hi Sally

61 | 62 | 63 | 64 |

Hi Joe

65 | 66 | 67 | 68 |

Hi unknown user

69 | 70 | -------------------------------------------------------------------------------- /source/general/cli.rst: -------------------------------------------------------------------------------- 1 | ################### 2 | 以 CLI 方式运行 3 | ################### 4 | 5 | 除了从浏览器中通过 URL 来调用程序的 :doc:`控制器 <./controllers>` 之外, 6 | 你也可以通过 CLI (命令行界面)的方式来调用。 7 | 8 | .. contents:: 页面内容 9 | 10 | 什么是 CLI ? 11 | ================ 12 | 13 | CLI (命令行界面)是一种基于文本的和计算机交互的方式。 更多信息, 14 | 请查看 `维基百科 `_ 。 15 | 16 | 为什么使用命令行? 17 | ============================= 18 | 19 | 虽然不是很明显,但是有很多情况下我们需要使用命令行来运行 CodeIgniter。 20 | 21 | - 使用 cron 定时运行任务,而不需要使用 *wget* 或 *curl* 22 | - 通过函数 :php:func:`is_cli()` 的返回值来让你的 cron 页面不能通过 URL 访问到 23 | - 制作交互式的任务,譬如:设置权限,清除缓存,备份等等 24 | - 与其他语言进行集成,譬如可以通过 C++ 调用一条指令来运行你模型中的代码。 25 | 26 | 让我们试一试:Hello World! 27 | ============================= 28 | 29 | 让我们先创建一个简单的控制器,打开你的文本编辑器,新建一个文件并命名为 30 | Tools.php,然后输入如下的代码:: 31 | 32 | ` 。 7 | 8 | .. important:: 不鼓励继续使用邮件辅助库,这个库当前仅是为了向前兼容而存在。 9 | 10 | .. contents:: 11 | :local: 12 | 13 | .. raw:: html 14 | 15 |
16 | 17 | 加载辅助库 18 | =================== 19 | 20 | 该辅助库通过下面的代码加载:: 21 | 22 | $this->load->helper('email'); 23 | 24 | 可用函数 25 | =================== 26 | 27 | 该辅助库有下列可用函数: 28 | 29 | .. php:function:: valid_email($email) 30 | 31 | :param string $email: E-mail address 32 | :returns: TRUE if a valid email is supplied, FALSE otherwise 33 | :rtype: bool 34 | 35 | 检查 Email 地址格式是否正确,注意该函数只是简单的检查它的格式是否正确, 36 | 并不能保证该 Email 地址能接受到邮件。 37 | 38 | Example:: 39 | 40 | if (valid_email('email@somesite.com')) 41 | { 42 | echo 'email is valid'; 43 | } 44 | else 45 | { 46 | echo 'email is not valid'; 47 | } 48 | 49 | .. note:: 该函数实际上就是调用 PHP 原生的 ``filter_var()`` 函数而已:: 50 | 51 | (bool) filter_var($email, FILTER_VALIDATE_EMAIL); 52 | 53 | .. php:function:: send_email($recipient, $subject, $message) 54 | 55 | :param string $recipient: E-mail address 56 | :param string $subject: Mail subject 57 | :param string $message: Message body 58 | :returns: TRUE if the mail was successfully sent, FALSE in case of an error 59 | :rtype: bool 60 | 61 | 使用 PHP 函数 `mail() `_ 发送邮件。 62 | 63 | .. note:: 该函数实际上就是调用 PHP 原生的 ``mail()`` 函数而已 64 | 65 | :: 66 | 67 | mail($recipient, $subject, $message); 68 | 69 | 欲了解关于邮件更全面的解决方案,可以参考 CodeIgniter 的 :doc:`Email 类 <../libraries/email>` 。 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/search.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/search.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Template for the search page. 6 | 7 | :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- extends "layout.html" %} 11 | {% set title = _('搜索') %} 12 | {% set script_files = script_files + ['_static/searchtools.js'] %} 13 | {% block footer %} 14 | 17 | {# this is used when loading the search index using $.ajax fails, 18 | such as on Chrome for documents on localhost #} 19 | 20 | {{ super() }} 21 | {% endblock %} 22 | {% block body %} 23 | 31 | 32 | {% if search_performed %} 33 |

{{ _('搜索结果') }}

34 | {% if not search_results %} 35 |

{{ _('找不到和您的查询相符的文档。请检查输入字词有无错误,或尝试其他查询词,或改用较常见的字词,或减少查询字词的数量。') }}

36 | {% endif %} 37 | {% endif %} 38 |
39 | {% if search_results %} 40 |
    41 | {% for href, caption, context in search_results %} 42 |
  • 43 | {{ caption }} 44 |

    {{ context|e }}

    45 |
  • 46 | {% endfor %} 47 |
48 | {% endif %} 49 |
50 | {% endblock %} 51 | -------------------------------------------------------------------------------- /source/installation/upgrade_201.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.0.0 to 2.0.1 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder and replace 12 | your index.php file. If any modifications were made to your index.php 13 | they will need to be made fresh in this new one. 14 | 15 | .. note:: If you have any custom developed files in these folders please 16 | make copies of them first. 17 | 18 | Step 2: Replace config/mimes.php 19 | ================================ 20 | 21 | This config file has been updated to contain more mime types, please 22 | copy it to application/config/mimes.php. 23 | 24 | Step 3: Check for forms posting to default controller 25 | ===================================================== 26 | 27 | The default behavior for form_open() when called with no parameters 28 | used to be to post to the default controller, but it will now just leave 29 | an empty action="" meaning the form will submit to the current URL. If 30 | submitting to the default controller was the expected behavior it will 31 | need to be changed from:: 32 | 33 | echo form_open(); //
34 | 35 | to use either a / or base_url():: 36 | 37 | echo form_open('/'); // 38 | echo form_open(base_url()); // 39 | 40 | -------------------------------------------------------------------------------- /source/installation/upgrade_154.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.5.3 to 1.5.4 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - application/config/mimes.php 15 | - system/codeigniter 16 | - system/database 17 | - system/helpers 18 | - system/libraries 19 | - system/plugins 20 | 21 | .. note:: If you have any custom developed files in these folders please 22 | make copies of them first. 23 | 24 | Step 2: Add charset to your config.php 25 | ====================================== 26 | 27 | Add the following to application/config/config.php 28 | 29 | :: 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Default Character Set 34 | |-------------------------------------------------------------------------- 35 | | 36 | | This determines which character set is used by default in various methods 37 | | that require a character set to be provided. 38 | | 39 | */ 40 | $config['charset'] = "UTF-8"; 41 | 42 | Step 3: Autoloading language files 43 | ================================== 44 | 45 | If you want to autoload any language files, add this line to 46 | application/config/autoload.php 47 | 48 | :: 49 | 50 | $autoload['language'] = array(); 51 | 52 | Step 4: Update your user guide 53 | ============================== 54 | 55 | Please also replace your local copy of the user guide with the new 56 | version. 57 | -------------------------------------------------------------------------------- /source/helpers/typography_helper.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | 排版辅助库 3 | ################# 4 | 5 | 排版辅助库文件包含了文本排版相关的一些函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('typography'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: auto_typography($str[, $reduce_linebreaks = FALSE]) 27 | 28 | :param string $str: Input string 29 | :param bool $reduce_linebreaks: Whether to reduce multiple instances of double newlines to two 30 | :returns: HTML-formatted typography-safe string 31 | :rtype: string 32 | 33 | 格式化文本以便纠正语义和印刷错误的 HTML 代码。 34 | 35 | 这个函数是 ``CI_Typography::auto_typography`` 函数的别名。 36 | 更多信息,查看 :doc:`排版类 <../libraries/typography>` 。 37 | 38 | Usage example:: 39 | 40 | $string = auto_typography($string); 41 | 42 | .. note:: 格式排版可能会消耗大量处理器资源,特别是在排版大量内容时。 43 | 如果你选择使用这个函数的话,你可以考虑使用 `缓存 <../general/caching>`。 44 | 45 | 46 | .. php:function:: nl2br_except_pre($str) 47 | 48 | :param string $str: Input string 49 | :returns: String with HTML-formatted line breaks 50 | :rtype: string 51 | 52 | 将换行符转换为
标签,忽略
 标签中的换行符。除了对 
 
53 | 	标签中的换行处理有所不同之外,这个函数和 PHP 函数 ``nl2br()`` 是完全一样的。
54 | 
55 | 	使用示例::
56 | 
57 | 		$string = nl2br_except_pre($string);
58 | 
59 | .. php:function:: entity_decode($str, $charset = NULL)
60 | 
61 | 	:param	string	$str: Input string
62 | 	:param	string	$charset: Character set
63 | 	:returns:	String with decoded HTML entities
64 | 	:rtype:	string
65 | 
66 | 	这个函数是 ``CI_Security::entity_decode()`` 函数的别名。
67 | 	更多信息,查看 :doc:`安全类 <../libraries/security>` 。


--------------------------------------------------------------------------------
/source/license.rst:
--------------------------------------------------------------------------------
 1 | #####################
 2 | The MIT License (MIT)
 3 | #####################
 4 | 
 5 | Copyright (c) 2014 - 2015, British Columbia Institute of Technology
 6 | 
 7 | Permission is hereby granted, free of charge, to any person obtaining a copy
 8 | of this software and associated documentation files (the "Software"), to deal
 9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 | 
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 | 
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | 
25 | 
26 | 以下为中文译文:
27 | ------------------------------------------------------------------------------
28 | 
29 | MIT 开源许可协议
30 | 
31 | 版权所有 (c) 2014 - 2015, 不列颠哥伦比亚理工学院
32 | 
33 | 特此向任何得到本软件副本或相关文档的人授权:被授权人有权使用、复制、修改、
34 | 合并、出版、发布、散布、再授权和/或贩售软件及软件的副本,及授予被供应人
35 | 同等权利,只需服从以下义务:
36 | 
37 | 在软件和软件的所有副本中都必须包含以上版权声明和本许可声明。
38 | 
39 | 该软件是"按原样"提供的,没有任何形式的明示或暗示,包括但不限于为特定目的和
40 | 不侵权的适销性和适用性的保证担保。在任何情况下,作者或版权持有人,都无权要求
41 | 任何索赔,或有关损害赔偿的其他责任。无论在本软件的使用上或其他买卖交易中,
42 | 是否涉及合同,侵权或其他行为。


--------------------------------------------------------------------------------
/source/general/ancillary_classes.rst:
--------------------------------------------------------------------------------
 1 | ##########################
 2 | 创建附属类
 3 | ##########################
 4 | 
 5 | 有些时候,你可能想在你的控制器之外新建一些类,但同时又希望
 6 | 这些类还能访问 CodeIgniter 的资源。下面你会看到,这其实很简单。
 7 | 
 8 | get_instance()
 9 | ==============
10 | 
11 | .. php:function:: get_instance()
12 | 
13 | 	:returns:	Reference to your controller's instance
14 | 	:rtype:	CI_Controller
15 | 
16 | 任何在你的控制器方法中初始化的类都可以简单的通过 ``get_instance()``
17 | 函数来访问 CodeIgniter 资源。这个函数返回一个 CodeIgniter 对象。
18 | 
19 | 通常来说,调用 CodeIgniter 的方法需要使用 ``$this`` ::
20 | 
21 | 	$this->load->helper('url');
22 | 	$this->load->library('session');
23 | 	$this->config->item('base_url');
24 | 	// etc.
25 | 
26 | 但是 ``$this`` 只能在你的控制器、模型或视图中使用,如果你想在
27 | 你自己的类中使用 CodeIgniter 类,你可以像下面这样做:
28 | 
29 | 首先,将 CodeIgniter 对象赋值给一个变量::
30 | 
31 | 	$CI =& get_instance();
32 | 
33 | 一旦你把 CodeIgniter 对象赋值给一个变量之后,你就可以使用这个变量
34 | 来 *代替* ``$this`` ::
35 | 
36 | 	$CI =& get_instance();
37 | 
38 | 	$CI->load->helper('url');
39 | 	$CI->load->library('session');
40 | 	$CI->config->item('base_url');
41 | 	// etc.
42 | 
43 | 如果你在类中使用``get_instance()`` 函数,最好的方法是将它赋值给
44 | 一个属性 ,这样你就不用在每个方法里都调用 ``get_instance()`` 了。
45 | 
46 | 例如::
47 | 
48 | 	class Example {
49 | 
50 | 		protected $CI;
51 | 
52 | 		// We'll use a constructor, as you can't directly call a function
53 | 		// from a property definition.
54 | 		public function __construct()
55 | 		{
56 | 			// Assign the CodeIgniter super-object
57 | 			$this->CI =& get_instance();
58 | 		}
59 | 
60 | 		public function foo()
61 | 		{
62 | 			$this->CI->load->helper('url');
63 | 			redirect();
64 | 		}
65 | 
66 | 		public function bar()
67 | 		{
68 | 			$this->CI->config->item('base_url');
69 | 		}
70 | 	}
71 | 
72 | 在上面的例子中, ``foo()`` 和 ``bar()`` 方法在初始化 Example 
73 | 类之后都可以正常工作,而不需要在每个方法里都调用 ``get_instance()`` 函数。
74 | 


--------------------------------------------------------------------------------
/source/general/reserved_names.rst:
--------------------------------------------------------------------------------
 1 | ##############
 2 | 保留名称
 3 | ##############
 4 | 
 5 | 为了便于编程,CodeIgniter 使用了一些函数、方法、类 和 变量名来实现。
 6 | 因此,这些名称不能被开发者所使用,下面是不能使用的保留名称列表。
 7 | 
 8 | 控制器名称
 9 | ----------------
10 | 
11 | 因为你的控制器类将继承主程序控制器,所以你的方法命名一定不能和
12 | 主程序控制器类中的方法名相同,否则你的方法将会覆盖他们。
13 | 下面列出了已经保留的名称,请不要将你的控制器命名为这些:
14 | 
15 | -  CI_Controller
16 | -  Default
17 | -  index
18 | 
19 | 函数
20 | ---------
21 | 
22 | -  :php:func:`is_php()`
23 | -  :php:func:`is_really_writable()`
24 | -  ``load_class()``
25 | -  ``is_loaded()``
26 | -  ``get_config()``
27 | -  :php:func:`config_item()`
28 | -  :php:func:`show_error()`
29 | -  :php:func:`show_404()`
30 | -  :php:func:`log_message()`
31 | -  :php:func:`set_status_header()`
32 | -  :php:func:`get_mimes()`
33 | -  :php:func:`html_escape()`
34 | -  :php:func:`remove_invisible_characters()`
35 | -  :php:func:`is_https()`
36 | -  :php:func:`function_usable()`
37 | -  :php:func:`get_instance()`
38 | -  ``_error_handler()``
39 | -  ``_exception_handler()``
40 | -  ``_stringify_attributes()``
41 | 
42 | 变量
43 | ---------
44 | 
45 | -  ``$config``
46 | -  ``$db``
47 | -  ``$lang``
48 | 
49 | 常量
50 | ---------
51 | 
52 | -  ENVIRONMENT
53 | -  FCPATH
54 | -  SELF
55 | -  BASEPATH
56 | -  APPPATH
57 | -  VIEWPATH
58 | -  CI_VERSION
59 | -  MB_ENABLED
60 | -  ICONV_ENABLED
61 | -  UTF8_ENABLED
62 | -  FILE_READ_MODE
63 | -  FILE_WRITE_MODE
64 | -  DIR_READ_MODE
65 | -  DIR_WRITE_MODE
66 | -  FOPEN_READ
67 | -  FOPEN_READ_WRITE
68 | -  FOPEN_WRITE_CREATE_DESTRUCTIVE
69 | -  FOPEN_READ_WRITE_CREATE_DESTRUCTIVE
70 | -  FOPEN_WRITE_CREATE
71 | -  FOPEN_READ_WRITE_CREATE
72 | -  FOPEN_WRITE_CREATE_STRICT
73 | -  FOPEN_READ_WRITE_CREATE_STRICT
74 | -  SHOW_DEBUG_BACKTRACE
75 | -  EXIT_SUCCESS
76 | -  EXIT_ERROR
77 | -  EXIT_CONFIG
78 | -  EXIT_UNKNOWN_FILE
79 | -  EXIT_UNKNOWN_CLASS
80 | -  EXIT_UNKNOWN_METHOD
81 | -  EXIT_USER_INPUT
82 | -  EXIT_DATABASE
83 | -  EXIT__AUTO_MIN
84 | -  EXIT__AUTO_MAX


--------------------------------------------------------------------------------
/source/_themes/sphinx_rtd_theme/static/js/oldtheme.js:
--------------------------------------------------------------------------------
 1 | $( document ).ready(function() {
 2 |     // Shift nav in mobile when clicking the menu.
 3 |     $(document).on('click', "[data-toggle='wy-nav-top']", function() {
 4 |       $("[data-toggle='wy-nav-shift']").toggleClass("shift");
 5 |       $("[data-toggle='rst-versions']").toggleClass("shift");
 6 |     });
 7 |     // Close menu when you click a link.
 8 |     $(document).on('click', ".wy-menu-vertical .current ul li a", function() {
 9 |       $("[data-toggle='wy-nav-shift']").removeClass("shift");
10 |       $("[data-toggle='rst-versions']").toggleClass("shift");
11 |     });
12 |     $(document).on('click', "[data-toggle='rst-current-version']", function() {
13 |       $("[data-toggle='rst-versions']").toggleClass("shift-up");
14 |     });  
15 |     // Make tables responsive
16 |     $("table.docutils:not(.field-list)").wrap("
"); 17 | }); 18 | 19 | window.SphinxRtdTheme = (function (jquery) { 20 | var stickyNav = (function () { 21 | var navBar, 22 | win, 23 | stickyNavCssClass = 'stickynav', 24 | applyStickNav = function () { 25 | if (navBar.height() <= win.height()) { 26 | navBar.addClass(stickyNavCssClass); 27 | } else { 28 | navBar.removeClass(stickyNavCssClass); 29 | } 30 | }, 31 | enable = function () { 32 | applyStickNav(); 33 | win.on('resize', applyStickNav); 34 | }, 35 | init = function () { 36 | navBar = jquery('nav.wy-nav-side:first'); 37 | win = jquery(window); 38 | }; 39 | jquery(init); 40 | return { 41 | enable : enable 42 | }; 43 | }()); 44 | return { 45 | StickyNav : stickyNav 46 | }; 47 | }($)); 48 | -------------------------------------------------------------------------------- /source/helpers/directory_helper.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 目录辅助库 3 | ################ 4 | 5 | 目录辅助库文件包含了一些帮助你处理目录的函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('directory'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]]) 27 | 28 | :param string $source_dir: Path to the source directory 29 | :param int $directory_depth: Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) 30 | :param bool $hidden: Whether to include hidden directories 31 | :returns: An array of files 32 | :rtype: array 33 | 34 | 举例:: 35 | 36 | $map = directory_map('./mydirectory/'); 37 | 38 | .. note:: 路径总是相对于你的 index.php 文件。 39 | 40 | 如果目录内含有子目录,也将被列出。你可以使用第二个参数(整数) 41 | 来控制递归的深度。如果深度为 1,则只列出根目录:: 42 | 43 | $map = directory_map('./mydirectory/', 1); 44 | 45 | 默认情况下,返回的数组中不会包括那些隐藏文件。如果需要显示隐藏的文件, 46 | 你可以设置第三个参数为 true :: 47 | 48 | $map = directory_map('./mydirectory/', FALSE, TRUE); 49 | 50 | 每一个目录的名字都将作为数组的索引,目录所包含的文件将以数字作为索引。 51 | 下面有个典型的数组示例:: 52 | 53 | Array ( 54 | [libraries] => Array 55 | ( 56 | [0] => benchmark.html 57 | [1] => config.html 58 | ["database/"] => Array 59 | ( 60 | [0] => query_builder.html 61 | [1] => binds.html 62 | [2] => configuration.html 63 | [3] => connecting.html 64 | [4] => examples.html 65 | [5] => fields.html 66 | [6] => index.html 67 | [7] => queries.html 68 | ) 69 | [2] => email.html 70 | [3] => file_uploading.html 71 | [4] => image_lib.html 72 | [5] => input.html 73 | [6] => language.html 74 | [7] => loader.html 75 | [8] => pagination.html 76 | [9] => uri.html 77 | ) -------------------------------------------------------------------------------- /source/index.rst: -------------------------------------------------------------------------------- 1 | ###################### 2 | CodeIgniter 用户指南 3 | ###################### 4 | 5 | - :doc:`许可协议 ` 6 | - :doc:`变更记录 ` 7 | 8 | .. contents:: 9 | :local: 10 | :depth: 2 11 | 12 | ******* 13 | 欢迎 14 | ******* 15 | 16 | .. toctree:: 17 | :titlesonly: 18 | 19 | general/welcome 20 | 21 | ********** 22 | 基本信息 23 | ********** 24 | 25 | - :doc:`general/requirements` 26 | - :doc:`general/credits` 27 | 28 | ************ 29 | 安装 30 | ************ 31 | .. toctree:: 32 | :includehidden: 33 | :maxdepth: 2 34 | :titlesonly: 35 | 36 | installation/index 37 | 38 | ************ 39 | 介绍 40 | ************ 41 | 42 | .. toctree:: 43 | :titlesonly: 44 | 45 | overview/index 46 | 47 | ******** 48 | 教程 49 | ******** 50 | 51 | .. toctree:: 52 | :includehidden: 53 | :titlesonly: 54 | 55 | tutorial/index 56 | 57 | ************** 58 | 常规主题 59 | ************** 60 | 61 | .. toctree:: 62 | :glob: 63 | :titlesonly: 64 | 65 | general/index 66 | 67 | ***************** 68 | 类库参考 69 | ***************** 70 | 71 | .. toctree:: 72 | :glob: 73 | :titlesonly: 74 | 75 | libraries/index 76 | 77 | ****************** 78 | 数据库参考 79 | ****************** 80 | 81 | .. toctree:: 82 | :glob: 83 | :titlesonly: 84 | 85 | database/index 86 | 87 | **************** 88 | 辅助库参考 89 | **************** 90 | 91 | .. toctree:: 92 | :glob: 93 | :titlesonly: 94 | 95 | helpers/index 96 | 97 | *************************** 98 | 贡献 CodeIgniter 99 | *************************** 100 | 101 | .. toctree:: 102 | :glob: 103 | :titlesonly: 104 | 105 | contributing/index 106 | 107 | .. toctree:: 108 | :glob: 109 | :titlesonly: 110 | :hidden: 111 | 112 | * 113 | overview/index 114 | general/requirements 115 | general/welcome 116 | installation/index 117 | general/index 118 | libraries/index 119 | helpers/index 120 | database/index 121 | tutorial/index 122 | general/credits 123 | -------------------------------------------------------------------------------- /source/helpers/inflector_helper.rst: -------------------------------------------------------------------------------- 1 | ################### 2 | Inflector 辅助库 3 | ################### 4 | 5 | Inflector 辅助库文件包含了一些帮助你将单词转换为单复数或驼峰格式等等的函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('inflector'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: singular($str) 27 | 28 | :param string $str: Input string 29 | :returns: A singular word 30 | :rtype: string 31 | 32 | 将一个单词的复数形式变为单数形式。例如:: 33 | 34 | echo singular('dogs'); // Prints 'dog' 35 | 36 | .. php:function:: plural($str) 37 | 38 | :param string $str: Input string 39 | :returns: A plular word 40 | :rtype: string 41 | 42 | 将一个单词的单数形式变为复数形式。例如:: 43 | 44 | echo plural('dog'); // Prints 'dogs' 45 | 46 | .. php:function:: camelize($str) 47 | 48 | :param string $str: Input string 49 | :returns: Camelized string 50 | :rtype: string 51 | 52 | 将一个以空格或下划线分隔的单词转换为驼峰格式。例如:: 53 | 54 | echo camelize('my_dog_spot'); // Prints 'myDogSpot' 55 | 56 | .. php:function:: underscore($str) 57 | 58 | :param string $str: Input string 59 | :returns: String containing underscores instead of spaces 60 | :rtype: string 61 | 62 | 将以空格分隔的多个单词转换为下划线分隔格式。例如:: 63 | 64 | echo underscore('my dog spot'); // Prints 'my_dog_spot' 65 | 66 | .. php:function:: humanize($str[, $separator = '_']) 67 | 68 | :param string $str: Input string 69 | :param string $separator: Input separator 70 | :returns: Humanized string 71 | :rtype: string 72 | 73 | 将以下划线分隔的多个单词转换为以空格分隔,并且每个单词以大写开头。例如:: 74 | 75 | echo humanize('my_dog_spot'); // Prints 'My Dog Spot' 76 | 77 | 如果单词是以连接符分割的,第二个参数传入连接符:: 78 | 79 | echo humanize('my-dog-spot', '-'); // Prints 'My Dog Spot' 80 | 81 | .. php:function:: is_countable($word) 82 | 83 | :param string $word: Input string 84 | :returns: TRUE if the word is countable or FALSE if not 85 | :rtype: bool 86 | 87 | 判断某个单词是否有复数形式。例如:: 88 | 89 | is_countable('equipment'); // Returns FALSE -------------------------------------------------------------------------------- /source/installation/upgrade_170.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.6.3 to 1.7.0 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/codeigniter 15 | - system/database 16 | - system/helpers 17 | - system/language 18 | - system/libraries 19 | 20 | .. note:: If you have any custom developed files in these folders please 21 | make copies of them first. 22 | 23 | Step 2: Update your Session Table 24 | ================================= 25 | 26 | If you are using the Session class in your application, AND if you are 27 | storing session data to a database, you must add a new column named 28 | user_data to your session table. Here is an example of what this column 29 | might look like for MySQL:: 30 | 31 | user_data text NOT NULL 32 | 33 | To add this column you will run a query similar to this:: 34 | 35 | ALTER TABLE `ci_sessions` ADD `user_data` text NOT NULL 36 | 37 | You'll find more information regarding the new Session functionality in 38 | the :doc:`Session class <../libraries/sessions>` page. 39 | 40 | Step 3: Update your Validation Syntax 41 | ===================================== 42 | 43 | This is an **optional**, but recommended step, for people currently 44 | using the Validation class. CI 1.7 introduces a new :doc:`Form Validation 45 | class <../libraries/form_validation>`, which deprecates the old 46 | Validation library. We have left the old one in place so that existing 47 | applications that use it will not break, but you are encouraged to 48 | migrate to the new version as soon as possible. Please read the user 49 | guide carefully as the new library works a little differently, and has 50 | several new features. 51 | 52 | Step 4: Update your user guide 53 | ============================== 54 | 55 | Please replace your local copy of the user guide with the new version, 56 | including the image files. 57 | -------------------------------------------------------------------------------- /source/general/urls.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | CodeIgniter URL 3 | ################ 4 | 5 | 默认情况下,CodeIgniter 中的 URL 被设计成对搜索引擎和人类友好。 6 | 不同于使用标准的 “查询字符串” 方法,CodeIgniter 使用基于段的方法:: 7 | 8 | example.com/news/article/my_article 9 | 10 | .. note:: 在 CodeIgniter 中也可以使用查询字符串的方法,参见下文。 11 | 12 | URI 分段 13 | ============ 14 | 15 | 如果遵循模型-视图-控制器模式,那么 URI 中的每一段通常表示下面的含义:: 16 | 17 | example.com/class/function/ID 18 | 19 | #. 第一段表示要调用的控制器 **类** ; 20 | #. 第二段表示要调用的类中的 **函数** 或 **方法** ; 21 | #. 第三段以及后面的段代表传给控制器的参数,如 ID 或其他任何变量; 22 | 23 | :doc:`URI 类 <../libraries/uri>` 和 :doc:`URL 辅助库 <../helpers/url_helper>` 24 | 包含了一些函数可以让你更容易的处理 URI 数据,另外,你的 URL 可以通过 25 | :doc:`URI 路由 ` 进行重定向从而得到更大的灵活性。 26 | 27 | 移除 URL 中的 index.php 28 | =========================== 29 | 30 | 默认情况,你的 URL 中会包含 **index.php** 文件:: 31 | 32 | example.com/index.php/news/article/my_article 33 | 34 | 如果你的 Apache 服务器启用了 *mod_rewrite* ,你可以简单的通过一个 .htaccess 35 | 文件再加上一些简单的规则就可以移除 index.php 了。下面是这个文件的一个例子, 36 | 其中使用了 "否定条件" 来排除某些不需要重定向的项目: 37 | 38 | :: 39 | 40 | RewriteEngine On 41 | RewriteCond %{REQUEST_FILENAME} !-f 42 | RewriteCond %{REQUEST_FILENAME} !-d 43 | RewriteRule ^(.*)$ index.php/$1 [L] 44 | 45 | 在上面的例子中,除已存在的目录和文件,其他的 HTTP 请求都会经过你的 index.php 文件。 46 | 47 | .. note:: 这些规则并不是对所有 Web 服务器都有效。 48 | 49 | .. note:: 确保使用上面的规则排除掉你希望能直接访问到的资源。 50 | 51 | 添加 URL 后缀 52 | =================== 53 | 54 | 在你的 **config/config.php** 文件中你可以指定一个后缀,CodeIgniter 55 | 生成 URL 时会自动添加上它。譬如,一个像这样的 URL:: 56 | 57 | example.com/index.php/products/view/shoes 58 | 59 | 你可以添加一个后缀,如:**.html** ,这样页面看起来就是这个样子:: 60 | 61 | example.com/index.php/products/view/shoes.html 62 | 63 | 启用查询字符串 64 | ====================== 65 | 66 | 有些时候,你可能更喜欢使用查询字符串格式的 URL:: 67 | 68 | index.php?c=products&m=view&id=345 69 | 70 | CodeIgniter 也支持这个格式,你可以在 **application/config.php** 配置文件中启用它。 71 | 打开你的配置文件,查找下面这几项:: 72 | 73 | $config['enable_query_strings'] = FALSE; 74 | $config['controller_trigger'] = 'c'; 75 | $config['function_trigger'] = 'm'; 76 | 77 | 你只要把 "enable_query_strings" 参数设为 TRUE 即可启用该功能。然后通过你设置的 78 | trigger 关键字来访问你的控制器和方法:: 79 | 80 | index.php?c=controller&m=method 81 | 82 | .. note:: 如果你使用查询字符串格式的 URL,你就必须自己手工构造 URL 而不能使用 URL 83 | 辅助库了(以及其他生成 URL 相关的库,譬如表单辅助库),这是由于这些库只能处理 84 | 分段格式的 URL 。 -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ############################ 2 | CodeIgniter 3.0 中文文档 3 | ############################ 4 | 5 | 这里是 CodeIgniter 3.0.0 的中文文档,翻译自 CodeIgniter 6 | `官方的英文版本 `_ , 7 | 并参考了 `CodeIgniter 中国 `_ 提供的 8 | `CodeIgniter 2.2.2 中文手册 `_ 。 9 | 10 | 文档中的大部分内容我都进行了重新整理和翻译,我并没有对原文进行逐字逐句的推敲, 11 | 有些不好翻译的地方使用了一些自己组织的语言进行润色,力求做到语句通顺,易于理解。 12 | 13 | 鉴于个人能力所限,翻译之中难免犯错,欢迎大家批评指正。 14 | 你可以在 Github 上直接提交 Issues ,或者 Fork 我的项目作出修改然后向我提交 Pull Request , 15 | 我会尽快修复文档中的错误。 16 | 17 | ****************** 18 | 安装步骤 19 | ****************** 20 | 21 | CodeIgniter 的用户指南是使用 Sphinx 软件进行管理,并可以生成各种不同的格式。 22 | 所有的页面都是采用 `ReStructured Text `_ 23 | 格式书写,这种格式非常方便人们阅读。 24 | 25 | 安装条件 26 | ============= 27 | 28 | Sphinx 软件依赖于 Python,如果你使用的是 OS X 系统,则系统已经自带 Python 了。 29 | 你可以在终端中执行不带参数的 ``python`` 命令,以确认你的系统是否已安装 Python 。 30 | 如果你已安装,会显示出你当前所使用的版本。 31 | 如果显示的不是2.7以上版本,你可以去这里下载并安装2.7.2 32 | http://python.org/download/releases/2.7.2/ 33 | 34 | 安装 35 | ============ 36 | 37 | 1. 安装 `easy_install `_ 38 | 2. ``easy_install "sphinx==1.2.3"`` 39 | 3. ``easy_install sphinxcontrib-phpdomain`` 40 | 4. 安装 CI Lexer,它可以高亮文档中的 PHP, HTML, CSS, 和 JavaScript 代码 (参见 *cilexer/README*) 41 | 5. 返回代码库根目录 42 | 6. ``make html`` 43 | 44 | 译注: 45 | 46 | 1. Ubuntu 系统上安装 easy_install 可以直接:``sudo apt-get install python-setuptools`` 47 | 2. easy_install 需要 root 权限,前面加上 sudo 48 | 49 | 编辑并创建文档 50 | ================================== 51 | 52 | 所有的源文件都在 *source/* 目录下,在这里你可以添加新的文档或修改已有的文档。 53 | 如同代码的修改一样,我们推荐从你的 feature 分支发起 pull request 到这里的 *develop* 分支。 54 | 55 | 那么,HTML 文档在哪里? 56 | ======================== 57 | 58 | 很显然,HTML 文档才是我们最关心的,因为这毕竟才是用户最终看到的。 59 | 由于对自动生成的文件进行版本控制没有意义,所以它们并不在版本控制之下。 60 | 你如果想要预览 HTML 文档,你可以重新生成它们。生成 HTML 文档非常简单, 61 | 首先进入你的用户指南目录,然后执行上面安装步骤中的最后一步:: 62 | 63 | make html 64 | 65 | 你将会看到正在编译中的信息,编译成功后,生成的用户指南和图片都位于 *build/html/* 目录下。 66 | 在 HTML 第一次编译之后,后面将只会针对修改的文件进行重编译,这将大大的节约我们的时间。 67 | 如果你想再重新全部编译一次,只需删除 *build* 目录然后编译即可。 68 | 69 | *************** 70 | 风格指南 71 | *************** 72 | 73 | 使用 Sphinx 为 CodeIgniter 编写文档,请参考 source/documentation/index.rst 的一般准则。 -------------------------------------------------------------------------------- /source/helpers/security_helper.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | 安全辅助库 3 | ############### 4 | 5 | 安全辅助库文件包含了一些和安全相关的函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('security'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: xss_clean($str[, $is_image = FALSE]) 27 | 28 | :param string $str: Input data 29 | :param bool $is_image: Whether we're dealing with an image 30 | :returns: XSS-clean string 31 | :rtype: string 32 | 33 | 该函数提供了 XSS 攻击的过滤。 34 | 35 | 它是 ``CI_Input::xss_clean()`` 函数的别名,更多信息,请查阅 :doc:`输入类 <../libraries/input>` 文档。 36 | 37 | .. php:function:: sanitize_filename($filename) 38 | 39 | :param string $filename: Filename 40 | :returns: Sanitized file name 41 | :rtype: string 42 | 43 | 该函数提供了 目录遍历 攻击的防护。 44 | 45 | 它是 ``CI_Security::sanitize_filename()`` 函数的别名,更多信息,请查阅 :doc:`安全类 <../libraries/security>` 文档。 46 | 47 | 48 | .. php:function:: do_hash($str[, $type = 'sha1']) 49 | 50 | :param string $str: Input 51 | :param string $type: Algorithm 52 | :returns: Hex-formatted hash 53 | :rtype: string 54 | 55 | 该函数可计算单向散列,一般用于对密码进行加密,默认使用 SHA1 。 56 | 57 | 你可以前往 `hash_algos() `_ 查看所有支持的算法清单。 58 | 59 | 举例:: 60 | 61 | $str = do_hash($str); // SHA1 62 | $str = do_hash($str, 'md5'); // MD5 63 | 64 | .. note:: 这个函数前身为 ``dohash()``,已废弃。 65 | 66 | .. note:: 这个函数也不建议使用,使用原生的 ``hash()`` 函数替代。 67 | 68 | 69 | .. php:function:: strip_image_tags($str) 70 | 71 | :param string $str: Input string 72 | :returns: The input string with no image tags 73 | :rtype: string 74 | 75 | 该安全函数从一个字符串中剥除 image 标签,它将 image 标签转为纯图片的 URL 文本。 76 | 77 | 举例:: 78 | 79 | $string = strip_image_tags($string); 80 | 81 | 它是 ``CI_Security::strip_image_tags()`` 函数的别名,更多信息,请查阅 :doc:`安全类 <../libraries/security>` 文档。 82 | 83 | 84 | .. php:function:: encode_php_tags($str) 85 | 86 | :param string $str: Input string 87 | :returns: Safely formatted string 88 | :rtype: string 89 | 90 | 该安全函数将 PHP 标签转换为实体对象。 91 | 92 | .. note:: 如果你使用函数 :php:func:`xss_clean()` ,会自动转换。 93 | 94 | 举例:: 95 | 96 | $string = encode_php_tags($string); -------------------------------------------------------------------------------- /source/installation/upgrade_160.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.5.4 to 1.6.0 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace these files and directories in your "system" folder with the new 12 | versions: 13 | 14 | - system/codeigniter 15 | - system/database 16 | - system/helpers 17 | - system/libraries 18 | - system/plugins 19 | - system/language 20 | 21 | .. note:: If you have any custom developed files in these folders please 22 | make copies of them first. 23 | 24 | Step 2: Add time_to_update to your config.php 25 | =============================================== 26 | 27 | Add the following to application/config/config.php with the other 28 | session configuration options 29 | 30 | :: 31 | 32 | $config['sess_time_to_update'] = 300; 33 | 34 | 35 | Step 3: Add $autoload['model'] 36 | ============================== 37 | 38 | Add the following to application/config/autoload.php 39 | 40 | :: 41 | 42 | /* 43 | | ------------------------------------------------------------------- 44 | | Auto-load Model files 45 | | ------------------------------------------------------------------- 46 | | Prototype: 47 | | 48 | | $autoload['model'] = array('my_model'); 49 | | 50 | */ 51 | 52 | $autoload['model'] = array(); 53 | 54 | 55 | Step 4: Add to your database.php 56 | ================================ 57 | 58 | Make the following changes to your application/config/database.php file: 59 | 60 | Add the following variable above the database configuration options, 61 | with $active_group 62 | 63 | :: 64 | 65 | $active_record = TRUE; 66 | 67 | 68 | Remove the following from your database configuration options 69 | 70 | :: 71 | 72 | $db['default']['active_r'] = TRUE; 73 | 74 | 75 | Add the following to your database configuration options 76 | 77 | :: 78 | 79 | $db['default']['char_set'] = "utf8"; 80 | $db['default']['dbcollat'] = "utf8_general_ci"; 81 | 82 | 83 | Step 5: Update your user guide 84 | ============================== 85 | 86 | Please also replace your local copy of the user guide with the new 87 | version. 88 | -------------------------------------------------------------------------------- /source/general/core_classes.rst: -------------------------------------------------------------------------------- 1 | ############################ 2 | 创建核心系统类 3 | ############################ 4 | 5 | 每次 CodeIgniter 运行时,都有一些基础类伴随着核心框架自动的被初始化。 6 | 但你也可以使用你自己类来替代这些核心类或者扩展这些核心类。 7 | 8 | **大多数用户一般不会有这种需求,但对于那些想较大幅度的改变 9 | CodeIgniter 的人来说,我们依然提供了替换和扩展核心类的选择。** 10 | 11 | .. note:: 改变系统核心类会产生很大影响,所以在你做之前必须清楚地 12 | 知道自己正在做什么。 13 | 14 | 系统类清单 15 | ================= 16 | 17 | 以下是系统核心文件的清单,它们在每次 CodeIgniter 启动时被调用: 18 | 19 | - Benchmark 20 | - Config 21 | - Controller 22 | - Exceptions 23 | - Hooks 24 | - Input 25 | - Language 26 | - Loader 27 | - Log 28 | - Output 29 | - Router 30 | - Security 31 | - URI 32 | - Utf8 33 | 34 | 替换核心类 35 | ====================== 36 | 37 | 要使用你自己的系统类替换默认的系统类只需简单的将你自己的文件 38 | 放入目录 *application/core* 下:: 39 | 40 | application/core/some_class.php 41 | 42 | 如果这个目录不存在,你可以创建一个。 43 | 44 | 任何一个和上面清单中同名的文件将被替换成核心类。 45 | 46 | 要注意的是,你的类名必须以 CI 开头,譬如,你的文件是 Input.php , 47 | 那么类应该命名为:: 48 | 49 | class CI_Input { 50 | 51 | } 52 | 53 | 扩展核心类 54 | ==================== 55 | 56 | 如果你只是想往现有类中添加一些功能,譬如增加一两个方法,这时替换 57 | 整个类感觉就有点杀鸡用牛刀了。在这种情况下,最好是使用扩展类的方法。 58 | 扩展一个类和替换一个类的做法几乎是一样的,除了要注意以下几点: 59 | 60 | - 你定义的类必须继承自父类。 61 | - 你的类名和文件名必须以 MY\_ 开头。(这是可配置的,见下文) 62 | 63 | 举个例子,要扩展原始的 Input 类,你需要新建一个文件 64 | application/core/MY_Input.php,然后像下面这样定义你的类:: 65 | 66 | class MY_Input extends CI_Input { 67 | 68 | } 69 | 70 | .. note:: 如果在你的类中需要使用构造函数,记得要调用父类的构造函数: 71 | 72 | :: 73 | 74 | class MY_Input extends CI_Input { 75 | 76 | public function __construct() 77 | { 78 | parent::__construct(); 79 | } 80 | } 81 | 82 | **提示:** 任何和父类同名的方法将会取代父类中的方法(这又被称作 “方法覆盖”), 83 | 这让你可以充分的利用并修改 CodeIgniter 的核心。 84 | 85 | 如果你扩展了 控制器 核心类,那么记得在你的应用程序控制器里继承你 86 | 扩展的新类。 87 | 88 | :: 89 | 90 | class Welcome extends MY_Controller { 91 | 92 | public function __construct() 93 | { 94 | parent::__construct(); 95 | } 96 | 97 | public function index() 98 | { 99 | $this->load->view('welcome_message'); 100 | } 101 | } 102 | 103 | 自定义前缀 104 | ----------------------- 105 | 106 | 要想自定义你自己的类的前缀,打开文件 *application/config/config.php* 107 | 然后找到这项:: 108 | 109 | $config['subclass_prefix'] = 'MY_'; 110 | 111 | 请注意所有原始的 CodeIgniter 类库都以 CI\_ 开头,所以请不要使用这个 112 | 作为你的自定义前缀。 -------------------------------------------------------------------------------- /source/database/helpers.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | 查询辅助函数 3 | #################### 4 | 5 | 关于执行查询的信息 6 | ================================== 7 | 8 | **$this->db->insert_id()** 9 | 10 | 当执行 INSERT 语句时,这个方法返回新插入行的ID。 11 | 12 | .. note:: 如果你使用的是 PostgreSQL 的 PDO 驱动器, 或者 Interbase 驱动器, 13 | 这个方法需要一个 ``$name`` 参数来指定合适的顺序。(什么意思?) 14 | 15 | **$this->db->affected_rows()** 16 | 17 | 当执行 INSERT、UPDATE 等写类型的语句时,这个方法返回受影响的行数。 18 | 19 | .. note:: 在 MySQL 中执行 "DELETE FROM TABLE" 语句返回受影响的行数为 0 。 20 | 为了让这个方法返回正确的受影响行数,数据库类对此做了一点小 hack。 21 | 默认情况下,这个 hack 是启用的,你可以在数据库驱动文件中关闭它。 22 | 23 | **$this->db->last_query()** 24 | 25 | 该方法返回上一次执行的查询语句(是查询语句,不是结果)。 26 | 举例:: 27 | 28 | $str = $this->db->last_query(); 29 | 30 | // Produces: SELECT * FROM sometable.... 31 | 32 | 33 | .. note:: 将数据库配置文件中的 **save_queries** 设置为 FALSE 可以让这个方法无效。 34 | 35 | 关于数据库的信息 36 | =============================== 37 | 38 | **$this->db->count_all()** 39 | 40 | 该方法用于获取数据表的总行数,第一个参数为表名,例如:: 41 | 42 | echo $this->db->count_all('my_table'); 43 | 44 | // Produces an integer, like 25 45 | 46 | **$this->db->platform()** 47 | 48 | 该方法输出你正在使用的数据库平台(MySQL,MS SQL,Postgres 等):: 49 | 50 | echo $this->db->platform(); 51 | 52 | **$this->db->version()** 53 | 54 | 该方法输出你正在使用的数据库版本:: 55 | 56 | echo $this->db->version(); 57 | 58 | 让你的查询更简单 59 | ========================== 60 | 61 | **$this->db->insert_string()** 62 | 63 | 这个方法简化了 INSERT 语句的书写,它返回一个正确格式化的 INSERT 语句。 64 | 举例:: 65 | 66 | $data = array('name' => $name, 'email' => $email, 'url' => $url); 67 | 68 | $str = $this->db->insert_string('table_name', $data); 69 | 70 | 第一个参数为表名,第二个参数是一个关联数组,表示待插入的数据。 71 | 上面的例子生成的 SQL 语句如下:: 72 | 73 | INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com') 74 | 75 | .. note:: 所有的值自动被转义,生成安全的查询语句。 76 | 77 | **$this->db->update_string()** 78 | 79 | 这个方法简化了 UPDATE 语句的书写,它返回一个正确格式化的 UPDATE 语句。 80 | 举例:: 81 | 82 | $data = array('name' => $name, 'email' => $email, 'url' => $url); 83 | 84 | $where = "author_id = 1 AND status = 'active'"; 85 | 86 | $str = $this->db->update_string('table_name', $data, $where); 87 | 88 | 第一个参数是表名,第二个参数是一个关联数组,表示待更新的数据,第三个参数 89 | 是个 WHERE 子句。上面的例子生成的 SQL 语句如下:: 90 | 91 | UPDATE table_name SET name = 'Rick', email = 'rick@example.com', url = 'example.com' WHERE author_id = 1 AND status = 'active' 92 | 93 | .. note:: 所有的值自动被转义,生成安全的查询语句。 -------------------------------------------------------------------------------- /source/helpers/cookie_helper.rst: -------------------------------------------------------------------------------- 1 | ############# 2 | Cookie 辅助库 3 | ############# 4 | 5 | Cookie 辅助库文件包含了一些帮助你处理 Cookie 的函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('cookie'); 20 | 21 | 可用函数 22 | =================== 23 | 24 | 该辅助库有下列可用函数: 25 | 26 | .. php:function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]]]) 27 | 28 | :param mixed $name: Cookie name *or* associative array of all of the parameters available to this function 29 | :param string $value: Cookie value 30 | :param int $expire: Number of seconds until expiration 31 | :param string $domain: Cookie domain (usually: .yourdomain.com) 32 | :param string $path: Cookie path 33 | :param string $prefix: Cookie name prefix 34 | :param bool $secure: Whether to only send the cookie through HTTPS 35 | :param bool $httponly: Whether to hide the cookie from JavaScript 36 | :rtype: void 37 | 38 | 该辅助函数提供给你一种更友好的语法来设置浏览器 Cookie,参考 39 | :doc:`输入类 <../libraries/input>` 获取它的详细用法,另外,它是 40 | ``CI_Input::set_cookie()`` 函数的别名。 41 | 42 | .. php:function:: get_cookie($index[, $xss_clean = NULL]]) 43 | 44 | :param string $index: Cookie name 45 | :param bool $xss_clean: Whether to apply XSS filtering to the returned value 46 | :returns: The cookie value or NULL if not found 47 | :rtype: mixed 48 | 49 | 该辅助函数提供给你一种更友好的语法来获取浏览器 Cookie,参考 50 | :doc:`输入类 <../libraries/input>` 获取它的详细用法,同时,这个函数 51 | 和 ``CI_Input::cookie()`` 函数非常类似,只是它会根据配置文件 52 | *application/config/config.php* 中的 ``$config['cookie_prefix']`` 参数 53 | 来作为 Cookie 的前缀。 54 | 55 | .. php:function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]]) 56 | 57 | :param string $name: Cookie name 58 | :param string $domain: Cookie domain (usually: .yourdomain.com) 59 | :param string $path: Cookie path 60 | :param string $prefix: Cookie name prefix 61 | :rtype: void 62 | 63 | 删除一条 Cookie,只需要传入 Cookie 名即可,也可以设置路径或其他参数 64 | 来删除特定 Cookie。 65 | :: 66 | 67 | delete_cookie('name'); 68 | 69 | 这个函数和 ``set_cookie()`` 比较类似,只是它并不提供 Cookie 的值和 70 | 过期时间等参数。第一个参数也可以是个数组,包含多个要删除的 Cookie 。 71 | 另外,你也可以像下面这样删除特定条件的 Cookie 。 72 | :: 73 | 74 | delete_cookie($name, $domain, $path, $prefix); 75 | -------------------------------------------------------------------------------- /source/installation/upgrade_203.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.0.2 to 2.0.3 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder and replace 12 | your index.php file. If any modifications were made to your index.php 13 | they will need to be made fresh in this new one. 14 | 15 | .. note:: If you have any custom developed files in these folders please 16 | make copies of them first. 17 | 18 | Step 2: Update your main index.php file 19 | ======================================= 20 | 21 | If you are running a stock index.php file simply replace your version 22 | with the new one. 23 | 24 | If your index.php file has internal modifications, please add your 25 | modifications to the new file and use it. 26 | 27 | Step 3: Replace config/user_agents.php 28 | ======================================= 29 | 30 | This config file has been updated to contain more user agent types, 31 | please copy it to application/config/user_agents.php. 32 | 33 | Step 4: Change references of the EXT constant to ".php" 34 | ======================================================= 35 | 36 | .. note:: The EXT Constant has been marked as deprecated, but has not 37 | been removed from the application. You are encouraged to make the 38 | changes sooner rather than later. 39 | 40 | Step 5: Remove APPPATH.'third_party' from autoload.php 41 | ======================================================= 42 | 43 | Open application/config/autoload.php, and look for the following:: 44 | 45 | $autoload['packages'] = array(APPPATH.'third_party'); 46 | 47 | If you have not chosen to load any additional packages, that line can be 48 | changed to:: 49 | 50 | $autoload['packages'] = array(); 51 | 52 | Which should provide for nominal performance gains if not autoloading 53 | packages. 54 | 55 | Update Sessions Database Tables 56 | =============================== 57 | 58 | If you are using database sessions with the CI Session Library, please 59 | update your ci_sessions database table as follows:: 60 | 61 | CREATE INDEX last_activity_idx ON ci_sessions(last_activity); 62 | ALTER TABLE ci_sessions MODIFY user_agent VARCHAR(120); 63 | 64 | -------------------------------------------------------------------------------- /cilexer/cilexer/cilexer.py: -------------------------------------------------------------------------------- 1 | # CodeIgniter 2 | # http://codeigniter.com 3 | # 4 | # An open source application development framework for PHP 5 | # 6 | # This content is released under the MIT License (MIT) 7 | # 8 | # Copyright (c) 2014 - 2015, British Columbia Institute of Technology 9 | # 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy 11 | # of this software and associated documentation files (the "Software"), to deal 12 | # in the Software without restriction, including without limitation the rights 13 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | # copies of the Software, and to permit persons to whom the Software is 15 | # furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included in 18 | # all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | # THE SOFTWARE. 27 | # 28 | # Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) 29 | # Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) 30 | # 31 | # http://opensource.org/licenses/MIT MIT License 32 | 33 | import re 34 | import copy 35 | 36 | from pygments.lexer import DelegatingLexer 37 | from pygments.lexers.web import PhpLexer, HtmlLexer 38 | 39 | __all__ = ['CodeIgniterLexer'] 40 | 41 | 42 | class CodeIgniterLexer(DelegatingLexer): 43 | """ 44 | Handles HTML, PHP, JavaScript, and CSS is highlighted 45 | PHP is highlighted with the "startline" option 46 | """ 47 | 48 | name = 'CodeIgniter' 49 | aliases = ['ci', 'codeigniter'] 50 | filenames = ['*.html', '*.css', '*.php', '*.xml', '*.static'] 51 | mimetypes = ['text/html', 'application/xhtml+xml'] 52 | 53 | def __init__(self, **options): 54 | super(CodeIgniterLexer, self).__init__(HtmlLexer, 55 | PhpLexer, 56 | startinline=True) 57 | -------------------------------------------------------------------------------- /source/database/metadata.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | 数据库元数据 3 | ################# 4 | 5 | ************** 6 | 表元数据 7 | ************** 8 | 9 | 下面这些方法用于获取表信息: 10 | 11 | 列出数据库的所有表 12 | ================================ 13 | 14 | **$this->db->list_tables();** 15 | 16 | 该方法返回一个包含你当前连接的数据库的所有表名称的数组。例如:: 17 | 18 | $tables = $this->db->list_tables(); 19 | 20 | foreach ($tables as $table) 21 | { 22 | echo $table; 23 | } 24 | 25 | 26 | 检测表是否存在 27 | =========================== 28 | 29 | **$this->db->table_exists();** 30 | 31 | 有时候,在对某个表执行操作之前先判断该表是否存在将是很有用的。 32 | 该函数返回一个布尔值:TRUE / FALSE。使用示例:: 33 | 34 | if ($this->db->table_exists('table_name')) 35 | { 36 | // some code... 37 | } 38 | 39 | .. note:: 使用你要查找的表名替换掉 *table_name* 40 | 41 | 42 | ************** 43 | 字段元数据 44 | ************** 45 | 46 | 列出表的所有列 47 | ========================== 48 | 49 | **$this->db->list_fields()** 50 | 51 | 该方法返回一个包含字段名称的数组。有两种不同的调用方式: 52 | 53 | 1. 将表名陈作为参数传入 $this->db->list_fields():: 54 | 55 | $fields = $this->db->list_fields('table_name'); 56 | 57 | foreach ($fields as $field) 58 | { 59 | echo $field; 60 | } 61 | 62 | 2. 你可以从任何查询结果对象上调用该方法,获取查询返回的所有字段:: 63 | 64 | $query = $this->db->query('SELECT * FROM some_table'); 65 | 66 | foreach ($query->list_fields() as $field) 67 | { 68 | echo $field; 69 | } 70 | 71 | 72 | 检测表中是否存在某字段 73 | ========================================== 74 | 75 | **$this->db->field_exists()** 76 | 77 | 有时候,在执行一个操作之前先确定某个字段是否存在将会有很用。 78 | 该方法返回一个布尔值:TRUE / FALSE。使用示例:: 79 | 80 | if ($this->db->field_exists('field_name', 'table_name')) 81 | { 82 | // some code... 83 | } 84 | 85 | .. note:: 使用你要查找的字段名替换掉 *field_name* ,然后使用 86 | 你要查找的表名替换掉 *table_name* 。 87 | 88 | 89 | 获取字段的元数据 90 | ======================= 91 | 92 | **$this->db->field_data()** 93 | 94 | 该方法返回一个包含了字段信息的对象数组。 95 | 96 | 获取字段名称或相关的元数据,如数据类型,最大长度等等, 97 | 在有些时候也是非常有用的。 98 | 99 | .. note:: 并不是所有的数据库都支持元数据。 100 | 101 | 使用示例:: 102 | 103 | $fields = $this->db->field_data('table_name'); 104 | 105 | foreach ($fields as $field) 106 | { 107 | echo $field->name; 108 | echo $field->type; 109 | echo $field->max_length; 110 | echo $field->primary_key; 111 | } 112 | 113 | 如果你已经执行了一个查询,你也可以在查询结果对象上调用该方法获取 114 | 返回结果中的所有字段的元数据:: 115 | 116 | $query = $this->db->query("YOUR QUERY"); 117 | $fields = $query->field_data(); 118 | 119 | 如果你的数据库支持,该函数获取的字段信息将包括下面这些: 120 | 121 | - name - 列名称 122 | - max_length - 列的最大长度 123 | - primary_key - 等于1的话表示此列是主键 124 | - type - 列的数据类型 125 | -------------------------------------------------------------------------------- /source/installation/upgrade_140.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.3.3 to 1.4.0 3 | ############################# 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.3.3. If you have not upgraded to that version please do so first. 7 | 8 | Before performing an update you should take your site offline by 9 | replacing the index.php file with a static one. 10 | 11 | Step 1: Update your CodeIgniter files 12 | ===================================== 13 | 14 | Replace the following directories in your "system" folder with the new 15 | versions: 16 | 17 | .. note:: If you have any custom developed files in these folders please 18 | make copies of them first. 19 | 20 | - application/config/**hooks.php** 21 | - application/config/**mimes.php** 22 | - codeigniter 23 | - drivers 24 | - helpers 25 | - init 26 | - language 27 | - libraries 28 | - scaffolding 29 | 30 | Step 2: Update your config.php file 31 | =================================== 32 | 33 | Open your application/config/config.php file and add these new items:: 34 | 35 | 36 | 37 | /* 38 | |-------------------------------------------------------------------------- 39 | | Enable/Disable System Hooks 40 | |-------------------------------------------------------------------------- 41 | | 42 | | If you would like to use the "hooks" feature you must enable it by 43 | | setting this variable to TRUE (boolean). See the user guide for details. 44 | | 45 | */ 46 | $config['enable_hooks'] = FALSE; 47 | 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Allowed URL Characters 52 | |-------------------------------------------------------------------------- 53 | | 54 | | This lets you specify which characters are permitted within your URLs. 55 | | When someone tries to submit a URL with disallowed characters they will 56 | | get a warning message. 57 | | 58 | | As a security measure you are STRONGLY encouraged to restrict URLs to 59 | | as few characters as possible. By default only these are allowed: a-z 0-9~%.:_- 60 | | 61 | | Leave blank to allow all characters -- but only if you are insane. 62 | | 63 | | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! 64 | | 65 | */ 66 | $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-'; 67 | 68 | Step 3: Update your user guide 69 | ============================== 70 | 71 | Please also replace your local copy of the user guide with the new 72 | version. 73 | -------------------------------------------------------------------------------- /source/installation/upgrade_141.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.4.0 to 1.4.1 3 | ############################# 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.4.0. If you have not upgraded to that version please do so first. 7 | 8 | Before performing an update you should take your site offline by 9 | replacing the index.php file with a static one. 10 | 11 | Step 1: Update your CodeIgniter files 12 | ===================================== 13 | 14 | Replace the following directories in your "system" folder with the new 15 | versions: 16 | 17 | .. note:: If you have any custom developed files in these folders please 18 | make copies of them first. 19 | 20 | - codeigniter 21 | - drivers 22 | - helpers 23 | - libraries 24 | 25 | Step 2: Update your config.php file 26 | =================================== 27 | 28 | Open your application/config/config.php file and add this new item:: 29 | 30 | 31 | 32 | /* 33 | |-------------------------------------------------------------------------- 34 | | Output Compression 35 | |-------------------------------------------------------------------------- 36 | | 37 | | Enables Gzip output compression for faster page loads. When enabled, 38 | | the output class will test whether your server supports Gzip. 39 | | Even if it does, however, not all browsers support compression 40 | | so enable only if you are reasonably sure your visitors can handle it. 41 | | 42 | | VERY IMPORTANT: If you are getting a blank page when compression is enabled it 43 | | means you are prematurely outputting something to your browser. It could 44 | | even be a line of whitespace at the end of one of your scripts. For 45 | | compression to work, nothing can be sent before the output buffer is called 46 | | by the output class. Do not "echo" any values with compression enabled. 47 | | 48 | */ 49 | $config['compress_output'] = FALSE; 50 | 51 | Step 3: Rename an Autoload Item 52 | =============================== 53 | 54 | Open the following file: application/config/autoload.php 55 | 56 | Find this array item:: 57 | 58 | $autoload['core'] = array(); 59 | 60 | And rename it to this:: 61 | 62 | $autoload['libraries'] = array(); 63 | 64 | This change was made to improve clarity since some users were not sure 65 | that their own libraries could be auto-loaded. 66 | 67 | Step 4: Update your user guide 68 | ============================== 69 | 70 | Please also replace your local copy of the user guide with the new 71 | version. 72 | -------------------------------------------------------------------------------- /source/installation/upgrade_b11.rst: -------------------------------------------------------------------------------- 1 | ################################### 2 | Upgrading From Beta 1.0 to Beta 1.1 3 | ################################### 4 | 5 | To upgrade to Beta 1.1 please perform the following steps: 6 | 7 | Step 1: Replace your index file 8 | =============================== 9 | 10 | Replace your main index.php file with the new index.php file. Note: If 11 | you have renamed your "system" folder you will need to edit this info in 12 | the new file. 13 | 14 | Step 2: Relocate your config folder 15 | =================================== 16 | 17 | This version of CodeIgniter now permits multiple sets of "applications" 18 | to all share a common set of backend files. In order to enable each 19 | application to have its own configuration values, the config directory 20 | must now reside inside of your application folder, so please move it 21 | there. 22 | 23 | Step 3: Replace directories 24 | =========================== 25 | 26 | Replace the following directories with the new versions: 27 | 28 | - drivers 29 | - helpers 30 | - init 31 | - libraries 32 | - scaffolding 33 | 34 | Step 4: Add the calendar language file 35 | ====================================== 36 | 37 | There is a new language file corresponding to the new calendaring class 38 | which must be added to your language folder. Add the following item to 39 | your version: language/english/calendar_lang.php 40 | 41 | Step 5: Edit your config file 42 | ============================= 43 | 44 | The original application/config/config.php file has a typo in it Open 45 | the file and look for the items related to cookies:: 46 | 47 | $conf['cookie_prefix'] = ""; 48 | $conf['cookie_domain'] = ""; 49 | $conf['cookie_path'] = "/"; 50 | 51 | Change the array name from $conf to $config, like this:: 52 | 53 | $config['cookie_prefix'] = ""; 54 | $config['cookie_domain'] = ""; 55 | $config['cookie_path'] = "/"; 56 | 57 | Lastly, add the following new item to the config file (and edit the 58 | option if needed):: 59 | 60 | 61 | /* 62 | |------------------------------------------------ 63 | | URI PROTOCOL 64 | |------------------------------------------------ 65 | | 66 | | This item determines which server global 67 | | should be used to retrieve the URI string. The 68 | | default setting of "auto" works for most servers. 69 | | If your links do not seem to work, try one of 70 | | the other delicious flavors: 71 | | 72 | | 'auto' Default - auto detects 73 | | 'path_info' Uses the PATH_INFO 74 | | 'query_string' Uses the QUERY_STRING 75 | */ 76 | 77 | $config['uri_protocol'] = "auto"; 78 | 79 | -------------------------------------------------------------------------------- /source/overview/at_a_glance.rst: -------------------------------------------------------------------------------- 1 | ####################### 2 | CodeIgniter 概览 3 | ####################### 4 | 5 | CodeIgniter 是一个应用程序框架 6 | ======================================= 7 | 8 | CodeIgniter 是为 PHP 开发人员提供的一套 Web 应用程序工具包。 9 | 它的目标是能够让你比从零开始更加快速的完成项目,它提供了一套 10 | 丰富的的类库来满足我们日常的任务需求,并且提供了一个简单的 11 | 接口和逻辑结构来调用这些库。CodeIgniter 通过最小化你需要的代码量, 12 | 让你把更多的精力放到项目的创造性开发上。 13 | 14 | CodeIgniter 是免费的 15 | ====================== 16 | 17 | CodeIgniter 通过 MIT 开源许可协议授权,你可以任意使用。 18 | 阅读 :doc:`许可协议 <../license>` 的内容了解更多。 19 | 20 | CodeIgniter 是轻量级的 21 | =========================== 22 | 23 | 真正的轻量级。我们的核心系统只需要一些非常小的库,这和那些 24 | 需要大量资源的框架完全相反。而且,库都是根据请求动态加载, 25 | 你需要什么才加载什么,所以核心系统是个非常轻快的系统。 26 | 27 | CodeIgniter 是快速的 28 | ====================== 29 | 30 | 真正的快速。我们保证你很难找到一个比 CodeIgniter 性能更好的框架。 31 | 32 | CodeIgniter 使用 M-V-C 架构 33 | ============================ 34 | 35 | CodeIgniter 使用了模型-视图-控制器 架构,它能很好的将逻辑层和表示层分离。 36 | 特别是对于那些使用了模板文件的项目来说更好,它能减少模板文件中的代码量。 37 | 我们在介绍 MVC 架构的页面有更详细的介绍。 38 | 39 | CodeIgniter 生成干净的 URL 40 | ================================ 41 | 42 | CodeIgniter 生成的 URL 非常干净,而且对搜索引擎友好。不同于标准的 43 | “查询字符串” 方法, CodeIgniter 使用了基于段的方法:: 44 | 45 | example.com/news/article/345 46 | 47 | 注意:默认 URL 中会包含 index.php 文件,但是可以通过更改 .htaccess 48 | 文件来去掉它。 49 | 50 | CodeIgniter 功能强大 51 | ========================= 52 | 53 | CodeIgniter 拥有全面的类库,能满足大多数 Web 开发任务的需要, 54 | 譬如:访问数据库,发送邮件,验证表单数据,会话管理,处理图像, 55 | 处理 XML-RPC 数据,等等等等。 56 | 57 | CodeIgniter 是可扩展的 58 | ========================= 59 | 60 | 系统可以非常简单的通过你自己的类库和辅助函数来扩展,也可以通过 61 | 类扩展或系统钩子来实现。 62 | 63 | CodeIgniter 不需要模板引擎 64 | ============================================== 65 | 66 | 尽管 CodeIgniter 自带了一个非常简单的可选的模板解析器,但并不强制你 67 | 使用模板。模板引擎的性能无法和原生的 PHP 代码相比,另外使用模板引擎 68 | 还需要学习一种新的语法,而使用原生 PHP 代码只需要你掌握基本的 PHP 69 | 语法即可。看下面的 PHP 代码:: 70 | 71 |
    72 | 73 |
  • 74 | 75 |
76 | 77 | 再来看看使用模板引擎的代码(伪代码):: 78 | 79 |
    80 | {foreach from=$addressbook item="name"} 81 |
  • {$name}
  • 82 | {/foreach} 83 |
84 | 85 | 的确,模板引擎中的代码要清晰一点,但是它是以性能为代价的, 86 | 因为模板引擎中的伪代码必须要转换回 PHP 代码才能运行。 87 | 我们的一个目标是: *性能最大化* ,所以,我们决定不使用模板引擎。 88 | 89 | CodeIgniter 拥有全面的文档 90 | ==================================== 91 | 92 | 程序员们都喜欢写代码而讨厌写文档,当然,我们也不例外。 93 | 但是由于文档和代码是一样重要的,所以我们尽力来做好它。 94 | 我们的代码非常简洁并且注释也非常全面。 95 | 96 | CodeIgniter 拥有一个友好的用户社区 97 | ============================================= 98 | 99 | 你可以看到我们的社区用户在不断的增长,在 100 | `社区论坛 `_ 里活跃的参与着各种话题。 101 | -------------------------------------------------------------------------------- /source/general/profiling.rst: -------------------------------------------------------------------------------- 1 | ########################## 2 | 程序分析 3 | ########################## 4 | 5 | 分析器类会在页面下方显示基准测试结果,运行过的 SQL 语句, 6 | 以及 $_POST 数据。这些信息有助于开发过程中的调试和优化。 7 | 8 | 初始化类 9 | ====================== 10 | 11 | .. important:: 这个类无须初始化,如果已按照下面的方式启用, 12 | 他将被 :doc:`输出类 <../libraries/output>` 自动加载。 13 | 14 | 启用分析器 15 | ===================== 16 | 17 | 要启用分析器,你可以在你的 :doc:`控制器 ` 18 | 方法的任何位置添加一行下面的代码:: 19 | 20 | $this->output->enable_profiler(TRUE); 21 | 22 | 当启用之后,将会生成一份报告插入到页面的最底部。 23 | 24 | 使用下面的方法禁用分析器:: 25 | 26 | $this->output->enable_profiler(FALSE); 27 | 28 | 设置基准测试点 29 | ======================== 30 | 31 | 为了让分析器编译并显示你的基准测试数据,你必须使用特定的语法 32 | 来命名基准点。 33 | 34 | 请阅读 :doc:`基准测试类 <../libraries/benchmark>` 中关于设置基准点的资料。 35 | 36 | 启用和禁用分析器中的字段 37 | ======================================== 38 | 39 | 分析器中的每个字段都可以通过设置相应的控制变量为 TRUE 或 FALSE 40 | 来启用或禁用。有两种方法来实现,其中的一种方法是: 41 | 在 *application/config/profiler.php* 文件里设置全局的默认值。 42 | 43 | 例如:: 44 | 45 | $config['config'] = FALSE; 46 | $config['queries'] = FALSE; 47 | 48 | 另一种方法是:在你的控制器里通过调用 :doc:`输出类 <../libraries/output>` 49 | 的 set_profiler_sections() 函数来覆盖全局设置和默认设置:: 50 | 51 | $sections = array( 52 | 'config' => TRUE, 53 | 'queries' => TRUE 54 | ); 55 | 56 | $this->output->set_profiler_sections($sections); 57 | 58 | 下表列出了可用的分析器字段和用来访问这些字段的 key 。 59 | 60 | ======================= =================================================================== ======== 61 | Key Description Default 62 | ======================= =================================================================== ======== 63 | **benchmarks** 在各个计时点花费的时间以及总时间 TRUE 64 | **config** CodeIgniter 配置变量 TRUE 65 | **controller_info** 被请求的控制器类和调用的方法 TRUE 66 | **get** 请求中的所有 GET 数据 TRUE 67 | **http_headers** 本次请求的 HTTP 头部 TRUE 68 | **memory_usage** 本次请求消耗的内存(单位字节) TRUE 69 | **post** 请求中的所有 POST 数据 TRUE 70 | **queries** 列出所有执行的数据库查询,以及执行时间 TRUE 71 | **uri_string** 本次请求的 URI TRUE 72 | **session_data** 当前会话中存储的数据 TRUE 73 | **query_toggle_count** 指定显示多少个数据库查询,剩下的则默认折叠起来 25 74 | ======================= =================================================================== ======== 75 | 76 | .. note:: 在你的数据库配置文件中禁用 :doc:`save_queries ` 参数 77 | 也可以禁用数据库查询相关的分析器,上面说的 'queries' 字段就没用了。 78 | 你可以通过 ``$this->db->save_queries = TRUE;`` 来覆写该设置。 79 | 另外,禁用这个设置也会导致你无法查看查询语句以及 80 | `last_query ` 。 -------------------------------------------------------------------------------- /source/libraries/typography.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 排版类 3 | ################ 4 | 5 | 排版类提供了一些方法用于帮助你格式化文本。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | ************************** 15 | 使用排版类 16 | ************************** 17 | 18 | 初始化该类 19 | ====================== 20 | 21 | 跟 CodeIgniter 中的其他类一样,可以在你的控制器中使用 ``$this->load->library()`` 22 | 方法加载排版类:: 23 | 24 | $this->load->library('typography'); 25 | 26 | 一旦加载,排版类就可以像下面这样使用:: 27 | 28 | $this->typography 29 | 30 | *************** 31 | 类参考 32 | *************** 33 | 34 | .. php:class:: CI_Typography 35 | 36 | .. attribute:: $protect_braced_quotes = FALSE 37 | 38 | 当排版类和 :doc:`模板解析器类 ` 同时使用时,经常需要保护大括号中的的单引号和双引号不被转换。 39 | 要保护这个,将 ``protect_braced_quotes`` 属性设置为 TRUE 。 40 | 41 | 使用示例:: 42 | 43 | $this->load->library('typography'); 44 | $this->typography->protect_braced_quotes = TRUE; 45 | 46 | .. method auto_typography($str[, $reduce_linebreaks = FALSE]) 47 | 48 | :param string $str: Input string 49 | :param bool $reduce_linebreaks: Whether to reduce consequitive linebreaks 50 | :returns: HTML typography-safe string 51 | :rtype: string 52 | 53 | 格式化文本以便纠正语义和印刷错误的 HTML 代码。按如下规则格式化输入的字符串: 54 | 55 | - 将段落使用

包起来(看起来像是用两个换行符把段落分隔开似的)。 56 | - 除了出现
 标签外,所有的单个换行符被转换为 
。 57 | - 块级元素如
标签,不会被段落包住,但是如果他们包含文本的话文本会被段落包住。 58 | - 除了出现在标签中的引号外,引号会被转换成正确的实体。 59 | - 撇号被转换为相应的实体。 60 | - 双破折号(像 -- 或--)被转换成 em — 破折号。 61 | - 三个连续的点也会被转换为省略号… 。 62 | - 句子后连续的多个空格将被转换为   以便在网页中显示。 63 | 64 | 使用示例:: 65 | 66 | $string = $this->typography->auto_typography($string); 67 | 68 | 第二个可选参数用于是否将多于两个连续的换行符压缩成两个,传入 TRUE 启用压缩换行:: 69 | 70 | $string = $this->typography->auto_typography($string, TRUE); 71 | 72 | .. note:: 格式排版可能会消耗大量处理器资源,特别是在排版大量内容时。 73 | 如果你选择使用这个函数的话,你可以考虑使用 `缓存 <../general/caching>`。 74 | 75 | .. php:method:: format_characters($str) 76 | 77 | :param string $str: Input string 78 | :returns: Formatted string 79 | :rtype: string 80 | 81 | 该方法和上面的 ``auto_typography()`` 类似,但是它只对字符进行处理: 82 | 83 | - 除了出现在标签中的引号外,引号会被转换成正确的实体。 84 | - 撇号被转换为相应的实体。 85 | - 双破折号(像 -- 或--)被转换成 em — 破折号。 86 | - 三个连续的点也会被转换为省略号… 。 87 | - 句子后连续的多个空格将被转换为   以便在网页中显示。 88 | 89 | 使用示例:: 90 | 91 | $string = $this->typography->format_characters($string); 92 | 93 | .. php:method:: nl2br_except_pre($str) 94 | 95 | :param string $str: Input string 96 | :returns: Formatted string 97 | :rtype: string 98 | 99 | 将换行符转换为
标签,忽略
 标签中的换行符。除了对 
 
100 | 		标签中的换行处理有所不同之外,这个函数和 PHP 函数 ``nl2br()`` 是完全一样的。
101 | 
102 | 		使用示例::
103 | 
104 | 			$string = $this->typography->nl2br_except_pre($string);


--------------------------------------------------------------------------------
/source/database/transactions.rst:
--------------------------------------------------------------------------------
  1 | ############
  2 | 事务
  3 | ############
  4 | 
  5 | CodeIgniter 允许你在支持事务安全的表上使用事务。在 MySQL 中,你需要将
  6 | 表的存储引擎设置为 InnoDb 或 BDB,而不是通常我们使用的 MyISAM 。大多数
  7 | 其他数据库平台都原生支持事务。
  8 | 
  9 | 如果你对事务还不熟悉,我们推荐针对你正在使用的数据库,先在网上寻找一些
 10 | 在线资源学习一下。下面将假设你已经明白事务的基本概念。
 11 | 
 12 | CodeIgniter 的事务方法
 13 | ======================================
 14 | 
 15 | CodeIgniter 使用的事务处理方法与流行的数据库类 ADODB 的处理方法非常相似。
 16 | 我们选择这种方式是因为它极大的简化了事务的处理过程。大多数情况下,你只需
 17 | 编写两行代码就行了。
 18 | 
 19 | 传统的事务处理需要实现大量的工作,你必须随时跟踪你的查询,并根据查询的成功
 20 | 或失败来决定提交还是回滚。当遇到嵌套查询时将会更加麻烦。相比之下,我们实现了
 21 | 一个智能的事务系统,它将自动的为你做这些工作。(你仍然可以选择手工管理你的
 22 | 事务,但这实在是没啥好处)
 23 | 
 24 | 运行事务
 25 | ====================
 26 | 
 27 | 要使用事务来运行你的查询,你可以使用 $this->db->trans_start() 和
 28 | $this->db->trans_complete() 两个方法,像下面这样::
 29 | 
 30 | 	$this->db->trans_start();
 31 | 	$this->db->query('AN SQL QUERY...');
 32 | 	$this->db->query('ANOTHER QUERY...');
 33 | 	$this->db->query('AND YET ANOTHER QUERY...');
 34 | 	$this->db->trans_complete();
 35 | 
 36 | 在 start 和 complete 之间,你可以运行任意多个查询,根据查询执行
 37 | 成功或失败,系统将自动提交或回滚。
 38 | 
 39 | 严格模式 (Strict Mode)
 40 | ============================
 41 | 
 42 | CodeIgniter 默认使用严格模式运行所有的事务,在严格模式下,如果你正在
 43 | 运行多组事务,只要有一组失败,所有组都会被回滚。如果禁用严格模式,那么
 44 | 每一组都被视为独立的组,这意味着其中一组失败不会影响其他的组。
 45 | 
 46 | 严格模式可以用下面的方法禁用::
 47 | 
 48 | 	$this->db->trans_strict(FALSE);
 49 | 
 50 | 错误处理
 51 | ===============
 52 | 
 53 | 如果你的数据库配置文件 config/database.php 中启用了错误报告(db_debug = TRUE),
 54 | 当提交没有成功时,你会看到一条标准的错误信息。如果没有启用错误报告,
 55 | 你可以像下面这样来管理你的错误::
 56 | 
 57 | 	$this->db->trans_start();
 58 | 	$this->db->query('AN SQL QUERY...');
 59 | 	$this->db->query('ANOTHER QUERY...');
 60 | 	$this->db->trans_complete();
 61 | 	
 62 | 	if ($this->db->trans_status() === FALSE)
 63 | 	{
 64 | 		// generate an error... or use the log_message() function to log your error
 65 | 	}
 66 | 
 67 | 启用事务
 68 | =====================
 69 | 
 70 | 当执行 $this->db->trans_start() 方法时,事务将自动启用,如果
 71 | 你要禁用事务,可以使用 $this->db->trans_off() 方法来实现::
 72 | 
 73 | 	$this->db->trans_off();
 74 | 	
 75 | 	$this->db->trans_start();
 76 | 	$this->db->query('AN SQL QUERY...');
 77 | 	$this->db->trans_complete();
 78 | 
 79 | 当事务被禁用时,你的查询会自动提交,就跟没有使用事务一样。
 80 | 
 81 | 测试模式(Test Mode)
 82 | ======================
 83 | 
 84 | 你可以选择性的将你的事务系统设置为 “测试模式”,这将导致你的所有
 85 | 查询都被回滚,就算查询成功执行也一样。要使用 “测试模式”,你只需要
 86 | 将 $this->db->trans_start() 函数的第一个参数设置为 TRUE 即可::
 87 | 
 88 | 	$this->db->trans_start(TRUE); // Query will be rolled back
 89 | 	$this->db->query('AN SQL QUERY...');
 90 | 	$this->db->trans_complete();
 91 | 
 92 | 手工运行事务
 93 | =============================
 94 | 
 95 | 如果你想手工运行事务,可以像下面这样做::
 96 | 
 97 | 	$this->db->trans_begin();
 98 | 	
 99 | 	$this->db->query('AN SQL QUERY...');
100 | 	$this->db->query('ANOTHER QUERY...');
101 | 	$this->db->query('AND YET ANOTHER QUERY...');
102 | 	
103 | 	if ($this->db->trans_status() === FALSE)
104 | 	{
105 | 		$this->db->trans_rollback();
106 | 	}
107 | 	else
108 | 	{
109 | 		$this->db->trans_commit();
110 | 	}
111 | 
112 | .. note:: 手动运行事务时,请务必使用 $this->db->trans_begin() 方法,
113 | 	**而不是** $this->db->trans_start() 方法。
114 | 


--------------------------------------------------------------------------------
/source/general/errors.rst:
--------------------------------------------------------------------------------
  1 | ##############
  2 | 错误处理
  3 | ##############
  4 | 
  5 | CodeIgniter 可以通过下面介绍的方法来在你的应用程序中生成错误报告。
  6 | 另外,还有一个错误日志类用来将错误或调试信息保存到文本文件中。
  7 | 
  8 | .. note:: CodeIgniter 默认将显示所有的 PHP 错误,你可能在开发结束之后
  9 | 	改变该行为。在你的 index.php 文件的顶部有一个 error_reporting()
 10 | 	函数,通过它可以修改错误设置。当发生错误时,禁用错误报告
 11 | 	并不会阻止向日志文件写入错误信息。
 12 | 
 13 | 和 CodeIgniter 中的大多数系统不同,错误函数是一个可以在整个应用程序中
 14 | 使用的简单接口,这让你在使用该函数时不用担心类或方法的作用域的问题。
 15 | 
 16 | 当任何一处核心代码调用 ``exit()`` 时,CodeIgniter 会返回一个状态码。
 17 | 这个状态码和 HTTP 状态码不同,是用来通知其他程序 PHP 脚本是否成功运行的,
 18 | 如果运行不成功,又是什么原因导致了脚本退出。状态码的值被定义在
 19 | *application/config/constants.php* 文件中。状态码在 CLI 形式下非常有用,
 20 | 可以帮助你的服务器跟踪并监控你的脚本。
 21 | 
 22 | 下面的函数用于生成错误信息:
 23 | 
 24 | .. php:function:: show_error($message, $status_code, $heading = 'An Error Was Encountered')
 25 | 
 26 | 	:param	mixed	$message: Error message
 27 | 	:param	int	$status_code: HTTP Response status code
 28 | 	:param	string	$heading: Error page heading
 29 | 	:rtype:	void
 30 | 
 31 | 	该函数使用下面的错误模板来显示错误信息::
 32 | 
 33 | 		application/views/errors/html/error_general.php
 34 | 
 35 | 	或:
 36 | 
 37 | 		application/views/errors/cli/error_general.php
 38 | 
 39 | 	可选参数 ``$status_code`` 将决定发送什么 HTTP 状态码。
 40 | 	如果 ``$status_code`` 小于 100,HTTP 状态码将被置为 500 ,
 41 | 	退出状态码将被置为 ``$status_code + EXIT__AUTO_MIN`` 。
 42 | 	如果它的值大于 ``EXIT__AUTO_MAX`` 或者如果 ``$status_code`` 
 43 | 	大于等于 100 ,退出状态码将被置为 ``EXIT_ERROR`` 。
 44 | 	详情可查看 *application/config/constants.php* 文件。
 45 | 
 46 | .. php:function:: show_404($page = '', $log_error = TRUE)
 47 | 
 48 | 	:param	string	$page: URI string
 49 | 	:param	bool	$log_error: Whether to log the error
 50 | 	:rtype:	void
 51 | 
 52 | 	该函数使用下面的错误模板来显示 404 错误信息::
 53 | 
 54 | 		application/views/errors/html/error_404.php
 55 | 
 56 | 	或:
 57 | 
 58 | 		application/views/errors/cli/error_404.php
 59 | 
 60 | 	传递给该函数的字符串代表的是找不到的文件路径。退出状态码
 61 | 	将设置为 ``EXIT_UNKNOWN_FILE`` 。
 62 | 	注意如果找不到控制器 CodeIgniter 将自动显示 404 错误信息。
 63 | 
 64 | 	默认 CodeIgniter 会自动将 ``show_404()`` 函数调用记录到错误日志中。
 65 | 	将第二个参数设置为 FALSE 将跳过记录日志。
 66 | 
 67 | .. php:function:: log_message($level, $message, $php_error = FALSE)
 68 | 
 69 | 	:param	string	$level: Log level: 'error', 'debug' or 'info'
 70 | 	:param	string	$message: Message to log
 71 | 	:param	bool	$php_error: Whether we're logging a native PHP error message
 72 | 	:rtype:	void
 73 | 
 74 | 	该函数用于向你的日志文件中写入信息,第一个参数你必须提供
 75 | 	三个信息级别中的一个,用于指定记录的是什么类型的信息(调试,
 76 | 	错误和一般信息),第二个参数为信息本身。
 77 | 
 78 | 	示例::
 79 | 
 80 | 		if ($some_var == '')
 81 | 		{
 82 | 			log_message('error', 'Some variable did not contain a value.');
 83 | 		}
 84 | 		else
 85 | 		{
 86 | 			log_message('debug', 'Some variable was correctly set');
 87 | 		}
 88 | 
 89 | 		log_message('info', 'The purpose of some variable is to provide some value.');
 90 | 
 91 | 	有三种信息类型:
 92 | 
 93 | 	#. 错误信息。这些是真正的错误,譬如 PHP 错误或用户错误。
 94 | 	#. 调试信息。这些信息帮助你调试程序,譬如,你可以在一个类
 95 | 	   初始化的地方记录下来作为调试信息。
 96 | 	#. 一般信息。这些是最低级别的信息,简单的给出程序运行过程中的一些信息。
 97 | 
 98 | 	.. note:: 为了保证日志文件被正确写入,*logs/* 目录必须设置为可写的。
 99 | 		此外,你必须要设置 *application/config/config.php* 文件中的
100 | 		"threshold"  参数,举个例子,譬如你只想记录错误信息,而不想
101 | 		记录另外两种类型的信息,可以通过这个参数来控制。如果你将
102 | 		该参数设置为 0 ,日志就相当于被禁用了。
103 | 


--------------------------------------------------------------------------------
/source/general/hooks.rst:
--------------------------------------------------------------------------------
  1 | ####################################
  2 | 钩子 - 扩展框架核心
  3 | ####################################
  4 | 
  5 | CodeIgniter 的钩子特性提供了一种方法来修改框架的内部运作流程,而无需修改
  6 | 核心文件。CodeIgniter 的运行遵循着一个特定的流程,你可以参考这个页面的
  7 | :doc:`应用程序流程图 <../overview/appflow>` 。但是,有些时候你可能希望在
  8 | 执行流程中的某些阶段添加一些动作,例如在控制器加载之前或之后执行一段脚本,
  9 | 或者在其他的某些位置触发你的脚本。
 10 | 
 11 | 启用钩子
 12 | ==============
 13 | 
 14 | 钩子特性可以在 **application/config/config.php** 文件中全局的启用或禁用,
 15 | 设置下面这个参数::
 16 | 
 17 | 	$config['enable_hooks'] = TRUE;
 18 | 
 19 | 定义钩子
 20 | ===============
 21 | 
 22 | 钩子是在 **application/config/hooks.php** 文件中被定义的,每个钩子可以定义
 23 | 为下面这样的数组格式::
 24 | 
 25 | 	$hook['pre_controller'] = array(
 26 | 		'class'    => 'MyClass',
 27 | 		'function' => 'Myfunction',
 28 | 		'filename' => 'Myclass.php',
 29 | 		'filepath' => 'hooks',
 30 | 		'params'   => array('beer', 'wine', 'snacks')
 31 | 	);
 32 | 
 33 | **注意:**
 34 | 
 35 | 数组的索引为你想使用的挂钩点名称,譬如上例中挂钩点为 pre_controller ,
 36 | 下面会列出所有可用的挂钩点。钩子数组是一个关联数组,数组的键值可以是
 37 | 下面这些:
 38 | 
 39 | -  **class** 你希望调用的类名,如果你更喜欢使用过程式的函数的话,这一项可以留空。
 40 | -  **function** 你希望调用的方法或函数的名称。
 41 | -  **filename** 包含你的类或函数的文件名。
 42 | -  **filepath** 包含你的脚本文件的目录名。
 43 |    注意:
 44 |    你的脚本必须放在 *application/* 目录里面,所以 filepath 是相对 *application/* 
 45 |    目录的路径,举例来说,如果你的脚本位于 *application/hooks/* ,那么 filepath
 46 |    可以简单的设置为 'hooks' ,如果你的脚本位于 *application/hooks/utilities/* ,
 47 |    那么 filepath 可以设置为 'hooks/utilities' ,路径后面不用加斜线。
 48 | -  **params** 你希望传递给你脚本的任何参数,可选。
 49 | 
 50 | 如果你使用 PHP 5.3 以上的版本,你也可以使用 lambda表达式(匿名函数或闭包)作为钩子,
 51 | 这样语法更简单::
 52 | 
 53 | 	$hook['post_controller'] = function()
 54 | 	{
 55 | 		/* do something here */
 56 | 	};
 57 | 
 58 | 多次调用同一个挂钩点
 59 | ===============================
 60 | 
 61 | 如果你想在同一个挂钩点处添加多个脚本,只需要将钩子数组变成二维数组即可,像这样::
 62 | 
 63 | 	$hook['pre_controller'][] = array(
 64 | 		'class'    => 'MyClass',
 65 | 		'function' => 'MyMethod',
 66 | 		'filename' => 'Myclass.php',
 67 | 		'filepath' => 'hooks',
 68 | 		'params'   => array('beer', 'wine', 'snacks')
 69 | 	);
 70 | 
 71 | 	$hook['pre_controller'][] = array(
 72 | 		'class'    => 'MyOtherClass',
 73 | 		'function' => 'MyOtherMethod',
 74 | 		'filename' => 'Myotherclass.php',
 75 | 		'filepath' => 'hooks',
 76 | 		'params'   => array('red', 'yellow', 'blue')
 77 | 	);
 78 | 
 79 | 注意数组索引后面多了个中括号::
 80 | 
 81 | 	$hook['pre_controller'][]
 82 | 
 83 | 这可以让你在同一个挂钩点处执行多个脚本,多个脚本执行顺序就是你定义数组的顺序。
 84 | 
 85 | 挂钩点
 86 | ===========
 87 | 
 88 | 以下是所有可用挂钩点的一份列表:
 89 | 
 90 | -  **pre_system**
 91 |    在系统执行的早期调用,这个时候只有 基准测试类 和 钩子类 被加载了,
 92 |    还没有执行到路由或其他的流程。
 93 | -  **pre_controller**
 94 |    在你的控制器调用之前执行,所有的基础类都已加载,路由和安全检查也已经完成。
 95 | -  **post_controller_constructor**
 96 |    在你的控制器实例化之后立即执行,控制器的任何方法都还尚未调用。
 97 | -  **post_controller**
 98 |    在你的控制器完全运行结束时执行。
 99 | -  **display_override**
100 |    覆盖 ``_display()`` 方法,该方法用于在系统执行结束时向浏览器发送最终的页面结果。
101 |    这可以让你有自己的显示页面的方法。注意你可能需要使用 ``$this->CI =& get_instance()``
102 |    方法来获取 CI 超级对象,以及使用 ``$this->CI->output->get_output()`` 方法来
103 |    获取最终的显示数据。
104 | -  **cache_override**
105 |    使用你自己的方法来替代 :doc:`输出类 <../libraries/output>` 中的 ``_display_cache()``
106 |    方法,这让你有自己的缓存显示机制。
107 | -  **post_system**
108 |    在最终的页面发送到浏览器之后、在系统的最后期被调用。


--------------------------------------------------------------------------------
/source/database/examples.rst:
--------------------------------------------------------------------------------
  1 | ##################################
  2 | 数据库快速入门: 示例代码
  3 | ##################################
  4 | 
  5 | 这个页面包含的示例代码将简单介绍如何使用数据库类。更详细的信息请参考每个函数单独的介绍页面。
  6 | 
  7 | 初始化数据库类
  8 | ===============================
  9 | 
 10 | 下面的代码将根据你的 :doc:`数据库配置 ` 加载并初始化数据库类::
 11 | 
 12 | 	$this->load->database();
 13 | 
 14 | 数据库类一旦载入,你就可以像下面介绍的那样使用它。
 15 | 
 16 | 注意:如果你所有的页面都需要连接数据库,你可以让其自动加载。参见 :doc:`数据库连接 `。
 17 | 
 18 | 多结果标准查询(对象形式)
 19 | =====================================================
 20 | 
 21 | ::
 22 | 
 23 | 	$query = $this->db->query('SELECT name, title, email FROM my_table');
 24 | 	
 25 | 	foreach ($query->result() as $row)
 26 | 	{
 27 | 		echo $row->title;
 28 | 		echo $row->name;
 29 | 		echo $row->email;
 30 | 	}
 31 | 	
 32 | 	echo 'Total Results: ' . $query->num_rows();
 33 | 
 34 | 上面的 ``result()`` 函数返回一个**对象数组**。譬如:``$row->title``
 35 | 
 36 | 多结果标准查询(数组形式)
 37 | ====================================================
 38 | 
 39 | ::
 40 | 
 41 | 	$query = $this->db->query('SELECT name, title, email FROM my_table');
 42 | 	
 43 | 	foreach ($query->result_array() as $row)
 44 | 	{
 45 | 		echo $row['title'];
 46 | 		echo $row['name'];
 47 | 		echo $row['email'];
 48 | 	}
 49 | 
 50 | 上面的 ``result_array()`` 函数返回一个**数组的数组**。譬如:``$row['title']``
 51 | 
 52 | 测试查询结果
 53 | ===================
 54 | 
 55 | 如果你的查询不返回结果,建议使用函数 ``num_rows()`` 来测试::
 56 | 
 57 | 	$query = $this->db->query("YOUR QUERY");
 58 | 	if ($query->num_rows() > 0)
 59 | 	{
 60 | 		foreach ($query->result() as $row)
 61 | 		{
 62 | 			echo $row->title;
 63 | 			echo $row->name;
 64 | 			echo $row->body;
 65 | 		}
 66 | 	}
 67 | 
 68 | 单结果标准查询(对象形式)
 69 | =================================
 70 | 
 71 | ::
 72 | 
 73 | 	$query = $this->db->query('SELECT name FROM my_table LIMIT 1'); 
 74 | 	$row = $query->row();
 75 | 	echo $row->name;
 76 | 
 77 | 上面的 ``row()`` 函数返回一个**对象**。譬如:``$row->name``
 78 | 
 79 | 单结果标准查询(数组形式)
 80 | =================================================
 81 | 
 82 | ::
 83 | 
 84 | 	$query = $this->db->query('SELECT name FROM my_table LIMIT 1');
 85 | 	$row = $query->row_array();
 86 | 	echo $row['name'];
 87 | 
 88 | 上面的 ``row_array()`` 函数返回一个**数组**。譬如:``$row['name']``
 89 | 
 90 | 标准插入
 91 | ===============
 92 | 
 93 | ::
 94 | 
 95 | 	$sql = "INSERT INTO mytable (title, name) VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")";
 96 | 	$this->db->query($sql);
 97 | 	echo $this->db->affected_rows();
 98 | 
 99 | 使用查询构造器查询数据
100 | ===========================
101 | 
102 | :doc:`查询构造器模式 ` 提供给我们一种简单的查询数据的途径::
103 | 
104 | 	$query = $this->db->get('table_name');
105 | 	
106 | 	foreach ($query->result() as $row)
107 | 	{
108 | 		echo $row->title;
109 | 	}
110 | 
111 | 上面的 ``get()`` 函数从给定的表中查询出所有的结果。:doc:`查询构造器 ` 提供了所有数据库操作的快捷函数。
112 | 
113 | 使用查询构造器插入数据
114 | ===========================
115 | 
116 | ::
117 | 
118 | 	$data = array(
119 | 		'title' => $title,
120 | 		'name' => $name,
121 | 		'date' => $date
122 | 	);
123 | 	
124 | 	//
125 | 	// 生成这样的SQL代码: 
126 | 	//   INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
127 | 	//
128 | 	$this->db->insert('mytable', $data);
129 | 
130 | 


--------------------------------------------------------------------------------
/source/helpers/array_helper.rst:
--------------------------------------------------------------------------------
  1 | ############
  2 | 数组辅助库
  3 | ############
  4 | 
  5 | 数组辅助库文件包含了一些帮助你处理数组的函数。
  6 | 
  7 | .. contents::
  8 |   :local:
  9 | 
 10 | .. raw:: html
 11 | 
 12 |   
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('array'); 20 | 21 | 22 | 可用函数 23 | =================== 24 | 25 | 该辅助库有下列可用函数: 26 | 27 | .. php:function:: element($item, $array[, $default = NULL]) 28 | 29 | :param string $item: Item to fetch from the array 30 | :param array $array: Input array 31 | :param bool $default: What to return if the array isn't valid 32 | :returns: NULL on failure or the array item. 33 | :rtype: mixed 34 | 35 | 该函数通过索引获取数组中的元素。它会测试索引是否设置并且有值,如果有值, 36 | 函数将返回该值,如果没有值,默认返回 NULL 或返回通过第三个参数设置的默认值。 37 | 38 | 示例:: 39 | 40 | $array = array( 41 | 'color' => 'red', 42 | 'shape' => 'round', 43 | 'size' => '' 44 | ); 45 | 46 | echo element('color', $array); // returns "red" 47 | echo element('size', $array, 'foobar'); // returns "foobar" 48 | 49 | 50 | .. php:function:: elements($items, $array[, $default = NULL]) 51 | 52 | :param string $item: Item to fetch from the array 53 | :param array $array: Input array 54 | :param bool $default: What to return if the array isn't valid 55 | :returns: NULL on failure or the array item. 56 | :rtype: mixed 57 | 58 | 该函数通过多个索引获取数组中的多个元素。它会测试每一个索引是否设置并且有值, 59 | 如果其中某个索引没有值,返回结果中该索引所对应的元素将被置为 NULL ,或者 60 | 通过第三个参数设置的默认值。 61 | 62 | 示例:: 63 | 64 | $array = array( 65 | 'color' => 'red', 66 | 'shape' => 'round', 67 | 'radius' => '10', 68 | 'diameter' => '20' 69 | ); 70 | 71 | $my_shape = elements(array('color', 'shape', 'height'), $array); 72 | 73 | 上面的函数返回的结果如下:: 74 | 75 | array( 76 | 'color' => 'red', 77 | 'shape' => 'round', 78 | 'height' => NULL 79 | ); 80 | 81 | 你可以通过第三个参数设置任何你想要设置的默认值。 82 | :: 83 | 84 | $my_shape = elements(array('color', 'shape', 'height'), $array, 'foobar'); 85 | 86 | 上面的函数返回的结果如下:: 87 | 88 | array(      89 | 'color' => 'red', 90 | 'shape' => 'round', 91 | 'height' => 'foobar' 92 | ); 93 | 94 | 当你需要将 ``$_POST`` 数组传递到你的模型中时这将很有用,这可以防止用户发送额外的数据 95 | 被写入到你的数据库。 96 | 97 | :: 98 | 99 | $this->load->model('post_model'); 100 | $this->post_model->update( 101 | elements(array('id', 'title', 'content'), $_POST) 102 | ); 103 | 104 | 从上例中可以看出,只有 id、title、content 三个字段被更新。 105 | 106 | 107 | .. php:function:: random_element($array) 108 | 109 | :param array $array: Input array 110 | :returns: A random element from the array 111 | :rtype: mixed 112 | 113 | 传入一个数组,并返回数组中随机的一个元素。 114 | 115 | 使用示例:: 116 | 117 | $quotes = array( 118 | "I find that the harder I work, the more luck I seem to have. - Thomas Jefferson", 119 | "Don't stay in bed, unless you can make money in bed. - George Burns", 120 | "We didn't lose the game; we just ran out of time. - Vince Lombardi", 121 | "If everything seems under control, you're not going fast enough. - Mario Andretti", 122 | "Reality is merely an illusion, albeit a very persistent one. - Albert Einstein", 123 | "Chance favors the prepared mind - Louis Pasteur" 124 | ); 125 | 126 | echo random_element($quotes); -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}img{width:100%;height:auto}} 2 | /*# sourceMappingURL=badge_only.css.map */ 3 | -------------------------------------------------------------------------------- /source/general/helpers.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 辅助函数 3 | ################ 4 | 5 | 辅助函数,顾名思义,是帮助我们完成特定任务的函数。每个辅助函数文件都是某一类 6 | 函数的集合。例如, **URL 辅助函数** 帮助我们创建链接,**表单辅助函数**帮助 7 | 我们创建表单元素,**本文辅助函数** 帮助我们处理文本的格式化,**Cookie 辅助函数** 8 | 帮助我们读取或设置 Cookie ,**文件辅助库** 帮助我们处理文件,等等等等。 9 | 10 | 不同于 CodeIgniter 中的大多数系统,辅助函数没有使用面向对象的方式来实现的。 11 | 它们是简单的过程式函数,每个函数处理一个特定的任务,不依赖于其他的函数。 12 | 13 | CodeIgniter 默认不会自己加载辅助库,所以使用辅助函数的第一步就是加载它。 14 | 一旦加载了,它就可以在你的 :doc:`控制器 <../general/controllers>` 和 15 | :doc:`视图 <../general/views>` 中全局访问了。 16 | 17 | 一般情况下,辅助函数位于 **system/helpers** 或者 **application/helpers** 目录 18 | 目录下。CodeIgniter 首先会查找 **application/helpers** 目录,如果该目录不存在, 19 | 或者你加载的辅助库没有在该目录下找到,CodeIgniter 就会去 *system/helpers/* 目录查找。 20 | 21 | 加载辅助库 22 | ================ 23 | 24 | 可以使用下面的方法简单的加载辅助库:: 25 | 26 | $this->load->helper('name'); 27 | 28 | **name** 参数为辅助库的文件名,去掉 .php 文件后缀以及 _helper 部分。 29 | 30 | 例如,要加载 **URL 辅助库** ,它的文件名为 **url_helper.php** ,你可以这样加载它:: 31 | 32 | $this->load->helper('url'); 33 | 34 | 辅助库可以在你的控制器方法的任何地方加载(甚至可以在你的视图文件中加载,尽管这不是 35 | 个好的实践),只要确保在使用之前加载它就可以了。你可以在你的控制器的构造函数中加载它, 36 | 这样就可以在该控制器的任何方法中使用它,你也可以在某个需要它的函数中单独加载它。 37 | 38 | .. note:: 上面的加载辅助库的方法没有返回值,所以不要将它赋值给变量,直接调用就好了。 39 | 40 | 加载多个辅助库 41 | ======================== 42 | 43 | 如果你需要加载多个辅助库,你可以使用一个数组,像下面这样:: 44 | 45 | $this->load->helper( 46 | array('helper1', 'helper2', 'helper3') 47 | ); 48 | 49 | 自动加载辅助库 50 | ==================== 51 | 52 | 如果你需要在你的整个应用程序中使用某个辅助库,你可以将其设置为在 CodeIgniter 初始化时 53 | 自动加载它。打开 **application/config/autoload.php** 文件然后将你想加载的辅助库添加到 54 | autoload 数组中。 55 | 56 | 使用辅助库 57 | ============== 58 | 59 | 一旦你想要使用的辅助库被加载,你就可以像使用标准的 PHP 函数一样使用它们。 60 | 61 | 譬如,要在你的视图文件中使用 ``anchor()`` 函数创建一个链接,你可以这样做:: 62 | 63 | 64 | 65 | 其中,"Click Here" 是链接的名称,"blog/comments" 是你希望链接到 66 | controller/method 的 URI 。 67 | 68 | 扩展辅助库 69 | =================== 70 | 71 | 为了扩展辅助库,你需要在 **application/helpers/** 目录下新建一个文件, 72 | 文件名和已存在的辅助库文件名一样,但是要加上 **MY\_** 前缀(这个可以配置, 73 | 见下文)。 74 | 75 | 如果你只是想往现有类中添加一些功能,譬如增加一两个方法,或者修改辅助库中的 76 | 某个函数,这时替换整个类感觉就有点杀鸡用牛刀了。在这种情况下,最好的方法是 77 | 扩展类。 78 | 79 | .. note:: “扩展”一词在这里可能不是很恰当,因为辅助库函数都是过程式的独立函数, 80 | 在传统编程中并不能被扩展。不过在 CodeIgniter 中,你可以向辅助库中添加函数, 81 | 或者使用你自己的函数替代辅助库中的函数。 82 | 83 | 譬如,要扩展原始的 **数组辅助库** ,首先你要创建一个文件 **application/helpers/MY_array_helper.php** , 84 | 然后像下面这样添加或重写函数:: 85 | 86 | // any_in_array() is not in the Array Helper, so it defines a new function 87 | function any_in_array($needle, $haystack) 88 | { 89 | $needle = is_array($needle) ? $needle : array($needle); 90 | 91 | foreach ($needle as $item) 92 | { 93 | if (in_array($item, $haystack)) 94 | { 95 | return TRUE; 96 | } 97 | } 98 | 99 | return FALSE; 100 | } 101 | 102 | // random_element() is included in Array Helper, so it overrides the native function 103 | function random_element($array) 104 | { 105 | shuffle($array); 106 | return array_pop($array); 107 | } 108 | 109 | 设置自定义前缀 110 | ----------------------- 111 | 112 | 用于扩展辅助库的文件名前缀和扩展类库和核心类是一样的。要自定义这个前缀,你可以打开 113 | **application/config/config.php** 文件然后找到这项:: 114 | 115 | $config['subclass_prefix'] = 'MY_'; 116 | 117 | 请注意所有原始的 CodeIgniter 类库都以 **CI\_** 开头,所以请不要使用这个 118 | 作为你的自定义前缀。 119 | 120 | 然后? 121 | ========= 122 | 123 | 在目录里你可以找到所有的辅助库清单,你可以浏览下它们看看它们都是做什么的。 -------------------------------------------------------------------------------- /source/database/connecting.rst: -------------------------------------------------------------------------------- 1 | ########################### 2 | 连接你的数据库 3 | ########################### 4 | 5 | 有两种方法连接数据库: 6 | 7 | 自动连接 8 | ======================== 9 | 10 | “自动连接” 特性将在每一个页面加载时自动实例化数据库类。要启用“自动连接”, 11 | 可在 ``application/config/autoload.php`` 中的 library 数组里添加 database:: 12 | 13 | $autoload['libraries'] = array('database'); 14 | 15 | 手动连接 16 | =================== 17 | 18 | 如果你只有一部分页面需要数据库连接,你可以在那些有需要的函数里手工添加 19 | 如下代码来连接数据库,或者写在类的构造函数里,让整个类都可以访问: 20 | 21 | :: 22 | 23 | $this->load->database(); 24 | 25 | 如果 ``database()`` 函数没有指定第一个参数,它将使用数据库配置文件中 26 | 指定的组连接数据库。对大多数人而言,这是首选方案。 27 | 28 | 可用的参数 29 | -------------------- 30 | 31 | #. 数据库连接值,用数组或DSN字符串传递; 32 | #. TRUE/FALSE (boolean) - 是否返回连接ID(参考下文的“连接多数据库”); 33 | #. TRUE/FALSE (boolean) - 是否启用查询构造器类,默认为 TRUE 。 34 | 35 | 手动连接到数据库 36 | --------------------------------- 37 | 38 | 这个函数的第一个参数是**可选的**,被用来从你的配置文件中 39 | 指定一个特定的数据库组,甚至可以使用没有在配置文件中定义的 40 | 数据库连接值。下面是例子: 41 | 42 | 从你的配置文件中选择一个特定分组:: 43 | 44 | $this->load->database('group_name'); 45 | 46 | 其中 ``group_name`` 是你的配置文件中连接组的名字。 47 | 48 | 连接一个完全手动指定的数据库,可以传一个数组参数:: 49 | 50 | $config['hostname'] = 'localhost'; 51 | $config['username'] = 'myusername'; 52 | $config['password'] = 'mypassword'; 53 | $config['database'] = 'mydatabase'; 54 | $config['dbdriver'] = 'mysqli'; 55 | $config['dbprefix'] = ''; 56 | $config['pconnect'] = FALSE; 57 | $config['db_debug'] = TRUE; 58 | $config['cache_on'] = FALSE; 59 | $config['cachedir'] = ''; 60 | $config['char_set'] = 'utf8'; 61 | $config['dbcollat'] = 'utf8_general_ci'; 62 | $this->load->database($config); 63 | 64 | 这些值的详细信息请参考 :doc: `数据库配置 ` 页面。 65 | 66 | .. note:: 对于 PDO 驱动,你应该使用 ``$config['dsn']`` 取代 'hostname' 和 'database' 参数: 67 | 68 | | 69 | | $config['dsn'] = 'mysql:host=localhost;dbname=mydatabase'; 70 | 71 | 或者你可以使用数据源名称(DSN,Data Source Name)作为参数,DSN 的格式必须类似于下面这样:: 72 | 73 | $dsn = 'dbdriver://username:password@hostname/database'; 74 | $this->load->database($dsn); 75 | 76 | 当用 DSN 字符串连接时,要覆盖默认配置,可以像添加查询字符串一样添加配置变量。 77 | 78 | :: 79 | 80 | $dsn = 'dbdriver://username:password@hostname/database?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=/path/to/cache'; 81 | $this->load->database($dsn); 82 | 83 | 连接到多个数据库 84 | ================================ 85 | 86 | 如果你需要同时连接到多个不同的数据库,可以这样:: 87 | 88 | $DB1 = $this->load->database('group_one', TRUE); 89 | $DB2 = $this->load->database('group_two', TRUE); 90 | 91 | 注意:将 "group_one" 和 "group_two" 修改为你要连接的组名称 92 | (或者像上面介绍的那样传入连接值数组) 93 | 94 | 第二个参数 TRUE 表示函数将返回数据库对象。 95 | 96 | .. note:: 当你使用这种方式连接数据库时,你将通过你的对象名来执行数据库命令, 97 | 而不再是通过这份指南中通篇介绍的,就像下面这样的语法了: 98 | 99 | | 100 | | $this->db->query(); 101 | | $this->db->result(); 102 | | etc... 103 | | 104 | | 取而代之的,你将这样执行数据库命令: 105 | | 106 | | $DB1->query(); 107 | | $DB1->result(); 108 | | etc... 109 | 110 | .. note:: 如果你只是需要切换到同一个连接的另一个不同的数据库,你没必要创建 111 | 独立的数据库配置,你可以像下面这样切换到另一个数据库: 112 | 113 | | $this->db->db_select($database2_name); 114 | 115 | 重新连接 / 保持连接有效 116 | =========================================== 117 | 118 | 当你在处理一些重量级的 PHP 操作时(例如处理图片),如果超过了数据库的超时值, 119 | 你应该考虑在执行后续查询之前先调用 ``reconnect()`` 方法向数据库发送 ping 命令, 120 | 这样可以优雅的保持连接有效或者重新建立起连接。 121 | 122 | :: 123 | 124 | $this->db->reconnect(); 125 | 126 | 手动关闭连接 127 | =============================== 128 | 129 | 虽然 CodeIgniter 可以智能的管理并自动关闭数据库连接,你仍可以用下面的方法显式的关闭连接: 130 | 131 | :: 132 | 133 | $this->db->close(); -------------------------------------------------------------------------------- /source/database/caching.rst: -------------------------------------------------------------------------------- 1 | ###################### 2 | 数据库缓存类 3 | ###################### 4 | 5 | 数据库缓存类允许你把数据库查询结果保存在文本文件中以减少数据库访问。 6 | 7 | .. important:: 当缓存启用时,本类会被数据库驱动自动加载,切勿手动加载。 8 | 9 | .. important:: 并非所有查询结果都能被缓存,请仔细阅读本页内容。 10 | 11 | 启用缓存 12 | ================ 13 | 14 | 启用缓存需要三步: 15 | 16 | - 在服务器上创建一个可写的目录以便保存缓存文件; 17 | - 通过文件 application/config/database.php 中的 cachedir 参数设置其目录路径; 18 | - 通过将文件 application/config/database.php 中的 cache_on 参数设置为 TRUE, 19 | 也可以用下面的方法手动配置。 20 | 21 | 缓存一旦启用,每一次加载页面时,只要该页面含有数据库查询就会自动缓存起来。 22 | 23 | 缓存是如何工作的? 24 | ====================== 25 | 26 | 当你在访问页面时,CodeIgniter 的查询缓存系统会自动运行。如果缓存被启用, 27 | 当页面第一次加载时,查询结果对象会被序列化并保存到服务器上的一个文本文件中。 28 | 当下次再访问该页面时,会直接使用缓存文件而不用访问数据库了,这样, 29 | 在已缓存的页面,你的数据库访问会降为 0 。 30 | 31 | 只有读类型(SELECT)的查询可以被缓存,因为只有这类查询才会产生结果。 32 | 写类型的查询(INSERT、UPDATE 等)并不会生成结果,所以不会被缓存。 33 | 34 | 缓存文件永不过期,所有的查询只要缓存下来以后除非你删除它们否则将一直可用。 35 | 你可以针对特定的页面来删除缓存,或者也可以清空掉所有的缓存。一般来说, 36 | 你可以在某些事件发生时(如数据库中添加了数据)用下面的函数来清除缓存。 37 | 38 | 缓存能够提升站点的性能吗? 39 | ============================================= 40 | 41 | 缓存能否获得性能增益,取决于很多因素。如果你有一个低负荷而高度优化的 42 | 数据库,你可能不会看到性能的提升。而如果你的数据库正在被大量访问, 43 | 您可能会看到缓存后的性有所提升,前提是你的文件系统并没有太多的开销。 44 | 要记住一点的是,缓存只是简单的改变了数据获取的途径而已,从访问数据库 45 | 变成了访问文件系统。 46 | 47 | 例如,在一些集群服务器环境中,由于文件系统的操作太过频繁,缓存其实是 48 | 有害的。在共享的单一服务器环境中,缓存才可能有益。不幸的是,关于是否 49 | 需要缓存你的数据库这个问题并没有唯一的答案,这完全取决于你的情况。 50 | 51 | 缓存文件是如何存储的? 52 | =========================== 53 | 54 | CodeIgniter 将每个查询都缓存到它单独的缓存文件中,根据调用的控制器方法 55 | 缓存文件被进一步组织到各自的子目录中。更准确的说,子目录是使用你 URI 56 | 的前两段(控制器名 和 方法名)命名的。 57 | 58 | 例如,你有一个 blog 控制器和一个 comments 方法,并含有三个不同的查询。 59 | 缓存系统将创建一个名为 blog+comments 的目录,并在该目录下生成三个 60 | 缓存文件。 61 | 62 | 如果你的 URI 中含有动态查询时(例如使用分页时),每个查询实例都会 63 | 生成它单独的缓存文件,因此,最终可能会出现缓存文件数是你页面中的 64 | 查询次数的好几倍这样的情况。 65 | 66 | 管理你的缓存文件 67 | ========================= 68 | 69 | 由于缓存文件不会过期,那么你的应用程序中应该有删除缓存的机制, 70 | 例如,我们假设你有一个博客并允许用户评论,每当提交一个新评论时, 71 | 你都应该删除掉关于显示评论的那个控制器方法对应的缓存文件。下面将介绍 72 | 有两种不同的方法用来删除缓存数据。 73 | 74 | 不是所有的数据库方法都兼容缓存 75 | ============================================ 76 | 77 | 最后,我们必须得指出被缓存的结果对象只是一个简化版的结果对象, 78 | 正因为这样,有几个查询结果的方法无法使用。 79 | 80 | 下面列出的方法是无法在缓存的结果对象上使用的: 81 | 82 | - num_fields() 83 | - field_names() 84 | - field_data() 85 | - free_result() 86 | 87 | 同时,result_id 和 conn_id 这两个 id 也无法使用,因为这两个 id 88 | 只适用于实时的数据库操作。 89 | 90 | ****************** 91 | 函数参考 92 | ****************** 93 | 94 | $this->db->cache_on() / $this->db->cache_off() 95 | ================================================ 96 | 97 | 用于手工启用/禁用缓存,当你不想缓存某些查询时,这两个方法会很有用。 98 | 例子:: 99 | 100 | // Turn caching on 101 | $this->db->cache_on(); 102 | $query = $this->db->query("SELECT * FROM mytable"); 103 | 104 | // Turn caching off for this one query 105 | $this->db->cache_off(); 106 | $query = $this->db->query("SELECT * FROM members WHERE member_id = '$current_user'"); 107 | 108 | // Turn caching back on 109 | $this->db->cache_on(); 110 | $query = $this->db->query("SELECT * FROM another_table"); 111 | 112 | $this->db->cache_delete() 113 | ========================== 114 | 115 | 删除特定页面的缓存文件,这当你更新你的数据库之后需要清除缓存时很有用。 116 | 117 | 缓存系统根据你访问页面的 URI 来将缓存写入到相应的缓存文件中去,例如, 118 | 如果你在访问 example.com/index.php/blog/comments 这个页面,缓存系统 119 | 会将缓存文件保存到 blog+comments 目录下,要删除这些缓存文件,你可以使用:: 120 | 121 | $this->db->cache_delete('blog', 'comments'); 122 | 123 | 如果你没提供任何参数,将会清除当前 URI 对应的缓存文件。 124 | 125 | $this->db->cache_delete_all() 126 | =============================== 127 | 128 | 清除所有的缓存文件,例如:: 129 | 130 | $this->db->cache_delete_all(); 131 | 132 | -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/footer.html: -------------------------------------------------------------------------------- 1 |
2 | {% if next or prev %} 3 | 11 | {% endif %} 12 | 13 | {% if pagename != 'search' %} 14 |
15 | {% if pagename != 'general/welcome' and pagename != 'index' and pagename != 'DCO' and pagename != 'license' %} 16 | 17 |
18 | 19 | {% endif %} 20 | 21 |
22 |
23 | 32 |
33 |
34 |
35 |
36 | 37 | 38 | 49 | 50 |
51 | {% endif %} 52 | 53 |
54 | 55 |
56 |

57 | {%- if show_copyright %} 58 | {%- if hasdoc('copyright') %} 59 | {% trans path=pathto('copyright'), copyright=copyright|e %}© 版权所有 {{ copyright }}.{% endtrans %} 60 | {%- else %} 61 | {% trans copyright=copyright|e %}© 版权所有 {{ copyright }}.{% endtrans %} 62 | {%- endif %} 63 | {%- endif %} 64 | 65 | {%- if last_updated %} 66 | {% trans last_updated=last_updated|e %} 最后修改: {{ last_updated }}.{% endtrans %} 67 | {%- endif %} 68 |

69 | 70 |

aneasystone 制作的手册为基础构建

71 |
72 | 73 | {% trans %}基于 Sphinx 并使用 Read the Docs 提供的风格构建{% endtrans %}。 74 | 75 |
-------------------------------------------------------------------------------- /source/contributing/index.rst: -------------------------------------------------------------------------------- 1 | ################################## 2 | 向 CodeIgniter 贡献你的力量 3 | ################################## 4 | 5 | .. toctree:: 6 | :titlesonly: 7 | 8 | ../documentation/index 9 | ../DCO 10 | 11 | CodeIgniter 是一个社区驱动的项目,它会接受从社区里贡献的文档和代码。 12 | 这些贡献都是通过 GitHub 上 `CodeIgniter 代码仓库 `_ 13 | 的 Issues 或者 `Pull Requests `_ 14 | 的形式来完成的。 15 | 16 | Issues 是一种快速提交 bug 的方式,如果你发现了一个 CodeIgniter 的 bug 或文档错误,那么请先 17 | 看看下面这几点: 18 | 19 | - 是否已经存在一个打开的 Issue 20 | - 该 Issue 是否已经被修复了(检查下 delevop 分支的代码,或者已关闭的 Issues) 21 | - 这个 bug 很明显你一个人就能修复吗? 22 | 23 | 提交 Issues 是非常有用的,但是更好的做法是发起一个 Pull Request ,具体的做法是先 fork 24 | 主仓库的代码,然后将修改的代码提交到你自己的副本中。这需要你会使用版本控制系统 Git 。 25 | 26 | ******* 27 | 支持 28 | ******* 29 | 30 | 请注意,GitHub 并不是用来回答一般的技术支持类问题的! 31 | 32 | 如果你在使用 CodeIgniter 的某个功能时遇到了问题,请到论坛提问。 33 | 34 | 如果你不知道自己做的对不对,或者不确定自己找到了一个 bug ,也请先到论坛里提问。 35 | 36 | **************************** 37 | 提交好问题的技巧 38 | **************************** 39 | 40 | 使用描述性的标题(如:解析器类在处理逗号时出错),而不是使用模糊不清的标题(如:我的代码出错了) 41 | 42 | 在一份报告中只提交一个问题。 43 | 44 | 在问题中指出 CodeIgniter 的版本(如:3.0-develop),以及出问题的组件(如果你知道的话)(如:解析器类) 45 | 46 | 解释清楚你希望出现什么结果,以及当前出现的结果是什么。 47 | 如果有错误信息的话,并附上错误信息和堆栈信息。 48 | 49 | 如果有助于阐述你的问题的话,你可以包含少量的代码片段。 50 | 如果有大量的代码或截图的话,可以使用类似于 pastebin 或者 dropbox 这样的服务,不要在问题报告中包含这些内容。 51 | 为这些内容设置一个合理的过期时间,至少在问题被解决或关闭之前确保它们能访问。 52 | 53 | 如果你知道如何修复该问题,你可以 fork 并在你自己的分支中修改,然后提交一个 pull request 。 54 | 并将上面说的问题报告作为 pull request 的一部分。 55 | 56 | 如果能在问题报告中描述问题重现的详细步骤,那将是极好的。 57 | 如果你还能提供一个单元测试用例来重现该错误,那将更好,因为这给了修复这个问题的人一个更清晰的目标。 58 | 59 | 60 | ********** 61 | 指导手册 62 | ********** 63 | 64 | 这里是如何提交 Pull Requests 的一些指南,如果你提交的 Pull Requests 没有遵循这篇指南中提出的这些, 65 | 你的提交可能会被拒绝并要求你重新提交。这可能听起来有点难,但是为了保证我们的代码质量这是必须要做的。 66 | 67 | PHP 代码规范 68 | ============== 69 | 70 | 所有的代码都必须符合 :doc:`代码规范指南 <../general/styleguide>`,它其实就是 71 | `Allman 缩进风格 `_ 72 | 加上下划线规则以及可读的操作符。遵循代码规则可以让代码的风格保持一致,同时也意味着代的更可读性更好。 73 | 74 | 文档 75 | ============= 76 | 77 | 如果你的修改同时也需要在文档中另加说明,那么你也需要在文档中加上它。新的类、方法、参数、默认值的修改 78 | 等等这些都需要对文档做相应的调整。每一处修改也必须要在代码的变更日志(change-log)中进行更新。另外, 79 | PHP 的文档注释块(PHPDoc blocks)也要修改。 80 | 81 | 兼容性 82 | ============= 83 | 84 | CodeIgniter 推荐使用 PHP 5.4 或更高的版本,但是同时它也对 PHP 5.2.4 保持兼容,所以所有提交的代码都必须 85 | 满足这一点。如果你用到了 PHP 5.3 (或以上版本)中的函数或新特性,这些代码需要回退到 PHP 5.2.4 版本的。 86 | 87 | 分支 88 | ========= 89 | 90 | CodeIgniter 使用了 `Git-Flow `_ 分支模型, 91 | 这要求所有的 pull request 应该提交到 develop 分支,develop 分支是正在开发的打算在下一版发布的分支, 92 | master 分支总是包含最新的稳定版并保持干净,这样可以在譬如出现紧急安全漏洞时快速的在 master 分支代码 93 | 上打上补丁并发布新的版本,而无需担心新加的功能会影响它。正是因为这个原因,所有的提交都应该在 develop 94 | 分支,发送到 master 分支的提交会被自动关闭。如果你的提交中包含多处修改,请将每一个修改都放到你独立的分支中。 95 | 96 | 一次只做一件事:一个 pull request 应该只包含一个修改。这不是意味着说一次提交,而是一次修改(尽管大多数时候 97 | 一次提交就是一次修改)。这样做的原因是如果你在同一个 pull request 中修改了 X 和 Y ,但是我们希望能合并 X 98 | 同时不想合并 Y ,这时我们就无法合并你的请求。你可以使用 Git-Flow 分支模型为每一个功能创建一个独立的分支, 99 | 然后提交两个请求。 100 | 101 | 签名 102 | ======= 103 | 104 | 你必须对你的工作进行签名,保证这些工作是你原创的或者不是你原创的但是你有将它们添加到开源项目中的权利。 105 | 在 Git 中签名并没有得到足够重视,所以你几乎用不到 `--signoff` 参数,但是在你提交代码到 CodeIgniter 时, 106 | 必须使用该参数。 107 | 108 | .. code-block:: bash 109 | 110 | git commit --signoff 111 | 112 | 或简写: 113 | 114 | .. code-block:: bash 115 | 116 | git commit -s 117 | 118 | 这个命令会根据你 git 的配置信息在你的提交中添加签名,例如: 119 | 120 | Signed-off-by: John Q Public 121 | 122 | 如果你正在使用 Tower 客户端,在提交窗口中会有一个 "Sign-Off" 复选框,或者你可以将 ``git commit`` 设置成 123 | ``git commit -s`` 的别名,这样你就不用关心提交中的签名了。 124 | 125 | 通过这种方式对你的工作进行签名,说明你将遵守 DCO (Developer's Certificate or Origin),:doc:`/DCO` 126 | 申明的当前版本位于这份文档的根目录下。 127 | -------------------------------------------------------------------------------- /source/installation/upgrade_150.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 1.4.1 to 1.5.0 3 | ############################# 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.4.1. If you have not upgraded to that version please do so first. 7 | 8 | Before performing an update you should take your site offline by 9 | replacing the index.php file with a static one. 10 | 11 | Step 1: Update your CodeIgniter files 12 | ===================================== 13 | 14 | Replace these files and directories in your "system" folder with the new 15 | versions: 16 | 17 | - application/config/user_agents.php (new file for 1.5) 18 | - application/config/smileys.php (new file for 1.5) 19 | - codeigniter/ 20 | - database/ (new folder for 1.5. Replaces the "drivers" folder) 21 | - helpers/ 22 | - language/ 23 | - libraries/ 24 | - scaffolding/ 25 | 26 | .. note:: If you have any custom developed files in these folders please 27 | make copies of them first. 28 | 29 | Step 2: Update your database.php file 30 | ===================================== 31 | 32 | Open your application/config/database.php file and add these new items:: 33 | 34 | 35 | $db['default']['cache_on'] = FALSE; 36 | $db['default']['cachedir'] = ''; 37 | 38 | Step 3: Update your config.php file 39 | =================================== 40 | 41 | Open your application/config/config.php file and ADD these new items:: 42 | 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Class Extension Prefix 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This item allows you to set the filename/classname prefix when extending 50 | | native libraries. For more information please see the user guide: 51 | | 52 | | http://codeigniter.com/user_guide/general/core_classes.html 53 | | http://codeigniter.com/user_guide/general/creating_libraries.html 54 | | 55 | */ 56 | $config['subclass_prefix'] = 'MY_'; 57 | 58 | /* 59 | |-------------------------------------------------------------------------- 60 | | Rewrite PHP Short Tags 61 | |-------------------------------------------------------------------------- 62 | | 63 | | If your PHP installation does not have short tag support enabled CI 64 | | can rewrite the tags on-the-fly, enabling you to utilize that syntax 65 | | in your view files. Options are TRUE or FALSE (boolean) 66 | | 67 | */ 68 | $config['rewrite_short_tags'] = FALSE; 69 | 70 | In that same file REMOVE this item:: 71 | 72 | 73 | /* 74 | |-------------------------------------------------------------------------- 75 | | Enable/Disable Error Logging 76 | |-------------------------------------------------------------------------- 77 | | 78 | | If you would like errors or debug messages logged set this variable to 79 | | TRUE (boolean). Note: You must set the file permissions on the "logs" folder 80 | | such that it is writable. 81 | | 82 | */ 83 | $config['log_errors'] = FALSE; 84 | 85 | Error logging is now disabled simply by setting the threshold to zero. 86 | 87 | Step 4: Update your main index.php file 88 | ======================================= 89 | 90 | If you are running a stock index.php file simply replace your version 91 | with the new one. 92 | 93 | If your index.php file has internal modifications, please add your 94 | modifications to the new file and use it. 95 | 96 | Step 5: Update your user guide 97 | ============================== 98 | 99 | Please also replace your local copy of the user guide with the new 100 | version. 101 | -------------------------------------------------------------------------------- /source/libraries/benchmark.rst: -------------------------------------------------------------------------------- 1 | ################## 2 | 基准测试类 3 | ################## 4 | 5 | CodeIgniter 有一个一直都是启用状态的基准测试类,用于计算两个标记点之间的时间差。 6 | 7 | .. note:: 该类是由系统自动加载,无需手动加载。 8 | 9 | 另外,基准测试总是在框架被调用的那一刻开始,在输出类向浏览器发送最终的视图之前结束。 10 | 这样可以显示出整个系统执行的精确时间。 11 | 12 | .. contents:: 13 | :local: 14 | 15 | .. raw:: html 16 | 17 |
18 | 19 | ************************* 20 | 使用基准测试类 21 | ************************* 22 | 23 | 基准测试类可以在你的 :doc:`控制器 `、:doc:`视图 ` 24 | 以及 :doc:`模型 ` 中使用。 25 | 26 | 使用流程如下: 27 | 28 | #. 标记一个起始点 29 | #. 标记一个结束点 30 | #. 使用 elapsed_time 函数计算时间差。 31 | 32 | 这里是个真实的代码示例:: 33 | 34 | $this->benchmark->mark('code_start'); 35 | 36 | // Some code happens here 37 | 38 | $this->benchmark->mark('code_end'); 39 | 40 | echo $this->benchmark->elapsed_time('code_start', 'code_end'); 41 | 42 | .. note:: "code_start" 和 "code_end" 这两个单词是随意的,它们只是两个用于标记 43 | 的单词而已,你可以任意使用其他你想使用的单词,另外,你也可以设置多个标记点。 44 | 看如下示例:: 45 | 46 | $this->benchmark->mark('dog'); 47 | 48 | // Some code happens here 49 | 50 | $this->benchmark->mark('cat'); 51 | 52 | // More code happens here 53 | 54 | $this->benchmark->mark('bird'); 55 | 56 | echo $this->benchmark->elapsed_time('dog', 'cat'); 57 | echo $this->benchmark->elapsed_time('cat', 'bird'); 58 | echo $this->benchmark->elapsed_time('dog', 'bird'); 59 | 60 | 61 | 在 性能分析器 中使用基准测试点 62 | ==================================== 63 | 64 | 如果你希望你的基准测试数据显示在 :doc:`性能分析器 ` 中, 65 | 那么你的标记点就需要成对出现,而且标记点名称需要以 _start 和 _end 结束, 66 | 每一对的标记点名称应该一致。例如:: 67 | 68 | $this->benchmark->mark('my_mark_start'); 69 | 70 | // Some code happens here... 71 | 72 | $this->benchmark->mark('my_mark_end'); 73 | 74 | $this->benchmark->mark('another_mark_start'); 75 | 76 | // Some more code happens here... 77 | 78 | $this->benchmark->mark('another_mark_end'); 79 | 80 | 阅读 :doc:`性能分析器 ` 页面了解更多信息。 81 | 82 | 显示总执行时间 83 | =============================== 84 | 85 | 如果你想显示从 CodeIgniter 运行开始到最终结果输出到浏览器之间花费的总时间, 86 | 只需简单的将下面这行代码放入你的视图文件中:: 87 | 88 | benchmark->elapsed_time();?> 89 | 90 | 你大概也注意到了,这个方法和上面例子中的介绍的那个计算两个标记点之间时间差的方法是一样的, 91 | 只是不带任何参数。当不设参数时,CodeIgniter 在向浏览器输出最终结果之前不会停止计时,所以 92 | 无论你在哪里使用该方法,输出的计时结果都是总执行时间。 93 | 94 | 如果你不喜欢纯 PHP 语法的话,也可以在你的视图中使用另一种伪变量的方式来显示总执行时间:: 95 | 96 | {elapsed_time} 97 | 98 | .. note:: 如果你想在你的控制器方法中进行基准测试,你需要设置你自己的标记起始点和结束点。 99 | 100 | 显示内存占用 101 | ============================= 102 | 103 | 如果你的 PHP 在安装时使用了 --enable-memory-limit 参数进行编译,你就可以在你的视图文件中 104 | 使用下面这行代码来显示整个系统所占用的内存大小:: 105 | 106 | benchmark->memory_usage();?> 107 | 108 | .. note:: 这个方法只能在视图文件中使用,显示的结果代表整个应用所占用的内存大小。 109 | 110 | 如果你不喜欢纯 PHP 语法的话,也可以在你的视图中使用另一种伪变量的方式来显示占用的内存大小:: 111 | 112 | {memory_usage} 113 | 114 | 115 | *************** 116 | 类参考 117 | *************** 118 | 119 | .. php:class:: CI_Benchmark 120 | 121 | .. php:method:: mark($name) 122 | 123 | :param string $name: the name you wish to assign to your marker 124 | :rtype: void 125 | 126 | 设置一个基准测试的标记点。 127 | 128 | .. php:method:: elapsed_time([$point1 = ''[, $point2 = ''[, $decimals = 4]]]) 129 | 130 | :param string $point1: a particular marked point 131 | :param string $point2: a particular marked point 132 | :param int $decimals: number of decimal places for precision 133 | :returns: Elapsed time 134 | :rtype: string 135 | 136 | 计算并返回两个标记点之间的时间差。 137 | 138 | 如果第一个参数为空,方法将返回 ``{elapsed_time}`` 伪变量。这用于在视图中 139 | 显示整个系统的执行时间,输出类将在最终输出时使用真实的总执行时间替换掉这个伪变量。 140 | 141 | 142 | .. php:method:: memory_usage() 143 | 144 | :returns: Memory usage info 145 | :rtype: string 146 | 147 | 只是简单的返回 ``{memory_usage}`` 伪变量。 148 | 149 | 该方法可以在视图的任意位置使用,直到最终输出页面时 :doc:`输出类 ` 150 | 才会将真实的值替换掉这个伪变量。 -------------------------------------------------------------------------------- /source/general/models.rst: -------------------------------------------------------------------------------- 1 | ###### 2 | 模型 3 | ###### 4 | 5 | 模型对于那些想使用更传统的 MVC 模式的人来说是可选的。 6 | 7 | .. contents:: 本页内容 8 | 9 | 什么是模型? 10 | ================ 11 | 12 | 模型是专门用来和数据库打交道的 PHP 类。例如,假设你使用 CodeIgniter 13 | 管理一个博客,那么你应该会有一个用于插入、更新以及获取博客数据的模型类。 14 | 这里是一个模型类的例子:: 15 | 16 | class Blog_model extends CI_Model { 17 | 18 | public $title; 19 | public $content; 20 | public $date; 21 | 22 | public function __construct() 23 | { 24 | // Call the CI_Model constructor 25 | parent::__construct(); 26 | } 27 | 28 | public function get_last_ten_entries() 29 | { 30 | $query = $this->db->get('entries', 10); 31 | return $query->result(); 32 | } 33 | 34 | public function insert_entry() 35 | { 36 | $this->title = $_POST['title']; // please read the below note 37 | $this->content = $_POST['content']; 38 | $this->date = time(); 39 | 40 | $this->db->insert('entries', $this); 41 | } 42 | 43 | public function update_entry() 44 | { 45 | $this->title = $_POST['title']; 46 | $this->content = $_POST['content']; 47 | $this->date = time(); 48 | 49 | $this->db->update('entries', $this, array('id' => $_POST['id'])); 50 | } 51 | 52 | } 53 | 54 | .. note:: 上面的例子中使用了 :doc:`查询构造器 <../database/query_builder>` 数据库方法。 55 | 56 | .. note:: 为了保证简单,我们在这个例子中直接使用了 ``$_POST`` 数据,这其实是个不好的实践, 57 | 一个更通用的做法是使用 :doc:`输入库 <../libraries/input>` 的 ``$this->input->post('title')``。 58 | 59 | 剖析模型 60 | ================== 61 | 62 | 模型类位于你的 **application/models/** 目录下,如果你愿意,也可以在里面创建子目录。 63 | 64 | 模型类的基本原型如下:: 65 | 66 | class Model_name extends CI_Model { 67 | 68 | public function __construct() 69 | { 70 | parent::__construct(); 71 | } 72 | 73 | } 74 | 75 | 其中,**Model_name** 是类的名字,类名的第一个字母 **必须** 大写,其余部分小写。确保你的类 76 | 继承 CI_Model 基类。 77 | 78 | 文件名和类名应该一致,例如,如果你的类是这样:: 79 | 80 | class User_model extends CI_Model { 81 | 82 | public function __construct() 83 | { 84 | parent::__construct(); 85 | } 86 | 87 | } 88 | 89 | 那么你的文件名应该是这样:: 90 | 91 | application/models/User_model.php 92 | 93 | 加载模型 94 | =============== 95 | 96 | 你的模型一般会在你的 :doc:`控制器 ` 的方法中加载并调用, 97 | 你可以使用下面的方法来加载模型:: 98 | 99 | $this->load->model('model_name'); 100 | 101 | 如果你的模型位于一个子目录下,那么加载时要带上你的模型所在目录的相对路径, 102 | 譬如,如果你的模型位于 *application/models/blog/Queries.php* , 103 | 你可以这样加载它:: 104 | 105 | $this->load->model('blog/queries'); 106 | 107 | 加载之后,你就可以通过一个和你的类同名的对象访问模型中的方法。 108 | :: 109 | 110 | $this->load->model('model_name'); 111 | 112 | $this->model_name->method(); 113 | 114 | 如果你想将你的模型对象赋值给一个不同名字的对象,你可以使用 ``$this->load->model()`` 115 | 方法的第二个参数:: 116 | 117 | $this->load->model('model_name', 'foobar'); 118 | 119 | $this->foobar->method(); 120 | 121 | 这里是一个例子,该控制器加载一个模型,并处理一个视图:: 122 | 123 | class Blog_controller extends CI_Controller { 124 | 125 | public function blog() 126 | { 127 | $this->load->model('blog'); 128 | 129 | $data['query'] = $this->blog->get_last_ten_entries(); 130 | 131 | $this->load->view('blog', $data); 132 | } 133 | } 134 | 135 | 136 | 模型的自动加载 137 | =================== 138 | 139 | 如果你发现你有一个模型需要在整个应用程序中使用,你可以让 CodeIgniter 140 | 在系统初始化时自动加载它。打开 **application/config/autoload.php** 文件, 141 | 并将该模型添加到 autoload 数组中。 142 | 143 | 连接数据库 144 | =========================== 145 | 146 | 当模型加载之后,它 **并不会** 自动去连接你的数据库,下面是一些关于 147 | 数据库连接的选项: 148 | 149 | - 你可以在控制器或模型中使用 :doc:`标准的数据库方法 <../database/connecting>` 连接数据库。 150 | - 你可以设置第三个参数为 TRUE 让模型在加载时自动连接数据库,会使用你的数据库配置文件中的配置:: 151 | 152 | $this->load->model('model_name', '', TRUE); 153 | 154 | - 你还可以通过第三个参数传一个数据库连接配置:: 155 | 156 | $config['hostname'] = 'localhost'; 157 | $config['username'] = 'myusername'; 158 | $config['password'] = 'mypassword'; 159 | $config['database'] = 'mydatabase'; 160 | $config['dbdriver'] = 'mysqli'; 161 | $config['dbprefix'] = ''; 162 | $config['pconnect'] = FALSE; 163 | $config['db_debug'] = TRUE; 164 | 165 | $this->load->model('model_name', '', $config); -------------------------------------------------------------------------------- /source/tutorial/static_pages.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | 加载静态内容 3 | ############ 4 | 5 | **Note:** 这篇教程假设你已经下载好 CodeIgniter ,并将其 :doc:`安装 <../installation/index>` 6 | 到你的开发环境。 7 | 8 | 你要做的第一件事情是新建一个 **控制器** 来处理静态页面,控制器就是一个简单的类, 9 | 用来完成你的工作,它是你整个 Web 应用程序的 “粘合剂” 。 10 | 11 | 例如,当访问下面这个 URL 时: 12 | 13 | http://example.com/news/latest/10 14 | 15 | 通过这个 URL 我们就可以推测出来,有一个叫做 "news" 的控制器,被调用的方法为 "latest" , 16 | 这个方法的作用应该是查询 10 条新闻条目并显示在页面上。在 MVC 模式里,你会经常看到下面 17 | 格式的 URL : 18 | 19 | http://example.com/[controller-class]/[controller-method]/[arguments] 20 | 21 | 在正式环境下 URL 的格式可能会更复杂,但是现在,我们只需要关心这些就够了。 22 | 23 | 新建一个文件 application/controllers/Pages.php ,然后添加如下代码。 24 | 25 | :: 26 | 27 | 52 | 53 | CodeIgniter Tutorial 54 | 55 | 56 | 57 |

58 | 59 | 页头包含了一些基本的 HTML 代码,用于显示页面的主视图之前的内容。 60 | 另外,它还打印出了 ``$title`` 变量,这个我们后面讲控制器的时候再讲。 61 | 现在,再新建个页脚文件 *application/views/templates/footer.php* ,然后添加以下代码: 62 | 63 | :: 64 | 65 | © 2015 66 | 67 | 68 | 69 | 在控制器中添加逻辑 70 | ------------------------------ 71 | 72 | 你刚刚新建了一个控制器,里面有一个 ``view()`` 方法,这个方法接受一个参数 73 | 用于指定要加载的页面,静态页面模板位于 *application/views/pages/* 目录。 74 | 75 | 在该目录中,再新建两个文件 *home.php* 和 *about.php* ,在每个文件里随便 76 | 写点东西然后保存它们。如果你没什么好写的,就写 "Hello World!" 吧。 77 | 78 | 为了加载这些页面,你需要先检查下请求的页面是否存在: 79 | 80 | :: 81 | 82 | public function view($page = 'home') 83 | { 84 | if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php')) 85 | { 86 | // Whoops, we don't have a page for that! 87 | show_404(); 88 | } 89 | 90 | $data['title'] = ucfirst($page); // Capitalize the first letter 91 | 92 | $this->load->view('templates/header', $data); 93 | $this->load->view('pages/'.$page, $data); 94 | $this->load->view('templates/footer', $data); 95 | } 96 | 97 | 当请求的页面存在,将包括页面和页脚一起被加载并显示给用户,如果不存在, 98 | 会显示一个 "404 Page not found" 错误。 99 | 100 | 第一行检查页面是否存在,``file_exists()`` 是个原生的 PHP 函数,用于检查某个 101 | 文件是否存在,``show_404()`` 是个 CodeIgniter 内置的函数,用来显示一个默认的 102 | 错误页面。 103 | 104 | 在页头文件中,``$title`` 变量用来自定义页面的标题,它是在这个方法中赋值的, 105 | 但是注意的是并不是直接赋值给 title 变量,而是赋值给一个 ``$data`` 数组的 106 | title 元素。 107 | 108 | 最后要做的是按顺序加载所需的视图,``view()`` 方法的第二个参数用于向视图传递参数, 109 | ``$data`` 数组中的每一项将被赋值给一个变量,这个变量的名字就是数组的键值。 110 | 所以控制器中 ``$data['title']`` 的值,就等于视图中的 ``$title`` 的值。 111 | 112 | 路由 113 | ------- 114 | 115 | 控制器现在开始工作了!在你的浏览器中输入 ``[your-site-url]index.php/pages/view`` 116 | 来查看你的页面。当你访问 ``index.php/pages/view/about`` 时你将看到 about 页面, 117 | 包括页头和页脚。 118 | 119 | 使用自定义的路由规则,你可以将任意的 URI 映射到任意的控制器和方法上,从而打破 120 | 默认的规则: 121 | 122 | ``http://example.com/[controller-class]/[controller-method]/[arguments]`` 123 | 124 | 让我们来试试。打开文件 *application/config/routes.php* 然后添加如下两行代码, 125 | 并删除掉其他对 ``$route`` 数组赋值的代码。 126 | 127 | :: 128 | 129 | $route['default_controller'] = 'pages/view'; 130 | $route['(:any)'] = 'pages/view/$1'; 131 | 132 | CodeIgniter 从上到下读取路由规则并将请求映射到第一个匹配的规则,每一个规则都是 133 | 一个正则表达式(左侧)映射到 一个控制器和方法(右侧)。当有请求到来时,CodeIgniter 134 | 首先查找能匹配的第一条规则,然后调用相应的控制器和方法,可能还带有参数。 135 | 136 | 你可以在关于 :doc:`URI 路由的文档 <../general/routing>` 中找到更多信息。 137 | 138 | 这里,第二条规则中 ``$routes`` 数组使用了通配符 ``(:any)`` 可以匹配所有的请求, 139 | 然后将参数传递给 ``Pages`` 类的 ``view()`` 方法。 140 | 141 | 现在访问 ``index.php/about`` 。路由规则是不是正确的将你带到了控制器中的 ``view()`` 142 | 方法?实在是太棒了! 143 | -------------------------------------------------------------------------------- /source/installation/upgrade_130.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | Upgrading from 1.2 to 1.3 3 | ######################### 4 | 5 | .. note:: The instructions on this page assume you are running version 6 | 1.2. If you have not upgraded to that version please do so first. 7 | 8 | Before performing an update you should take your site offline by 9 | replacing the index.php file with a static one. 10 | 11 | Step 1: Update your CodeIgniter files 12 | ===================================== 13 | 14 | Replace the following directories in your "system" folder with the new 15 | versions: 16 | 17 | .. note:: If you have any custom developed files in these folders please 18 | make copies of them first. 19 | 20 | - application/**models**/ (new for 1.3) 21 | - codeigniter (new for 1.3) 22 | - drivers 23 | - helpers 24 | - init 25 | - language 26 | - libraries 27 | - plugins 28 | - scaffolding 29 | 30 | Step 2: Update your error files 31 | =============================== 32 | 33 | Version 1.3 contains two new error templates located in 34 | application/errors, and for naming consistency the other error templates 35 | have been renamed. 36 | 37 | If you **have not** customized any of the error templates simply replace 38 | this folder: 39 | 40 | - application/errors/ 41 | 42 | If you **have** customized your error templates, rename them as follows: 43 | 44 | - 404.php = error_404.php 45 | - error.php = error_general.php 46 | - error_db.php (new) 47 | - error_php.php (new) 48 | 49 | Step 3: Update your index.php file 50 | ================================== 51 | 52 | Please open your main index.php file (located at your root). At the very 53 | bottom of the file, change this:: 54 | 55 | require_once BASEPATH.'libraries/Front_controller'.EXT; 56 | 57 | To this:: 58 | 59 | require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; 60 | 61 | Step 4: Update your config.php file 62 | =================================== 63 | 64 | Open your application/config/config.php file and add these new items:: 65 | 66 | 67 | /* 68 | |------------------------------------------------ 69 | | URL suffix 70 | |------------------------------------------------ 71 | | 72 | | This option allows you to add a suffix to all URLs. 73 | | For example, if a URL is this: 74 | | 75 | | example.com/index.php/products/view/shoes 76 | | 77 | | You can optionally add a suffix, like ".html", 78 | | making the page appear to be of a certain type: 79 | | 80 | | example.com/index.php/products/view/shoes.html 81 | | 82 | */ 83 | $config['url_suffix'] = ""; 84 | 85 | 86 | /* 87 | |------------------------------------------------ 88 | | Enable Query Strings 89 | |------------------------------------------------ 90 | | 91 | | By default CodeIgniter uses search-engine and 92 | | human-friendly segment based URLs: 93 | | 94 | | example.com/who/what/where/ 95 | | 96 | | You can optionally enable standard query string 97 | | based URLs: 98 | | 99 | | example.com?who=me&what=something&where=here 100 | | 101 | | Options are: TRUE or FALSE (boolean) 102 | | 103 | | The two other items let you set the query string "words" 104 | | that will invoke your controllers and functions: 105 | | example.com/index.php?c=controller&m=function 106 | | 107 | */ 108 | $config['enable_query_strings'] = FALSE; 109 | $config['controller_trigger'] = 'c'; 110 | $config['function_trigger'] = 'm'; 111 | 112 | Step 5: Update your database.php file 113 | ===================================== 114 | 115 | Open your application/config/database.php file and add these new items:: 116 | 117 | 118 | $db['default']['dbprefix'] = ""; 119 | $db['default']['active_r'] = TRUE; 120 | 121 | Step 6: Update your user guide 122 | ============================== 123 | 124 | Please also replace your local copy of the user guide with the new 125 | version. 126 | -------------------------------------------------------------------------------- /source/database/queries.rst: -------------------------------------------------------------------------------- 1 | ####### 2 | 查询 3 | ####### 4 | 5 | ************ 6 | 基本查询 7 | ************ 8 | 9 | 常规查询 10 | =============== 11 | 12 | 要提交一个查询,使用 **query** 函数:: 13 | 14 | $this->db->query('YOUR QUERY HERE'); 15 | 16 | 当你执行读类型的查询(如:SELECT)时,``query()`` 函数将以**对象**形式 17 | 返回一个结果集,参考这里来 :doc:`显示你的结果 `。 18 | 当你执行写类型的查询(如:INSERT、DELETE、UPDATE)时,函数将简单的返回 19 | TRUE 或 FALSE 来表示操作是否成功。 20 | 你可以将函数返回的结果赋值给一个变量,这样你就可以根据这个变量来获取 21 | 数据了,像下面这样:: 22 | 23 | $query = $this->db->query('YOUR QUERY HERE'); 24 | 25 | 简化查询 26 | ================== 27 | 28 | **simple_query** 函数是 ``$this->db->query()`` 的简化版。它不会返回查询的 29 | 结果集,不会去设置查询计数器,不会去编译绑定的数据,不会去存储查询的调试信息。 30 | 它只是用于简单的提交一个查询,大多数用户并不会用到这个函数。 31 | 32 | **simple_query** 函数直接返回数据库驱动器的 "execute" 方法的返回值。对于写类型的 33 | 查询(如:INSERT、DELETE、UPDATE),返回代表操作是否成功的 TRUE 或 FALSE;而 34 | 对于读类型的成功查询,则返回代表结果集的对象。 35 | 36 | :: 37 | 38 | if ($this->db->simple_query('YOUR QUERY')) 39 | { 40 | echo "Success!"; 41 | } 42 | else 43 | { 44 | echo "Query failed!"; 45 | } 46 | 47 | .. note:: 对于所有的查询,如果成功执行的话,PostgreSQL 的 ``pg_exec()`` 函数 48 | 都会返回一个结果集对象,就算是写类型的查询也是这样。如果你想判断查询执行是否 49 | 成功或失败,请记住这一点。 50 | 51 | *************************************** 52 | 指定数据库前缀 53 | *************************************** 54 | 55 | 如果你配置了一个数据库前缀参数,想把它加上你的 SQL 语句里的表名前面, 56 | 你可以调用下面的方法:: 57 | 58 | $this->db->dbprefix('tablename'); // outputs prefix_tablename 59 | 60 | 如果你想动态的修改这个前缀,而又不希望创建一个新的数据库连接,可以使用这个方法:: 61 | 62 | $this->db->set_dbprefix('newprefix'); 63 | $this->db->dbprefix('tablename'); // outputs newprefix_tablename 64 | 65 | 66 | ********************** 67 | 保护标识符 68 | ********************** 69 | 70 | 在很多数据库里,保护表名和字段名是可取的,例如在 MySQL 数据库里使用反引号。 71 | **使用查询构造器会自动保护标识符**,尽管如此,你还是可以像下面这样手工来保护:: 72 | 73 | $this->db->protect_identifiers('table_name'); 74 | 75 | .. important:: 尽管查询构造器会尽力保护好你输入的表名和字段名,但值得注意的是, 76 | 它并不是被设计来处理任意用户输入的,所以,请不要传未处理的数据给它。 77 | 78 | 这个函数也可以为你的表名添加一个前缀,如果你在数据库配置文件中定义了 ``dbprefix`` 79 | 参数,通过将这个函数的第二个参数设置为 TRUE 来启用前缀:: 80 | 81 | $this->db->protect_identifiers('table_name', TRUE); 82 | 83 | 84 | **************** 85 | 转义查询 86 | **************** 87 | 88 | 在提交数据到你的数据库之前,确保先对其进行转义是个非常不错的做法。 89 | CodeIgniter 有三个方法来帮你做到这一点: 90 | 91 | #. **$this->db->escape()** 这个函数会检测数据类型,仅转义字符串类型的数据。 92 | 它会自动用单引号将你的数据括起来,你不用手动添加: 93 | :: 94 | 95 | $sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")"; 96 | 97 | #. **$this->db->escape_str()** 这个函数忽略数据类型,对传入的数据进行转义, 98 | 这个方法并不常用,一般情况都是使用上面的那个方法。方法的使用代码如下: 99 | :: 100 | 101 | $sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; 102 | 103 | #. **$this->db->escape_like_str()** 这个函数用于处理 LIKE 语句中的字符串, 104 | 这样,LIKE 通配符('%', '_')可以被正确的转义。 105 | 106 | :: 107 | 108 | $search = '20% raise'; 109 | $sql = "SELECT id FROM table WHERE column LIKE '%" . 110 | $this->db->escape_like_str($search)."%'"; 111 | 112 | 113 | ************** 114 | 查询绑定 115 | ************** 116 | 117 | 查询绑定可以简化你的查询语法,它通过系统自动的为你将各个查询组装在一起。 118 | 参考下面的例子:: 119 | 120 | $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; 121 | $this->db->query($sql, array(3, 'live', 'Rick')); 122 | 123 | 查询语句中的问号将会自动被第二个参数位置的数组的相应的值替代。 124 | 125 | 也可以使用数组的数组进行绑定,里面的数组会被转换成 IN 语句的集合:: 126 | 127 | $sql = "SELECT * FROM some_table WHERE id IN ? AND status = ? AND author = ?"; 128 | $this->db->query($sql, array(array(3, 6), 'live', 'Rick')); 129 | 130 | 上面的例子会被转换为这样的查询:: 131 | 132 | SELECT * FROM some_table WHERE id IN (3,6) AND status = 'live' AND author = 'Rick' 133 | 134 | 使用查询绑定的第二个好处是:所有的值会被自动转义,生成安全的查询语句。 135 | 你不再需要手工进行转义,系统会自动进行。 136 | 137 | *************** 138 | 错误处理 139 | *************** 140 | 141 | **$this->db->error();** 142 | 143 | 要获取最近一次发生的错误,使用 ``error()`` 方法可以得到一个包含错误代码和错误消息的数组。 144 | 这里是一个简单例子:: 145 | 146 | if ( ! $this->db->simple_query('SELECT `example_field` FROM `example_table`')) 147 | { 148 | $error = $this->db->error(); // Has keys 'code' and 'message' 149 | } 150 | 151 | -------------------------------------------------------------------------------- /source/tutorial/create_news_items.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | 创建新闻条目 3 | ################# 4 | 5 | 现在你已经知道如何通过 CodeIgniter 从数据库中读取数据了,但是你还没有 6 | 向数据库中写入数据。在这一节,你将继续完善前文中创建的 News 控制器和模型, 7 | 添加上这一功能。 8 | 9 | 创建一个表单 10 | ------------- 11 | 12 | 为了向数据库中写入数据,你需要先创建一个表单用来填写要存储的信息,这意味着 13 | 你的表单里需要包含两项:一项代表标题,另一项代表内容。你可以在模型中通过代码 14 | 从标题中提取出 slug 。在文件 application/views/news/create.php 中创建一个新视图。 15 | 16 | :: 17 | 18 |

19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 这里有两个地方你可能还不熟悉:form_open() 函数 以及 validation_errors() 函数。 35 | 36 | 第一个函数是由 :doc:`表单辅助库 <../helpers/form_helper>` 提供的,用于生成 form 37 | 元素,并添加一些额外的功能,如添加一个隐藏的 :doc:`CSRF 保护字段 <../libraries/security>` , 38 | 第二个函数用于显示表单验证的错误信息。 39 | 40 | 回到你的 News 控制器,你将要在这里做两件事:检查表单是否被提交,以及提交的数据是否能通过验证规则。 41 | 你可以使用 :doc:`表单验证类 <../libraries/form_validation>` 来做到这一点。 42 | 43 | :: 44 | 45 | public function create() 46 | { 47 | $this->load->helper('form'); 48 | $this->load->library('form_validation'); 49 | 50 | $data['title'] = 'Create a news item'; 51 | 52 | $this->form_validation->set_rules('title', 'Title', 'required'); 53 | $this->form_validation->set_rules('text', 'text', 'required'); 54 | 55 | if ($this->form_validation->run() === FALSE) 56 | { 57 | $this->load->view('templates/header', $data); 58 | $this->load->view('news/create'); 59 | $this->load->view('templates/footer'); 60 | 61 | } 62 | else 63 | { 64 | $this->news_model->set_news(); 65 | $this->load->view('news/success'); 66 | } 67 | } 68 | 69 | 上面的代码添加了不少功能,前几行代码加载了 表单辅助库 和 表单验证类。然后,设置了表单验证规则, 70 | set\_rules() 方法有三个参数:表单中字段的名称,错误信息中使用的名称,以及验证规则。在这个例子中, 71 | 规则为 title 和 text 字段是必填的。 72 | 73 | CodeIgniter 有一个强大的表单验证类,像上面示例中那样。你可以在 :doc:`这里 <../libraries/form_validation>` 74 | 阅读更多。 75 | 76 | 接下来,你可以看到一个判断条件检查表单验证是否成功通过,如果没有通过,将显示出表单, 77 | 如果通过了验证,则会调用模型。然后,加载视图显示出成功信息。新建一个视图文件 78 | application/views/news/success.php 并写上成功的信息。 79 | 80 | 模型 81 | ----- 82 | 83 | 最后只剩下一件事情了,那就是写一个方法将数据保存到数据库中,你将会使用 输入类 获取用户提交的数据, 84 | 并使用 查询构造器类 向数据库中插入数据。打开之前创建的模型文件,添加以下代码: 85 | 86 | :: 87 | 88 | public function set_news() 89 | { 90 | $this->load->helper('url'); 91 | 92 | $slug = url_title($this->input->post('title'), 'dash', TRUE); 93 | 94 | $data = array( 95 | 'title' => $this->input->post('title'), 96 | 'slug' => $slug, 97 | 'text' => $this->input->post('text') 98 | ); 99 | 100 | return $this->db->insert('news', $data); 101 | } 102 | 103 | 新加的这个方法用于向数据库插入数据,第三行有一个新方法 url\_title() , 104 | 这个方法由 :doc:`URL 辅助库 <../helpers/url_helper>` 提供,用于将字符串 105 | 中的所有空格替换成连接符(-),并将所有字符转换为小写。 106 | 这样其实就生成了一个 slug ,可以很好的用于创建 URI 。 107 | 108 | 然后我们继续准备将要被插入到数据库中的记录,我们将其赋值给 $data 数组, 109 | 数组中的每一项都对应之前创建的数据库表中的一列,这里你应该看到又出现了一个新方法, 110 | 来自 :doc:`输入类 <../libraries/input>` 的 post() 方法,这个方法可以对数据进行过滤, 111 | 防止其他人的恶意攻击。输入类默认已经加载了。最后,将 $data 数组插入到我们的数据库中。 112 | 113 | 路由 114 | ------- 115 | 116 | 在你开始向 CodeIgniter 程序中添加新闻条目之前,你需要到 config/routes.php 117 | 文件中去添加一条新的路由规则,确保你的文件中包含了下面的代码。这样可以让 118 | CodeIgniter 知道 'create' 将作为一个方法被调用,而不是一个新闻条目的 slug 。 119 | 120 | :: 121 | 122 | $route['news/create'] = 'news/create'; 123 | $route['news/(:any)'] = 'news/view/$1'; 124 | $route['news'] = 'news'; 125 | $route['(:any)'] = 'pages/view/$1'; 126 | $route['default_controller'] = 'pages/view'; 127 | 128 | 现在在你的浏览器中输入你安装好的 CodeIgniter 的本地开发地址,然后在 URL 129 | 后面添加上 index.php/news/create 。恭喜你,你刚刚完成了你的第一个 CodeIgniter 130 | 程序!添加些新闻来看看这些你创造的页面吧! 131 | -------------------------------------------------------------------------------- /source/helpers/smiley_helper.rst: -------------------------------------------------------------------------------- 1 | ############# 2 | 表情辅助库 3 | ############# 4 | 5 | 表情辅助库文件包含了一些让你管理表情的函数。 6 | 7 | .. important:: 表情辅助库已经废弃,不建议使用。现在只是为了向前兼容而保留。 8 | 9 | .. contents:: 10 | :local: 11 | 12 | .. raw:: html 13 | 14 |
15 | 16 | 加载辅助库 17 | =================== 18 | 19 | 该辅助库通过下面的代码加载:: 20 | 21 | $this->load->helper('smiley'); 22 | 23 | 概述 24 | ======== 25 | 26 | 表情辅助库用于将纯文本的表情转换为图片,譬如::-) 转换为 |smile!| 27 | 28 | 另外它还可以显示一组表情图片,当你点击其中的某个表情时将会被插入到一个表单域中。 29 | 例如,如果你有一个博客并允许用户提交评论,你可以将这组表情图片显示在评论的旁边, 30 | 这样用户就可以点击想要的表情,然后通过一点点的 Javascript 代码,将该表情插入到 31 | 用户的评论中去。 32 | 33 | 可点击的表情包教程 34 | ========================== 35 | 36 | 这里是一个如何在表单中使用可点击的表情包的示例,这个示例需要你首先下载并安装表情图片, 37 | 然后按下面的步骤创建一个控制器和视图。 38 | 39 | .. important:: 开始之前,请先 `下载表情图片 `_ 40 | 然后将其放置到服务器的一个公共目录,并打开 `application/config/smileys.php` 文件设置表情替换的规则。 41 | 42 | 控制器 43 | -------------- 44 | 45 | 在 **application/controllers/** 目录下,创建一个文件 Smileys.php 然后输入下面的代码。 46 | 47 | .. important:: 修改下面的 :php:func:`get_clickable_smileys()` 函数的 URL 参数,让其指向你的表情目录。 48 | 49 | 你会发现我们除了使用到了表情库,还使用到了 :doc:`表格类 <../libraries/table>`:: 50 | 51 | load->helper('smiley'); 58 | $this->load->library('table'); 59 | 60 | $image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comments'); 61 | $col_array = $this->table->make_columns($image_array, 8); 62 | 63 | $data['smiley_table'] = $this->table->generate($col_array); 64 | $this->load->view('smiley_view', $data); 65 | } 66 | 67 | } 68 | 69 | 然后,在 **application/views/** 目录下新建一个文件 **smiley_view.php** 并输入以下代码:: 70 | 71 | 72 | 73 | Smileys 74 | 75 | 76 | 77 |
78 | 79 |
80 |

Click to insert a smiley!

81 | 82 | When you have created the above controller and view, load it by visiting http://www.example.com/index.php/smileys/ 83 | 84 | 85 | 86 | 字段别名 87 | ------------- 88 | 89 | 当修改视图的时候,会牵扯到控制器中的 id 字段,带来不便。为了解决这一问题, 90 | 你可以在视图中给表情一个别名,并将其映射到 id 字段。 91 | 92 | :: 93 | 94 | $image_array = get_smiley_links("http://example.com/images/smileys/", "comment_textarea_alias"); 95 | 96 | 将别名映射到 id 字段,可以使用 smiley_js 函数并传入这两个参数:: 97 | 98 | $image_array = smiley_js("comment_textarea_alias", "comments"); 99 | 100 | 可用函数 101 | =================== 102 | 103 | .. php:function:: get_clickable_smileys($image_url[, $alias = ''[, $smileys = NULL]]) 104 | 105 | :param string $image_url: URL path to the smileys directory 106 | :param string $alias: Field alias 107 | :returns: An array of ready to use smileys 108 | :rtype: array 109 | 110 | 返回一个已经绑定了可点击表情的数组。你必须提供表情文件夹的 URL , 111 | 还有表单域的 ID 或者表单域的别名。 112 | 113 | 举例:: 114 | 115 | $image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comment'); 116 | 117 | .. php:function:: smiley_js([$alias = ''[, $field_id = ''[, $inline = TRUE]]]) 118 | 119 | :param string $alias: Field alias 120 | :param string $field_id: Field ID 121 | :param bool $inline: Whether we're inserting an inline smiley 122 | :returns: Smiley-enabling JavaScript code 123 | :rtype: string 124 | 125 | 生成可以让图片点击后插入到表单域中的 JavaScript 代码。如果你在生成表情链接的时候 126 | 提供了一个别名来代替 id ,你需要在函数中传入别名和相应的 id ,此函数被设计为 127 | 应放在你 Web 页面的 部分。 128 | 129 | 举例:: 130 | 131 | 132 | 133 | .. php:function:: parse_smileys([$str = ''[, $image_url = ''[, $smileys = NULL]]]) 134 | 135 | :param string $str: Text containing smiley codes 136 | :param string $image_url: URL path to the smileys directory 137 | :param array $smileys: An array of smileys 138 | :returns: Parsed smileys 139 | :rtype: string 140 | 141 | 输入一个文本字符串,并将其中的纯文本表情替换为等效的表情图片,第一个参数为你的字符串, 142 | 第二个参数是你的表情目录对应的 URL 。 143 | 144 | 举例:: 145 | 146 | $str = 'Here are some smileys: :-) ;-)'; 147 | $str = parse_smileys($str, 'http://example.com/images/smileys/'); 148 | echo $str; 149 | 150 | .. |smile!| image:: ../images/smile.gif -------------------------------------------------------------------------------- /source/general/views.rst: -------------------------------------------------------------------------------- 1 | ##### 2 | 视图 3 | ##### 4 | 5 | 简单来说,一个视图其实就是一个 Web 页面,或者页面的一部分,像页头、页脚、侧边栏等。 6 | 实际上,视图可以很灵活的嵌在另一个视图里,然后这个视图再嵌在另一个视图里,等等, 7 | 如果你想使用这种层次结构的话,可以这样做。 8 | 9 | 视图不是直接被调用的,它必须通过 :doc:`控制器 ` 来加载。在 MVC 框架里, 10 | 控制器扮演着类似于交警的角色,它专门负责读取特定的视图。如果你还没有读过 11 | :doc:`控制器 ` 页面,你应该先看下这个。 12 | 13 | 使用在 :doc:`控制器 ` 页面中创建的控制器例子,让我们再添加一个视图。 14 | 15 | 创建视图 16 | =============== 17 | 18 | 使用你的文本编辑器,创建一个 blogview.php 文件,代码如下:: 19 | 20 | 21 | 22 | My Blog 23 | 24 | 25 |

Welcome to my Blog!

26 | 27 | 28 | 29 | 然后保存到你的 *application/views/* 目录下。 30 | 31 | 加载视图 32 | ============== 33 | 34 | 使用下面的方法来加载指定的视图:: 35 | 36 | $this->load->view('name'); 37 | 38 | name 参数为你的视图文件名。 39 | 40 | .. note:: 文件的扩展名 .php 可以省略,除非你使用了其他的扩展名。 41 | 42 | 现在,打开你之前创建的控制器文件 Blog.php ,然后将 echo 语句替换成 43 | 加载视图的代码:: 44 | 45 | load->view('blogview'); 51 | } 52 | } 53 | 54 | 跟之前一样,通过类似于下面的 URL 来访问你的网站,你将看到新的页面:: 55 | 56 | example.com/index.php/blog/ 57 | 58 | 加载多个视图 59 | ====================== 60 | 61 | CodeIgniter 可以智能的处理在控制器中多次调用 ``$this->load->view()`` 方法。 62 | 如果出现了多次调用,视图会被合并到一起。例如,你可能希望有一个页头视图、 63 | 一个菜单视图,一个内容视图 以及 一个页脚视图。代码看起来应该这样:: 64 | 65 | load->view('header'); 73 | $this->load->view('menu'); 74 | $this->load->view('content', $data); 75 | $this->load->view('footer'); 76 | } 77 | 78 | } 79 | 80 | 在上面的例子中,我们使用了 "添加动态数据" ,我们会在后面讲到。 81 | 82 | 在子目录中存储视图 83 | ==================================== 84 | 85 | 如果你喜欢的话,你的视图文件可以放到子目录下组织存储,当你这样做, 86 | 加载视图时需要包含子目录的名字,例如:: 87 | 88 | $this->load->view('directory_name/file_name'); 89 | 90 | 向视图添加动态数据 91 | =============================== 92 | 93 | 通过视图加载方法的第二个参数可以从控制器中动态的向视图传入数据, 94 | 这个参数可以是一个 **数组** 或者一个 **对象** 。这里是使用数组的例子:: 95 | 96 | $data = array( 97 | 'title' => 'My Title', 98 | 'heading' => 'My Heading', 99 | 'message' => 'My Message' 100 | ); 101 | 102 | $this->load->view('blogview', $data); 103 | 104 | 这里是使用对象的例子:: 105 | 106 | $data = new Someclass(); 107 | $this->load->view('blogview', $data); 108 | 109 | .. note:: 当你使用对象时,对象中的变量会转换为数组元素。 110 | 111 | 让我们在你的控制器文件中尝试一下,添加如下代码:: 112 | 113 | load->view('blogview', $data); 122 | } 123 | } 124 | 125 | 再打开你的视图文件,将文本修改为传入的数组对应的变量:: 126 | 127 | 128 | 129 | <?php echo $title;?> 130 | 131 | 132 |

133 | 134 | 135 | 136 | 然后通过刚刚的 URL 重新加载页面,你应该可以看到变量被替换了。 137 | 138 | 使用循环 139 | ============== 140 | 141 | 传入视图文件的数据不仅仅限制为普通的变量,你还可以传入多维数组, 142 | 这样你就可以在视图中生成多行了。例如,如果你从数据库中获取数据, 143 | 一般情况下数据都是一个多维数组。 144 | 145 | 这里是个简单的例子,将它添加到你的控制器中:: 146 | 147 | load->view('blogview', $data); 158 | } 159 | } 160 | 161 | 然后打开你的视图文件,创建一个循环:: 162 | 163 | 164 | 165 | <?php echo $title;?> 166 | 167 | 168 |

169 | 170 |

My Todo List

171 | 172 |
    173 | 174 | 175 |
  • 176 | 177 | 178 |
179 | 180 | 181 | 182 | 183 | .. note:: 你会发现在上例中,我们使用了 PHP 的替代语法,如果你对其还不熟悉,可以阅读 184 | :doc:`这里 ` 。 185 | 186 | 将视图作为数据返回 187 | ======================= 188 | 189 | 加载视图方法有一个可选的第三个参数可以让你修改它的默认行为,它让视图作为字符串返回 190 | 而不是显示到浏览器中,这在你想对视图数据做某些处理时很有用。如果你将该参数设置为 TRUE , 191 | 该方法返回字符串,默认情况下为 FALSE ,视图将显示到浏览器。如果你需要返回的数据, 192 | 记住将它赋值给一个变量:: 193 | 194 | $string = $this->load->view('myfile', '', TRUE); -------------------------------------------------------------------------------- /source/general/security.rst: -------------------------------------------------------------------------------- 1 | ######## 2 | 安全 3 | ######## 4 | 5 | 这篇文章将介绍一些基本的关于 Web 安全的 "最佳实践" ,并详细说明了 CodeIgniter 6 | 内部的安全特性。 7 | 8 | URI 安全 9 | ============ 10 | 11 | CodeIgniter 严格限制 URI 中允许出现的字符,以此来减少恶意数据传到你的应用程序的可能性。 12 | URI 中只允许包含一些字符: 13 | 14 | - 字母和数字 15 | - 波浪符:~ 16 | - 百分号:% 17 | - 句号:. 18 | - 分号:: 19 | - 下划线:\_ 20 | - 连字号:- 21 | - 空格 22 | 23 | Register_globals 24 | ================ 25 | 26 | 在系统初始化期间,如果发现任何 ``$_GET``、``$_POST``、``$_REQUEST`` 和 ``$_COOKIE`` 27 | 数组中的键值变成了全局变量,则删除该变量。 28 | 29 | 这个过程和设置 *register_globals = off* 效果是一样的。 30 | (译注:阅读这里了解 `register_globals 设置 `_ ) 31 | 32 | display_errors 33 | ============== 34 | 35 | 在生产环境下,一般都是通过将 *display_errors* 标志设置为 0 来禁用 PHP 的错误报告。 36 | 这可以阻止原生的 PHP 错误被显示到页面上,错误中可能会包含潜在的敏感信息。 37 | 38 | 在 CodeIgniter 中,可以将 index.php 文件中的 **ENVIRONMENT** 常量设置为 **\'production\'** , 39 | 这样也可以关闭这些错误信息。在开发模式下,建议将它设置为 'development' 。 40 | 关于不同环境之间的区别可以阅读 :doc:`处理多环境 ` 页面了解更多。 41 | 42 | magic_quotes_runtime 43 | ==================== 44 | 45 | 在系统初始化期间, *magic_quotes_runtime* 指令会被禁用, 46 | 这样当你在从数据库中获取数据时就不用再去除反斜线了。 47 | 48 | ************** 49 | 最佳实践 50 | ************** 51 | 52 | 在你的应用程序处理任何数据之前,无论这些数据是来自于提交的表单 POST ,还是来自 53 | COOKIE、URI、XML-RPC ,或者甚至是来自于 SERVER 数组,你都应该使用下面这三步 54 | 来处理: 55 | 56 | #. 验证数据类型是否正确,以及长度、大小等等 57 | #. 过滤不良数据 58 | #. 在提交到数据库或者显示到浏览器之前对数据进行转义 59 | 60 | CodeIgniter 提供了以下的方法和技巧来帮你处理该过程: 61 | 62 | XSS 过滤 63 | ============= 64 | 65 | CodeIgniter 自带有一个 XSS 过滤器,这个过滤器可以查找一些 XSS 的常用技术, 66 | 譬如向你的数据中嵌入恶意的 JavaScript 脚本,劫持 cookie 信息或其他一些技术。 67 | XSS 过滤器在 :doc:`这里 <../libraries/security>` 有更详细的描述。 68 | 69 | .. note:: XSS 过滤 *只应该在输出数据时使用* 。 对输入的数据进行过滤可能会 70 | 在无意中对数据造成修改,譬如过滤密码中的特殊字符,这样会降低安全性, 71 | 而不是提高安全性。 72 | 73 | CSRF 保护 74 | =============== 75 | 76 | CSRF(Cross-Site Request Forgery,跨站请求伪造)是攻击者骗取受害者 77 | 在不知情的情况下提交请求的攻击方式。 78 | 79 | CodeIgniter 提供了对 CSRF 的保护,会在每个非 GET HTTP 请求时自动触发, 80 | 当然前提是你要使用某种方式来创建表单,这在 :doc:`安全类 <../libraries/security>` 81 | 文档中有进一步的解释。 82 | 83 | 密码处理 84 | ================= 85 | 86 | 在你的应用程序中正确处理密码是非常关键的。 87 | 88 | 但是不幸的是,许多开发者并不知道怎么去做,而且网络上充斥着大量过时的 89 | 甚至错误的建议,提供不了任何帮助。 90 | 91 | 我们提供了一个清单来帮助你,告诉你什么该做,什么不该做。 92 | 93 | - 绝不要以明文存储密码。 94 | 95 | 永远使用 **哈希算法** 来处理密码。 96 | 97 | - 绝不要使用 Base64 或其他编码方式来存储密码。 98 | 99 | 这和以明文存储密码是一样的,使用 **哈希** ,而不要使用 **编码** 。 100 | 101 | 编码以及加密,都是双向的过程,而密码是保密的,应该只被它的所有者知道, 102 | 这个过程必须是单向的。哈希正是用于做这个的,从来没有解哈希这种说法, 103 | 但是编码就存在解码,加密就存在解密。 104 | 105 | - 绝不要使用弱哈希或已被破解的哈希算法,像 MD5 或 SHA1 。 106 | 107 | 这些算法太老了,而且被证明存在缺陷,它们一开始就并不是为了保存密码而设计的。 108 | 109 | 另外,绝不要自己发明算法。 110 | 111 | 只使用强密码哈希算法,譬如 BCrypt ,在 PHP 自己的 `密码哈希 `_ 112 | 函数中也是使用它。 113 | 114 | 即使你的 PHP 版本不是 5.5+ ,也请使用它们,CodeIgniter 为你提供了这些算法,只要你的 PHP 115 | 版本是 5.3.7 以上都可以使用。(如果不满足这点要求,那么请升级你的 PHP) 116 | 117 | 如果你连升级 PHP 也无法做到,那么使用 `hash_pbkdf() ` 吧, 118 | 为实现兼容性我们提供了这个函数。 119 | 120 | - 绝不要以明文形式显示或发送密码。 121 | 122 | 即使是对密码的所有者也应该这样。如果你需要 "忘记密码" 的功能,可以随机生成一个新的 123 | 一次性的(这点很重要)密码,然后把这个密码发送给用户。 124 | 125 | - 绝不要对用户的密码做一些没必要的限制。 126 | 127 | 如果你使用除 BCrypt (它有最多 72 字符的限制)之外的其他哈希算法,你应该设置一个相对 128 | 长一点的密码长度(例如 1024 字符),这样可以缓解 DoS 攻击 。(这样可以缓解 DoS 攻击?) 129 | 130 | 但是除此之外,对密码的其他限制诸如密码中只允许使用某些字符,或者密码中不允许包含某些字符, 131 | 就没有任何意义了。 132 | 133 | 这样做不仅不会提高安全性,反而降低了安全性,而且真的没有任何理由需要这样做。 134 | 只要你对密码进行哈希处理了,那么无论是技术上,还是在存储上都没有任何限制。 135 | 136 | 验证输入数据 137 | =================== 138 | 139 | CodeIgniter 有一个 :doc:`表单验证类 <../libraries/form_validation>` 用于帮助你验证、 140 | 过滤以及预处理你的数据。 141 | 142 | 就算这个类不适用于你的使用场景,那么你也应该确保对输入数据进行验证过滤。 143 | 例如,你希望接受一个数字型的参数,你可以使用 ``is_numeric()`` 或 ``ctype_digit()`` 144 | 函数来检查一下。永远将数据限制在你运行的范围内。 145 | 146 | 记住,不仅要验证 ``$_POST`` 和 ``$_GET`` 变量,而且也不要放过 cookie 、user-agent 147 | 以及 **其他所有的不是直接由你的代码生成的数据** 。 148 | 149 | 插入数据库之前对数据进行转义 150 | ========================================= 151 | 152 | 永远不要不做转义就将数据插入到数据库,更多信息,可以阅读 :doc:`数据库查询 153 | <../database/queries>` 这一节。 154 | 155 | 隐藏你的文件 156 | =============== 157 | 158 | 另一个很好的安全实践是,在你的 *webroot* 目录(通常目录名为 "htdocs/")下只保留 159 | *index.php* 文件和 "assets" 目录(用于存放 js、css、图片等静态资源)。 160 | 只需要这些文件能从 Web 上访问就可以了。 161 | 162 | 允许你的访问者访问其他位置可能潜在的导致他们访问一些敏感数据或者执行脚本等等。 163 | 164 | 如果你不允许这样做,你可以使用 .htaccess 文件来限制对这些资源的访问。 165 | 166 | CodeIgniter 在每个目录下放置了一个 index.html 文件,试图隐藏这些敏感数据, 167 | 但是要记住的是,这对于防止一个真正的攻击者来说并不够。 168 | -------------------------------------------------------------------------------- /source/general/routing.rst: -------------------------------------------------------------------------------- 1 | ########### 2 | URI 路由 3 | ########### 4 | 5 | 一般情况下,一个 URL 字符串和它对应的控制器中类和方法是一一对应的关系。 6 | URL 中的每一段通常遵循下面的规则:: 7 | 8 | example.com/class/function/id/ 9 | 10 | 但是有时候,你可能想改变这种映射关系,调用一个不同的类和方法,而不是 11 | URL 中对应的那样。 12 | 13 | 例如,假设你希望你的 URL 变成下面这样:: 14 | 15 | example.com/product/1/ 16 | example.com/product/2/ 17 | example.com/product/3/ 18 | example.com/product/4/ 19 | 20 | URL 的第二段通常表示方法的名称,但在上面的例子中,第二段是一个商品 ID , 21 | 为了实现这一点,CodeIgniter 允许你重新定义 URL 的处理流程。 22 | 23 | 设置你自己的路由规则 24 | ============================== 25 | 26 | 路由规则定义在 *application/config/routes.php* 文件中,在这个文件中你会 27 | 发现一个名为 ``$route`` 的数组,利用它你可以设置你自己的路由规则。 28 | 在路由规则中你可以使用通配符或正则表达式。 29 | 30 | 通配符 31 | ========= 32 | 33 | 一个典型的使用通配符的路由规则如下:: 34 | 35 | $route['product/:num'] = 'catalog/product_lookup'; 36 | 37 | 在一个路由规则中,数组的键表示要匹配的 URI ,而数组的值表示要重定向的位置。 38 | 上面的例子中,如果 URL 的第一段是字符串 "product" ,第二段是个数字,那么, 39 | 将调用 "catalog" 类的 "product_lookup" 方法。 40 | 41 | 你可以使用纯字符串匹配,或者使用下面两种通配符: 42 | 43 | **(:num)** 匹配只含有数字的一段。 44 | **(:any)** 匹配含有任意字符的一段。(除了 '/' 字符,因为它是段与段之间的分隔符) 45 | 46 | .. note:: 通配符实际上是正则表达式的别名,**:any** 会被转换为 **[^/]+** , 47 | **:num** 会被转换为 **[0-9]+** 。 48 | 49 | .. note:: 路由规则将按照它们定义的顺序执行,前面的规则优先级高于后面的规则。 50 | 51 | .. note:: 路由规则并不是过滤器!设置一个这样的路由:'foo/bar/(:num)' , 52 | *Foo* 控制器的 *bar* 方法还是有可能会通过一个非数字的参数被调用 53 | (如果这个路由也是合法的话)。 54 | 55 | 例子 56 | ======== 57 | 58 | 这里是一些路由的例子:: 59 | 60 | $route['journals'] = 'blogs'; 61 | 62 | URL 的第一段是单词 "journals" 时,将重定向到 "blogs" 类。 63 | 64 | :: 65 | 66 | $route['blog/joe'] = 'blogs/users/34'; 67 | 68 | URL 包含 blog/joe 的话,将重定向到 "blogs" 类和 "users" 方法。ID 参数设为 "34" 。 69 | 70 | :: 71 | 72 | $route['product/(:any)'] = 'catalog/product_lookup'; 73 | 74 | URL 的第一段是 "product" ,第二段是任意字符时,将重定向到 "catalog" 类的 75 | "product_lookup" 方法。 76 | 77 | :: 78 | 79 | $route['product/(:num)'] = 'catalog/product_lookup_by_id/$1'; 80 | 81 | URL 的第一段是 "product" ,第二段是数字时,将重定向到 "catalog" 类的 82 | "product_lookup_by_id" 方法,并将第二段的数字作为参数传递给它。 83 | 84 | .. important:: 不要在前面或后面加反斜线('/')。 85 | 86 | 正则表达式 87 | =================== 88 | 89 | 如果你喜欢,你可以在路由规则中使用正则表达式。任何有效的正则表达式都是 90 | 允许的,包括逆向引用。 91 | 92 | .. note:: 如果你使用逆向引用,你需要使用美元符号代替双斜线语法。 93 | 94 | 一个典型的使用正则表达式的路由规则看起来像下面这样:: 95 | 96 | $route['products/([a-z]+)/(\d+)'] = '$1/id_$2'; 97 | 98 | 上例中,一个类似于 products/shirts/123 这样的 URL 将会重定向到 "shirts" 99 | 控制器的 "id_123" 方法。 100 | 101 | 使用正则表达式,你还可以匹配含有反斜线字符('/')的段,它通常来说是 102 | 多个段之间的分隔符。 103 | 104 | 例如,当一个用户访问你的 Web 应用中的某个受密码保护的页面时,如果他没有 105 | 登陆,会先跳转到登陆页面,你希望在他们在成功登陆后重定向回刚才那个页面, 106 | 那么这个例子会很有用:: 107 | 108 | $route['login/(.+)'] = 'auth/login/$1'; 109 | 110 | 如果你还不知道正则表达式,可以访问 `regular-expressions.info ` 111 | 开始学习一下。 112 | 113 | .. note:: 你也可以在你的路由规则中混用通配符和正则表达式。 114 | 115 | 回调函数 116 | ========= 117 | 118 | 如果你正在使用的 PHP 版本高于或等于 5.3 ,你还可以在路由规则中使用回调函数来处理逆向引用。 119 | 例如:: 120 | 121 | $route['products/([a-zA-Z]+)/edit/(\d+)'] = function ($product_type, $id) 122 | { 123 | return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id; 124 | }; 125 | 126 | 在路由中使用 HTTP 动词 127 | ========================== 128 | 129 | 还可以在你的路由规则中使用 HTTP 动词(请求方法),当你在创建 RESTful 应用时特别有用。 130 | 你可以使用标准的 HTTP 动词(GET、PUT、POST、DELETE、PATCH),也可以使用自定义的动词 131 | (例如:PURGE),不区分大小写。你需要做的就是在路由数组后面再加一个键,键名为 HTTP 132 | 动词。例如:: 133 | 134 | $route['products']['put'] = 'product/insert'; 135 | 136 | 上例中,当发送 PUT 请求到 "products" 这个 URI 时,将会调用 ``Product::insert()`` 方法。 137 | 138 | :: 139 | 140 | $route['products/(:num)']['DELETE'] = 'product/delete/$1'; 141 | 142 | 当发送 DELETE 请求到第一段为 "products" ,第二段为数字这个 URL时,将会调用 143 | ``Product::delete()`` 方法,并将数字作为第一个参数。 144 | 145 | 当然,使用 HTTP 动词是可选的。 146 | 147 | 保留路由 148 | =============== 149 | 150 | 有下面三个保留路由:: 151 | 152 | $route['default_controller'] = 'welcome'; 153 | 154 | 这个路由表示当用户不带任何参数直接访问你的网站时该加载哪个控制器, 155 | 上例中,将会加载 "welcome" 类。你应该永远都有个默认的路由,要不然 156 | 会显示 404 页面。 157 | 158 | :: 159 | 160 | $route['404_override'] = ''; 161 | 162 | 这个路由表示当用户请求了一个不存在的页面时该加载哪个控制器,它将会覆盖 163 | 默认的 404 错误页面。``show_404()`` 函数不会受影响,它还是会继续加载 164 | *application/views/errors/* 目录下的默认的 *error_404.php* 文件。 165 | 166 | 167 | :: 168 | 169 | $route['translate_uri_dashes'] = FALSE; 170 | 171 | 从它的布尔值就能看出来这其实并不是一个路由,这个选项可以自动的将 URL 172 | 中的控制器和方法中的连字符('-')转换为下划线('_'),当你需要这样时, 173 | 它可以让你少写很多路由规则。由于连字符不是一个有效的类名或方法名, 174 | 如果你不使用它的话,将会引起一个严重错误。 175 | 176 | .. important:: 保留的路由规则必须位于任何一般的通配符或正则路由的前面。 -------------------------------------------------------------------------------- /source/helpers/captcha_helper.rst: -------------------------------------------------------------------------------- 1 | ############## 2 | 验证码辅助库 3 | ############## 4 | 5 | 验证码辅助库文件包含了一些帮助你创建验证码图片的函数。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 加载辅助库 15 | =================== 16 | 17 | 该辅助库通过下面的代码加载:: 18 | 19 | $this->load->helper('captcha'); 20 | 21 | 使用验证码辅助库 22 | ======================== 23 | 24 | 辅助库加载之后你可以像下面这样生成一个验证码图片:: 25 | 26 | $vals = array( 27 | 'word' => 'Random word', 28 | 'img_path' => './captcha/', 29 | 'img_url' => 'http://example.com/captcha/', 30 | 'font_path' => './path/to/fonts/texb.ttf', 31 | 'img_width' => '150', 32 | 'img_height' => 30, 33 | 'expiration' => 7200, 34 | 'word_length' => 8, 35 | 'font_size' => 16, 36 | 'img_id' => 'Imageid', 37 | 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 38 | 39 | // White background and border, black text and red grid 40 | 'colors' => array( 41 | 'background' => array(255, 255, 255), 42 | 'border' => array(255, 255, 255), 43 | 'text' => array(0, 0, 0), 44 | 'grid' => array(255, 40, 40) 45 | ) 46 | ); 47 | 48 | $cap = create_captcha($vals); 49 | echo $cap['image']; 50 | 51 | - 验证码辅助函数需要使用 GD 图像库。 52 | - 只有 **img_path** 和 **img_url** 这两个参数是必须的。 53 | - 如果没有提供 **word** 参数,该函数将生成一个随机的 ASCII 字符串。 54 | 你也可以使用自己的词库,从里面随机挑选。 55 | - 如果你不设置 TRUE TYPE 字体(译者注:是主要的三种计算机矢量字体之一)的路径,将使用 GD 默认的字体。 56 | - "captcha" 目录必须是可写的。 57 | - **expiration** 参数表示验证码图片在删除之前将保留多久(单位为秒),默认保留 2 小时。 58 | - **word_length** 默认值为 8, **pool** 默认值为 '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' 59 | - **font_size** 默认值为 16,GD 库的字体对大小有限制,如果字体大小需要更大一点的话可以设置一种 TRUE TYPE 字体。 60 | - **img_id** 将会设置为验证码图片的 "id" 。 61 | - **colors** 数组中如果有某个颜色未设置,将使用默认颜色。 62 | 63 | 添加到数据库 64 | ----------------- 65 | 66 | 使用验证码函数是为了防止用户胡乱提交,要做到这一点,你需要将 ``create_captcha()`` 函数返回的信息保存到数据库中。 67 | 然后,等用户提交表单数据时,通过数据库中保存的数据进行验证,并确保它没有过期。 68 | 69 | 这里是数据表的一个例子:: 70 | 71 | CREATE TABLE captcha (   72 | captcha_id bigint(13) unsigned NOT NULL auto_increment,   73 | captcha_time int(10) unsigned NOT NULL,   74 | ip_address varchar(45) NOT NULL,   75 | word varchar(20) NOT NULL,   76 | PRIMARY KEY `captcha_id` (`captcha_id`),   77 | KEY `word` (`word`) 78 | ); 79 | 80 | 这里是使用数据库的示例。在显示验证码的那个页面,你的代码类似于下面这样:: 81 | 82 | $this->load->helper('captcha'); 83 | $vals = array(      84 | 'img_path' => './captcha/',      85 | 'img_url' => 'http://example.com/captcha/'      86 | ); 87 | 88 | $cap = create_captcha($vals); 89 | $data = array(      90 | 'captcha_time' => $cap['time'],      91 | 'ip_address' => $this->input->ip_address(),      92 | 'word' => $cap['word']      93 | ); 94 | 95 | $query = $this->db->insert_string('captcha', $data); 96 | $this->db->query($query); 97 | 98 | echo 'Submit the word you see below:'; 99 | echo $cap['image']; 100 | echo ''; 101 | 102 | 然后在处理用户提交的页面,处理如下:: 103 | 104 | // First, delete old captchas 105 | $expiration = time() - 7200; // Two hour limit 106 | $this->db->where('captcha_time < ', $expiration) 107 | ->delete('captcha'); 108 | 109 | // Then see if a captcha exists: 110 | $sql = 'SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?'; 111 | $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); 112 | $query = $this->db->query($sql, $binds); 113 | $row = $query->row(); 114 | 115 | if ($row->count == 0) 116 | {      117 | echo 'You must submit the word that appears in the image.'; 118 | } 119 | 120 | 可用函数 121 | =================== 122 | 123 | 该辅助库有下列可用函数: 124 | 125 | .. php:function:: create_captcha([$data = ''[, $img_path = ''[, $img_url = ''[, $font_path = '']]]]) 126 | 127 | :param array $data: Array of data for the CAPTCHA 128 | :param string $img_path: Path to create the image in 129 | :param string $img_url: URL to the CAPTCHA image folder 130 | :param string $font_path: Server path to font 131 | :returns: array('word' => $word, 'time' => $now, 'image' => $img) 132 | :rtype: array 133 | 134 | 根据你提供的一系列参数生成一张验证码图片,返回包含此图片信息的数组。 135 | 136 | :: 137 | 138 | array( 139 | 'image' => IMAGE TAG 140 | 'time' => TIMESTAMP (in microtime) 141 | 'word' => CAPTCHA WORD 142 | ) 143 | 144 | **image** 就是一个 image 标签:: 145 | 146 | 147 | 148 | **time** 是一个毫秒级的时间戳,作为图片的文件名(不带扩展名)。就像这样:1139612155.3422 149 | 150 | **word** 是验证码图片中的文字,如果在函数的参数中没有指定 word 参数,这将是一个随机字符串。 --------------------------------------------------------------------------------