├── cilexer ├── cilexer │ ├── __init__.py │ └── cilexer.py ├── setup.py └── README ├── source ├── images │ ├── file.gif │ ├── arrow.gif │ ├── ci-icon.ico │ ├── ci_logo.jpg │ ├── folder.gif │ ├── smile.png │ ├── appflowchart.png │ └── 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 ├── documentation │ └── ELDocs.tmbundle.zip ├── _themes │ └── sphinx_rtd_theme │ │ ├── static │ │ ├── images │ │ │ └── ci-icon.ico │ │ ├── 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 │ │ ├── js │ │ │ └── oldtheme.js │ │ └── css │ │ │ ├── badge_only.css │ │ │ └── theme_cn.css │ │ ├── theme.conf │ │ ├── searchbox.html │ │ ├── __init__.py │ │ ├── LICENSE │ │ ├── versions.html │ │ ├── breadcrumbs.html │ │ ├── search.html │ │ ├── pulldown.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_222.rst │ ├── upgrade_223.rst │ ├── upgrade_304.rst │ ├── upgrade_305.rst │ ├── upgrade_311.rst │ ├── upgrade_314.rst │ ├── upgrade_315.rst │ ├── upgrade_120.rst │ ├── upgrade_212.rst │ ├── upgrade_213.rst │ ├── upgrade_301.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_302.rst │ ├── upgrade_211.rst │ ├── index.rst │ ├── upgrade_202.rst │ ├── upgrade_162.rst │ ├── upgrade_152.rst │ ├── upgrade_172.rst │ ├── upgrade_133.rst │ ├── upgrade_312.rst │ ├── upgrade_201.rst │ ├── upgrade_154.rst │ ├── upgrade_310.rst │ ├── upgrading.rst │ ├── upgrade_313.rst │ ├── upgrade_303.rst │ ├── upgrade_170.rst │ ├── upgrade_306.rst │ ├── upgrade_160.rst │ ├── upgrade_203.rst │ ├── downloads.rst │ ├── upgrade_140.rst │ ├── upgrade_141.rst │ ├── upgrade_b11.rst │ ├── upgrade_150.rst │ └── upgrade_130.rst ├── general │ ├── index.rst │ ├── creating_drivers.rst │ ├── welcome.rst │ ├── credits.rst │ ├── libraries.rst │ ├── requirements.rst │ ├── autoloader.rst │ ├── 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 ├── database │ ├── index.rst │ ├── call_function.rst │ ├── helpers.rst │ ├── metadata.rst │ ├── examples.rst │ ├── transactions.rst │ ├── connecting.rst │ └── caching.rst ├── tutorial │ ├── conclusion.rst │ ├── index.rst │ ├── static_pages.rst │ └── create_news_items.rst ├── DCO.rst ├── license.rst └── index.rst ├── .gitignore ├── deploy-gh-pages.sh ├── .travis.yml └── README.rst /cilexer/cilexer/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /source/images/file.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/file.gif -------------------------------------------------------------------------------- /source/images/arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/arrow.gif -------------------------------------------------------------------------------- /source/images/ci-icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/ci-icon.ico -------------------------------------------------------------------------------- /source/images/ci_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/ci_logo.jpg -------------------------------------------------------------------------------- /source/images/folder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/folder.gif -------------------------------------------------------------------------------- /source/images/smile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/smile.png -------------------------------------------------------------------------------- /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/images/appflowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/appflowchart.png -------------------------------------------------------------------------------- /source/images/ci_logo_flame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/images/ci_logo_flame.jpg -------------------------------------------------------------------------------- /source/documentation/ELDocs.tmbundle.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/documentation/ELDocs.tmbundle.zip -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/images/ci-icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/images/ci-icon.ico -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /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/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/1YwB1sO8YE1Lyjf12WNiUA.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/1YwB1sO8YE1Lyjf12WNiUA.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/H2DMvhDLycM56KNuAtbJYA.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/H2DMvhDLycM56KNuAtbJYA.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/PLygLKRVCQnA5fhu3qk5fQ.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/PLygLKRVCQnA5fhu3qk5fQ.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/UyBMtLsHKBKXelqf4x7VRQ.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/UyBMtLsHKBKXelqf4x7VRQ.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yYlIZu-HDpmDIZMigmsroc4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yYlIZu-HDpmDIZMigmsroc4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yejkDdvhIIFj_YMdgqpnSB0.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/AIed271kqQlcIRSOnQH0yejkDdvhIIFj_YMdgqpnSB0.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/AcvTq8Q0lyKKNxRlL28RnxJtnKITppOI_IvcXXDNrsc.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/AcvTq8Q0lyKKNxRlL28RnxJtnKITppOI_IvcXXDNrsc.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCCYE0-AqJ3nfInTTiDXDjU4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCCYE0-AqJ3nfInTTiDXDjU4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCI4P5ICox8Kq3LLUNMylGO4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/BjAYBlHtW3CJxDcjzrnZCI4P5ICox8Kq3LLUNMylGO4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/HkF_qI1x_noxlxhrhMQYEFtXRa8TVwTICgirnJhmVJw.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/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/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/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/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/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/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJQalQocB-__pDVGhF3uS2Ks.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJSFaMxiho_5XQnyRZzQsrZs.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJSFaMxiho_5XQnyRZzQsrZs.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJS_vZmeiCMnoWNN9rHBYaTc.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJS_vZmeiCMnoWNN9rHBYaTc.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJWhQUTDJGru-0vvUpABgH8I.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJWhQUTDJGru-0vvUpABgH8I.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJYlIZu-HDpmDIZMigmsroc4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJYlIZu-HDpmDIZMigmsroc4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJZ6iIh_FvlUHQwED9Yt5Kbw.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJZ6iIh_FvlUHQwED9Yt5Kbw.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJejkDdvhIIFj_YMdgqpnSB0.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/dazS1PrQQuCxC3iOAJFEJejkDdvhIIFj_YMdgqpnSB0.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZiYE0-AqJ3nfInTTiDXDjU4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZiYE0-AqJ3nfInTTiDXDjU4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjTOQ_MqJVwkKsUn0wKzc2I.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjTOQ_MqJVwkKsUn0wKzc2I.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjUj_cnvWIuuBMVgbX098Mw.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZjUj_cnvWIuuBMVgbX098Mw.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZkbcKLIaa1LC45dFaAfauRA.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37ZkbcKLIaa1LC45dFaAfauRA.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zmo_sUJ8uO4YLWRInS22T3Y.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zmo_sUJ8uO4YLWRInS22T3Y.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zo4P5ICox8Kq3LLUNMylGO4.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zo4P5ICox8Kq3LLUNMylGO4.woff2 -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zr6up8jxqWt8HVA3mDhkV_0.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-Chinese/codeigniter-user-guide/HEAD/source/_themes/sphinx_rtd_theme/static/fonts/y7lebkjgREBJK96VQi37Zr6up8jxqWt8HVA3mDhkV_0.woff2 -------------------------------------------------------------------------------- /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 | 架构目标 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | build/* 4 | cilexer/build/* 5 | cilexer/dist/* 6 | cilexer/pycilexer.egg-info/* 7 | 8 | # IDE Files 9 | #------------------------- 10 | /nbproject/ 11 | .idea/* 12 | 13 | ## Sublime Text cache files 14 | *.tmlanguage.cache 15 | *.tmPreferences.cache 16 | *.stTheme.cache 17 | *.sublime-workspace 18 | *.sublime-project 19 | 20 | deploy.sh 21 | -------------------------------------------------------------------------------- /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.png 18 | -------------------------------------------------------------------------------- /deploy-gh-pages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git config --global user.name "Travis-CI" 4 | git config --global user.email "support@codeigniter.org.cn" 5 | git clone --branch=gh-pages "https://${GH_TOKEN}@${GH_REF}" gh-pages 6 | cd ./build/html 7 | rm .buildinfo 8 | zip -r ./codeigniter_user_guide.zip ./ 9 | cd ../latex 10 | cp CodeIgniter.pdf ../../gh-pages/ 11 | cd ../../gh-pages 12 | cp -Rf ../build/html/* . 13 | git add -f . 14 | git commit -m "Deploy to GitHub Pages" 15 | git push -fq origin gh-pages 16 | -------------------------------------------------------------------------------- /source/installation/troubleshooting.rst: -------------------------------------------------------------------------------- 1 | ######## 2 | 疑难解答 3 | ######## 4 | 5 | 如果你发现无论输入什么 URL 都只显示默认页面的话,那么可能是你的服务器不支持 PATH_INFO 变量,该变量用来提供搜索引擎友好的 URL 。 6 | 解决这个问题的第一步是打开 *application/config/config.php* 文件, 7 | 找到 URI Protocol 信息,根据注释提示,该值可以有几种不同的设置方式, 8 | 你可以逐个尝试一下。 9 | 如果还是不起作用,你需要让 CodeIgniter 强制在你的 URL 中添加一个问号, 10 | 要做到这点,你可以打开 *application/config/config.php* 文件, 11 | 然后将下面的代码:: 12 | 13 | $config['index_page'] = "index.php"; 14 | 15 | 修改为这样:: 16 | 17 | $config['index_page'] = "index.php?"; 18 | -------------------------------------------------------------------------------- /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/installation/upgrade_222.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.2.1 to 2.2.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. -------------------------------------------------------------------------------- /source/installation/upgrade_223.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.2.2 to 2.2.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. -------------------------------------------------------------------------------- /source/installation/upgrade_304.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.0.3 to 3.0.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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | -------------------------------------------------------------------------------- /source/installation/upgrade_305.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.0.4 to 3.0.5 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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | -------------------------------------------------------------------------------- /source/installation/upgrade_311.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.1.0 to 3.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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | -------------------------------------------------------------------------------- /source/installation/upgrade_314.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.1.3 to 3.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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | -------------------------------------------------------------------------------- /source/installation/upgrade_315.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.1.4 to 3.1.5 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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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:`创建你自己的类库 ` 部分。 -------------------------------------------------------------------------------- /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/general/requirements.rst: -------------------------------------------------------------------------------- 1 | ################### 2 | 服务器要求 3 | ################### 4 | 5 | 推荐使用 `PHP `_ 5.6 或更新版本。 6 | 7 | 虽然 CodeIgniter 也可以在 PHP 5.3.7 上运行,但是出于潜在的安全和性能问题, 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 其实只是数据库抽象层) 20 | -------------------------------------------------------------------------------- /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/installation/upgrade_301.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.0.0 to 3.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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | 16 | Step 2: Update your CLI error templates 17 | ======================================= 18 | 19 | Replace all files under your *application/views/errors/cli/* directory. 20 | -------------------------------------------------------------------------------- /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`` 或者设置为你自定义的路径。 -------------------------------------------------------------------------------- /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/overview/features.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | CodeIgniter 特性 3 | #################### 4 | 5 | 通过一个程序支持的特性并不能断定一个程序的好坏,因为特性不能体现出它良好的用户体验,不能体现出它优雅的设计,也不能显示出它代码质量如何,性能如何,细节处理的如何,安全性如何。判断程序好坏唯一的方法是体验一下并深入研究下它的代码。 6 | 7 | :doc:`安装 <../installation/index>` CodeIgniter 非常简单,所以我们鼓励你去安装它,同时,这里是一份 CodeIgniter 支持的主要特性列表。 8 | 9 | - 基于 MVC 体系 10 | - 超轻量级 11 | - 对数种数据库平台的全特性支持 12 | - 支持查询构造器 13 | - 表单与数据验证 14 | - 安全性与 XSS 过滤 15 | - 会话管理 16 | - 发送邮件类,支持附件、HTML 或文本邮件、多协议(sendmail、SMTP、Mail)及更多 17 | - 图像处理库(裁剪、缩放、旋转等),支持 GD、ImageMagick 和 NetPBM 18 | - 文件上传类 19 | - FTP 类 20 | - 本地化 21 | - 分页 22 | - 数据加密 23 | - 基准测试 24 | - 全页面缓存 25 | - 错误日志 26 | - 应用程序评测 27 | - 日历类 28 | - User-Agent 类 29 | - Zip 编码类 30 | - 模板引擎类 31 | - Trackback 类 32 | - XML-RPC 类 33 | - 单元测试类 34 | - 搜索引擎友好的 URL 35 | - 灵活的 URL 路由 36 | - 支持钩子和类扩展 37 | - 大量的辅助函数 38 | 39 | -------------------------------------------------------------------------------- /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/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/mimes.php 17 | ====================================== 18 | 19 | This config file has been updated to contain more user agent types, 20 | please copy it to *application/config/mimes.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. 27 | -------------------------------------------------------------------------------- /source/installation/upgrade_220.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.1.4 to 2.2.x 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/installation/upgrade_302.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.0.1 to 3.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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | 16 | Step 2: Update your application/config/constants.php file 17 | ========================================================= 18 | 19 | The *application/config/constants.php* file has been updated to check 20 | if constants aren't already defined before doing that, making it easier 21 | to add an environment-specific configuration. 22 | 23 | .. note:: If you've made modifications to this file, please make a 24 | backup first and cross-check the differences first. -------------------------------------------------------------------------------- /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/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: The language line; in an HTML label tag, if the ``$for`` parameter is not empty 32 | :rtype: string 33 | 34 | 此函数使用简单的语法从已加载的语言文件中返回一行文本。 35 | 这种简单的写法在视图文件中可能比调用 ``CI_Lang::line()`` 更顺手。 36 | 37 | Examples:: 38 | 39 | echo lang('language_key'); 40 | // Outputs: Language line 41 | 42 | echo lang('language_key', 'form_item_id', array('class' => 'myClass')); 43 | // Outputs: 44 | -------------------------------------------------------------------------------- /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/_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/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/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/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 | -------------------------------------------------------------------------------- /source/installation/index.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | 安装说明 3 | ######################### 4 | 5 | 通过下面四步来安装 CodeIgniter: 6 | 7 | #. 解压缩安装包; 8 | #. 将 CodeIgniter 文件夹及里面的文件上传到服务器,通常 *index.php* 文件将位于网站的根目录; 9 | #. 使用文本编辑器打开 *application/config/config.php* 文件设置你网站的根 URL,如果你想使用加密或会话,在这里设置上你的加密密钥; 10 | #. 如果你打算使用数据库,打开 *application/config/database.php* 文件设置数据库参数。 11 | 12 | 如果你想通过隐藏 CodeIgniter 的文件位置来增加安全性,你可以将 system 和 application 目录修改为其他的名字,然后打开主目录下的 *index.php* 文件将 ``$system_path`` 和 ``$application_folder`` 两个变量设置为你修改的名字。 13 | 14 | 为了达到更好的安全性,system 和 application 目录都应该放置在 Web 根目录之外,这样它们就不能通过浏览器直接访问。CodeIgniter 默认在每个目录下都包含了一个 *.htaccess* 文件,用于阻止直接访问,但是最好还是将它们移出能公开访问的地方,防止出现 Web 服务器配置更改或者 *.htaccess* 文件不被支持这些情况。 15 | 16 | 如果你想让 views 目录保持公开,也可以将你的 views 目录移出 application 目录。 17 | 18 | 移动完目录之后,打开 index.php 文件,分别设置好 ``$system_path`` 、 ``$application_folder`` 和 ``$view_folder`` 三个变量的值,最好设置成绝对路径,例如:“*/www/MyUser/system*”。 19 | 20 | 在生产环境还要额外再多一步,就是禁用 PHP 错误报告以及所有其他仅在开发环境使用的功能。在 CodeIgniter 中,可以通过设置 ``ENVIRONMENT`` 常量来做到这一点,这在 :doc:`安全 <../general/security>` 这篇指南中有着更详细的介绍。 21 | 22 | 以上就是全部安装过程! 23 | 24 | 如果你刚刚接触 CodeIgniter,请阅读用户指南的 :doc:`开始 <../overview/getting_started>` 部分,学习如何构造动态的 PHP 应用,开始享受吧! 25 | 26 | .. toctree:: 27 | :hidden: 28 | :titlesonly: 29 | 30 | downloads 31 | self 32 | upgrading 33 | troubleshooting 34 | -------------------------------------------------------------------------------- /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/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/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 文件进行命名。 55 | -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/breadcrumbs.html: -------------------------------------------------------------------------------- 1 |
2 | 24 |
25 |
26 | -------------------------------------------------------------------------------- /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/installation/upgrade_312.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.1.1 to 3.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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | 16 | Step 2: Update your "ci_sessions" database table 17 | ================================================ 18 | 19 | If you're using the :doc:`Session Library ` with the 20 | 'database' driver, you may have to ``ALTER`` your sessions table for your 21 | sessions to continue to work. 22 | 23 | .. note:: The table in question is not necessarily named "ci_sessions". 24 | It is what you've set as your ``$config['sess_save_path']``. 25 | 26 | This will only affect you if you've changed your ``session.hash_function`` 27 | *php.ini* setting to something like 'sha512'. Or if you've been running 28 | an older CodeIgniter version on PHP 7.1+. 29 | 30 | It is recommended that you do this anyway, just to avoid potential issues 31 | in the future if you do change your configuration. 32 | 33 | Just execute the one of the following SQL queries, depending on your 34 | database:: 35 | 36 | // MySQL: 37 | ALTER TABLE ci_sessions CHANGE id id varchar(128) NOT NULL; 38 | 39 | // PostgreSQL 40 | ALTER TABLE ci_sessions ALTER COLUMN id SET DATA TYPE varchar(128); 41 | -------------------------------------------------------------------------------- /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 | 如果你选择使用这个函数的话,你可以考虑使用 :doc:`缓存 <../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>` 。
68 | 


--------------------------------------------------------------------------------
/source/license.rst:
--------------------------------------------------------------------------------
 1 | #####################
 2 | The MIT License (MIT)
 3 | #####################
 4 | 
 5 | Copyright (c) 2014 - 2017, 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 - 2017, 不列颠哥伦比亚理工学院
32 | 
33 | 特此向任何得到本软件副本或相关文档的人授权:被授权人有权使用、复制、修改、
34 | 合并、出版、发布、散布、再授权和/或贩售软件及软件的副本,及授予被供应人
35 | 同等权利,只需服从以下义务:
36 | 
37 | 在软件和软件的所有副本中都必须包含以上版权声明和本许可声明。
38 | 
39 | 该软件是"按原样"提供的,没有任何形式的明示或暗示,包括但不限于为特定目的和
40 | 不侵权的适销性和适用性的保证担保。在任何情况下,作者或版权持有人,都无权要求
41 | 任何索赔,或有关损害赔偿的其他责任。无论在本软件的使用上或其他买卖交易中,
42 | 是否涉及合同,侵权或其他行为。
43 | 


--------------------------------------------------------------------------------
/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/installation/upgrade_310.rst:
--------------------------------------------------------------------------------
 1 | #############################
 2 | Upgrading from 3.0.6 to 3.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/* directory.
12 | 
13 | .. note:: If you have any custom developed files in these directories,
14 | 	please make copies of them first.
15 | 
16 | Step 2: Check your PHP version
17 | ==============================
18 | 
19 | We recommend always running versions that are `currently supported
20 | `_, which right now is at least PHP 5.6.
21 | 
22 | PHP 5.2.x versions are now officially not supported by CodeIgniter, and while 5.3.7+
23 | may be at least runnable, we strongly discourage you from using any PHP versions below
24 | the ones listed on the `PHP.net Supported Versions `_
25 | page.
26 | 
27 | Step 3: If you're using the 'odbc' database driver, check for usage of Query Builder
28 | ====================================================================================
29 | 
30 | :doc:`Query Builder <../database/query_builder>` functionality and ``escape()`` can
31 | no longer be used with the 'odbc' database driver.
32 | 
33 | This is because, due to its nature, the `ODBC extension for PHP `_
34 | does not provide a function that allows to safely escape user-supplied strings for usage
35 | inside an SQL query (which our :doc:`Query Builder <../database/query_builder>` relies on).
36 | 
37 | Thus, user inputs MUST be bound, as shown in :doc:`Running Queries <../database/queries>`,
38 | under the "Query Bindings" section.


--------------------------------------------------------------------------------
/source/installation/upgrading.rst:
--------------------------------------------------------------------------------
 1 | #################################
 2 | 从老版本升级
 3 | #################################
 4 | 
 5 | 请根据你要升级的版本阅读相应的升级注意事项。
 6 | 
 7 | .. toctree::
 8 | 	:titlesonly:
 9 | 
10 | 	从 3.1.4 升级到 3.1.5 
11 | 	从 3.1.3 升级到 3.1.4 
12 | 	从 3.1.2 升级到 3.1.3 
13 | 	从 3.1.1 升级到 3.1.2 
14 | 	从 3.1.0 升级到 3.1.1 
15 | 	从 3.0.6 升级到 3.1.0 
16 | 	从 3.0.5 升级到 3.0.6 
17 | 	从 3.0.4 升级到 3.0.5 
18 | 	从 3.0.3 升级到 3.0.4 
19 | 	从 3.0.2 升级到 3.0.3 
20 | 	从 3.0.1 升级到 3.0.2 
21 | 	从 3.0.0 升级到 3.0.1 
22 | 	从 2.2.x 升级到 3.0.x 
23 | 	从 2.2.2 升级到 2.2.3 
24 | 	从 2.2.1 升级到 2.2.2 
25 | 	从 2.2.0 升级到 2.2.1 
26 | 	从 2.1.4 升级到 2.2.x 
27 | 	从 2.1.3 升级到 2.1.4 
28 | 	从 2.1.2 升级到 2.1.3 
29 | 	从 2.1.1 升级到 2.1.2 
30 | 	从 2.1.0 升级到 2.1.1 
31 | 	从 2.0.3 升级到 2.1.0 
32 | 	从 2.0.2 升级到 2.0.3 
33 | 	从 2.0.1 升级到 2.0.2 
34 | 	从 2.0 升级到 2.0.1 
35 | 	从 1.7.2 升级到 2.0 
36 | 	从 1.7.1 升级到 1.7.2 
37 | 	从 1.7.0 升级到 1.7.1 
38 | 	从 1.6.3 升级到 1.7.0 
39 | 	从 1.6.2 升级到 1.6.3 
40 | 	从 1.6.1 升级到 1.6.2 
41 | 	从 1.6.0 升级到 1.6.1 
42 | 	从 1.5.4 升级到 1.6.0 
43 | 	从 1.5.3 升级到 1.5.4 
44 | 	从 1.5.2 升级到 1.5.3 
45 | 	从 1.5.0 or 1.5.1 升级到 1.5.2 
46 | 	从 1.4.1 升级到 1.5.0 
47 | 	从 1.4.0 升级到 1.4.1 
48 | 	从 1.3.3 升级到 1.4.0 
49 | 	从 1.3.2 升级到 1.3.3 
50 | 	从 1.3.1 升级到 1.3.2 
51 | 	从 1.3 升级到 1.3.1 
52 | 	从 1.2 升级到 1.3 
53 | 	从 1.1 升级到 1.2 
54 | 	从 Beta 1.0 升级到 Beta 1.1 
55 | 


--------------------------------------------------------------------------------
/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/installation/upgrade_313.rst:
--------------------------------------------------------------------------------
 1 | #############################
 2 | Upgrading from 3.1.2 to 3.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/* directory.
12 | 
13 | .. note:: If you have any custom developed files in these directories,
14 | 	please make copies of them first.
15 | 
16 | Step 2: Remove usage of nice_date() helper (deprecation)
17 | ========================================================
18 | 
19 | The :doc:`Date Helper <../helpers/date_helper>` function ``nice_date()`` is
20 | no longer useful since the introduction of PHP's `DateTime classes
21 | `_
22 | 
23 | You can replace it with the following:
24 | ::
25 | 
26 | 	DateTime::createFromFormat($input_format, $input_date)->format($desired_output_format);
27 | 
28 | Thus, ``nice_date()`` is now deprecated and scheduled for removal in
29 | CodeIgniter 3.2+.
30 | 
31 | .. note:: The function is still available, but you're strongly encouraged
32 | 	to remove its usage sooner rather than later.
33 | 
34 | Step 3: Remove usage of $config['standardize_newlines']
35 | =======================================================
36 | 
37 | The :doc:`Input Library <../libraries/input>` would optionally replace
38 | occurrences of `\r\n`, `\r`, `\n` in input data with whatever the ``PHP_EOL``
39 | value is on your system - if you've set ``$config['standardize_newlines']``
40 | to ``TRUE`` in your *application/config/config.php*.
41 | 
42 | This functionality is now deprecated and scheduled for removal in
43 | CodeIgniter 3.2.+.
44 | 
45 | .. note:: The functionality is still available, but you're strongly
46 | 	encouraged to remove its usage sooner rather than later.
47 | 


--------------------------------------------------------------------------------
/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 | ) -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | 5 | env: 6 | global: 7 | - GH_REF: github.com/CodeIgniter-Chinese/codeigniter-user-guide.git 8 | - secure: rLGHJqNPSYi9tyAXQIIUyiETbi8USNzsKeIudMOXUt42xjphnyn8rfPow0pGq1QMnr0XRRtTSuhNaSHHusqhIgjovCY/RabzdmUYl1ZeZ6x6Z5bwjtecm/P1IJUxX/Sy7ps+x2xugfeDU6vgHT9apActJJSYZHwYWBj/AW7IErCkWE3sgwn9IPpGqqbLK0mVGBvRlBP3wssuzBt7PiEvrZ+MKSgBNiYb8zP4A9D7GDDl7VPHC/ggkhzRZBCT+uAFH3yFRo38jNU9+MkUkMIwKjWJRrPwOz7epwjRIF2Ch5IMzkokB45QVZgO9ZfbyyvkTrG/381bzeVMTjhEImsvjfJMmrip+9QaRx5pfqaWcIPrRTl9oegUFEIweR9Edx24yAqVXvuMl6v5nNOiZcGcO6RJx5+341la/MogN8HWtkBtU++Ya4bHJPclj2hAmNYXmR+F/iKFrPz6oc7UCbF5+NHEPTvW/3wdPI/XAvCsI1x+8PvLI22Pjcy/7u4odsXzEzl1gDwUunVMW0gG2OgbsDx4Ma3zJmJK6En0vJmRgtIbaqZcwH5DsHNV0ituxxuALRG9aC8JwXj5CtDwOwoupiEs2GYkg6j+fgzCHiWi27LhJXWtPXY4pR1aX3rtgjsdVf/jWqmLjsVa6RGDsqJhcXenO+nhcoUNcvpZS0gozLw= 9 | 10 | cache: 11 | directories: 12 | - $HOME/.cache/pip 13 | 14 | sudo: false 15 | 16 | addons: 17 | apt: 18 | packages: 19 | - texlive-xetex 20 | - texlive-latex-recommended 21 | - texlive-fonts-recommended 22 | - texlive-latex-extra 23 | - lmodern 24 | 25 | install: 26 | - pip install --upgrade pip 27 | - pip install "Sphinx==1.2.3" 28 | - pip install "sphinxcontrib-phpdomain==0.1.3.post1" 29 | - cd cilexer && python setup.py install && cd .. 30 | 31 | script: 32 | - make html 33 | - wget http://codeigniter-chinese.github.io/codeigniter-user-guide/_fonts/fonts.tar.gz 34 | - mkdir $HOME/.fonts && tar xzf fonts.tar.gz && cp *.ttf $HOME/.fonts/ 35 | - make latexpdf 36 | 37 | after_success: 38 | - bash ./deploy-gh-pages.sh 39 | 40 | # Flags used here, not in `make html`: 41 | # -n Run in nit-picky mode. Currently, this generates warnings for all missing references. 42 | # -W Turn warnings into errors. This means that the build stops at the first warning and sphinx-build exits with exit status 1. 43 | 44 | git: 45 | depth: 10 46 | 47 | branches: 48 | only: 49 | - master 50 | -------------------------------------------------------------------------------- /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 | 贡献 CodeIgniter 59 | *************************** 60 | 61 | .. toctree:: 62 | :glob: 63 | :titlesonly: 64 | 65 | contributing/index 66 | 67 | ************** 68 | 常规主题 69 | ************** 70 | 71 | .. toctree:: 72 | :glob: 73 | :titlesonly: 74 | 75 | general/index 76 | 77 | ***************** 78 | 类库参考 79 | ***************** 80 | 81 | .. toctree:: 82 | :glob: 83 | :titlesonly: 84 | 85 | libraries/index 86 | 87 | ****************** 88 | 数据库参考 89 | ****************** 90 | 91 | .. toctree:: 92 | :glob: 93 | :titlesonly: 94 | 95 | database/index 96 | 97 | **************** 98 | 辅助函数参考 99 | **************** 100 | 101 | .. toctree:: 102 | :glob: 103 | :titlesonly: 104 | 105 | helpers/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 | database/index 120 | helpers/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 plural 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 90 | -------------------------------------------------------------------------------- /source/installation/upgrade_303.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.0.2 to 3.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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | 16 | Step 2: Make sure your 'base_url' config value is not empty 17 | =========================================================== 18 | 19 | When ``$config['base_url']`` is not set, CodeIgniter tries to automatically 20 | detect what your website's base URL is. This is done purely for convenience 21 | when you are starting development of a new application. 22 | 23 | Auto-detection is never reliable and also has security implications, which 24 | is why you should **always** have it manually configured! 25 | 26 | One of the changes in CodeIgniter 3.0.3 is how this auto-detection works, 27 | and more specifically it now falls back to the server's IP address instead 28 | of the hostname requested by the client. Therefore, if you've ever relied 29 | on auto-detection, it will change how your website works now. 30 | 31 | In case you need to allow e.g. multiple domains, or both http:// and 32 | https:// prefixes to be dynamically used depending on the request, 33 | remember that *application/config/config.php* is still a PHP script, in 34 | which you can create this logic with a few lines of code. For example:: 35 | 36 | $allowed_domains = array('domain1.tld', 'domain2.tld'); 37 | $default_domain = 'domain1.tld'; 38 | 39 | if (in_array($_SERVER['HTTP_HOST'], $allowed_domains, TRUE)) 40 | { 41 | $domain = $_SERVER['HTTP_HOST']; 42 | } 43 | else 44 | { 45 | $domain = $default_domain; 46 | } 47 | 48 | if ( ! empty($_SERVER['HTTPS'])) 49 | { 50 | $config['base_url'] = 'https://'.$domain; 51 | } 52 | else 53 | { 54 | $config['base_url'] = 'http://'.$domain; 55 | } 56 | -------------------------------------------------------------------------------- /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/installation/upgrade_306.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 3.0.5 to 3.0.6 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/* directory. 12 | 13 | .. note:: If you have any custom developed files in these directories, 14 | please make copies of them first. 15 | 16 | Step 2: Update your index.php file (optional) 17 | ============================================= 18 | 19 | We've made some tweaks to the index.php file, mostly related to proper 20 | usage of directory separators (i.e. use the ``DIRECTORY_SEPARATOR`` 21 | constant instead of a hard coded forward slash "/"). 22 | 23 | Nothing will break if you skip this step, but if you're running Windows 24 | or just want to be up to date with every change - we do recommend that 25 | you update your index.php file. 26 | 27 | *Tip: Just copy the ``ENVIRONMENT``, ``$system_path``, ``$application_folder`` 28 | and ``$view_folder`` declarations from the old file and put them into the 29 | new one, replacing the defaults.* 30 | 31 | Step 3: Remove 'prep_for_form' usage (deprecation) 32 | ================================================== 33 | 34 | The :doc:`Form Validation Library <../libraries/form_validation>` has a 35 | ``prep_for_form()`` method, which is/can also be used as a rule in 36 | ``set_rules()`` to automatically perform HTML encoding on input data. 37 | 38 | Automatically encoding input (instead of output) data is a bad practice in 39 | the first place, and CodeIgniter and PHP itself offer other alternatives 40 | to this method anyway. 41 | For example, :doc:`Form Helper <../helpers/form_helper>` functions will 42 | automatically perform HTML escaping when necessary. 43 | 44 | Therefore, the *prep_for_form* method/rule is pretty much useless and is now 45 | deprecated and scheduled for removal in 3.1+. 46 | 47 | .. note:: The method is still available, but you're strongly encouraged to 48 | remove its usage sooner rather than later. 49 | -------------------------------------------------------------------------------- /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 。 -------------------------------------------------------------------------------- /source/general/core_classes.rst: -------------------------------------------------------------------------------- 1 | ############################ 2 | 创建核心系统类 3 | ############################ 4 | 5 | 每次 CodeIgniter 运行时,都有一些基础类伴随着核心框架自动的被初始化。但你也可以使用你自己类来替代这些核心类或者扩展这些核心类。 6 | 7 | **大多数用户一般不会有这种需求,但对于那些想较大幅度的改变 CodeIgniter 的人来说,我们依然提供了替换和扩展核心类的选择。** 8 | 9 | .. note:: 改变系统核心类会产生很大影响,所以在你做之前必须清楚地知道自己正在做什么。 10 | 11 | 系统类清单 12 | ================= 13 | 14 | 以下是系统核心文件的清单,它们在每次 CodeIgniter 启动时被调用: 15 | 16 | - Benchmark 17 | - Config 18 | - Controller 19 | - Exceptions 20 | - Hooks 21 | - Input 22 | - Language 23 | - Loader 24 | - Log 25 | - Output 26 | - Router 27 | - Security 28 | - URI 29 | - Utf8 30 | 31 | 替换核心类 32 | ====================== 33 | 34 | 要使用你自己的系统类替换默认的系统类只需简单的将你自己的文件放入目录 *application/core* 下:: 35 | 36 | application/core/some_class.php 37 | 38 | 如果这个目录不存在,你可以创建一个。 39 | 40 | 任何一个和上面清单中同名的文件将被替换成核心类。 41 | 42 | 要注意的是,你的类名必须以 CI 开头,例如,你的文件是 Input.php,那么类应该命名为:: 43 | 44 | class CI_Input { 45 | 46 | } 47 | 48 | 扩展核心类 49 | ==================== 50 | 51 | 如果你只是想往现有类中添加一些功能,例如增加一两个方法,这时替换整个类感觉就有点杀鸡用牛刀了。在这种情况下,最好是使用扩展类的方法。扩展一个类和替换一个类的做法几乎是一样的,除了要注意以下几点: 52 | 53 | - 你定义的类必须继承自父类。 54 | - 你的类名和文件名必须以 MY\_ 开头。(这是可配置的,见下文) 55 | 56 | 举个例子,要扩展原始的 Input 类,你需要新建一个文件 application/core/MY_Input.php,然后像下面这样定义你的类:: 57 | 58 | class MY_Input extends CI_Input { 59 | 60 | } 61 | 62 | .. note:: 如果在你的类中需要使用构造函数,记得要调用父类的构造函数: 63 | 64 | :: 65 | 66 | class MY_Input extends CI_Input { 67 | 68 | public function __construct() 69 | { 70 | parent::__construct(); 71 | } 72 | } 73 | 74 | **提示:** 任何和父类同名的方法将会取代父类中的方法(这又被称作“方法覆盖”),这让你可以充分的利用并修改 CodeIgniter 的核心。 75 | 76 | 如果你扩展了控制器核心类,那么记得在你的应用程序控制器里继承你扩展的新类。 77 | 78 | :: 79 | 80 | class Welcome extends MY_Controller { 81 | 82 | public function __construct() 83 | { 84 | parent::__construct(); 85 | // Your own constructor code 86 | } 87 | 88 | public function index() 89 | { 90 | $this->load->view('welcome_message'); 91 | } 92 | } 93 | 94 | 自定义前缀 95 | ----------------------- 96 | 97 | 要想自定义你自己的类的前缀,打开文件 *application/config/config.php* 然后找到这项:: 98 | 99 | $config['subclass_prefix'] = 'MY_'; 100 | 101 | 请注意所有原始的 CodeIgniter 类库都以 CI\_ 开头,所以请不要使用这个作为你的自定义前缀。 102 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /source/installation/downloads.rst: -------------------------------------------------------------------------------- 1 | ####################### 2 | 下载 CodeIgniter 3 | ####################### 4 | 5 | - `CodeIgniter v3.1.5 (当前版本) `_ 6 | - `CodeIgniter v3.1.4 `_ 7 | - `CodeIgniter v3.1.3 `_ 8 | - `CodeIgniter v3.1.2 `_ 9 | - `CodeIgniter v3.1.1 `_ 10 | - `CodeIgniter v3.1.0 `_ 11 | - `CodeIgniter v3.0.6 `_ 12 | - `CodeIgniter v3.0.5 `_ 13 | - `CodeIgniter v3.0.4 `_ 14 | - `CodeIgniter v3.0.3 `_ 15 | - `CodeIgniter v3.0.2 `_ 16 | - `CodeIgniter v3.0.1 `_ 17 | - `CodeIgniter v3.0.0 `_ 18 | - `CodeIgniter v2.2.3 `_ 19 | - `CodeIgniter v2.2.2 `_ 20 | - `CodeIgniter v2.2.1 `_ 21 | - `CodeIgniter v2.2.0 `_ 22 | - `CodeIgniter v2.1.4 `_ 23 | - `CodeIgniter v2.1.3 `_ 24 | - `CodeIgniter v2.1.2 `_ 25 | - `CodeIgniter v2.1.1 `_ 26 | - `CodeIgniter v2.1.0 `_ 27 | 28 | ****** 29 | GitHub 30 | ****** 31 | 32 | `Git `_ 是一个分布式版本控制系统。 33 | 34 | CodeIgniter 可以在 `GitHub `_ 上公开访问。请注意,尽管我们在保持代码的基础功能上做出了大量的努力,但是我们并不能为开发分支的代码中的功能作担保。 35 | 36 | 从 2.0.3 版本开始,每个版本的稳定版都可以从 `GitHub Releases `_ 获取。 37 | -------------------------------------------------------------------------------- /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 = NULL[, $httponly = NULL]]]]]]]) 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 | -------------------------------------------------------------------------------- /cilexer/cilexer/cilexer.py: -------------------------------------------------------------------------------- 1 | # CodeIgniter 2 | # https://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 - 2017, 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. (https://ellislab.com/) 29 | # Copyright (c) 2014 - 2016, 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/helpers.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | 查询辅助函数 3 | #################### 4 | 5 | 关于执行查询的信息 6 | ================================== 7 | 8 | **$this->db->insert_id()** 9 | 10 | 当执行 INSERT 语句时,这个方法返回新插入行的ID。 11 | 12 | .. note:: If using the PDO driver with PostgreSQL, or using the Interbase 13 | driver, this function requires a $name parameter, which specifies the 14 | appropriate sequence to check for the insert id. 15 | 16 | **$this->db->affected_rows()** 17 | 18 | 当执行 INSERT、UPDATE 等写类型的语句时,这个方法返回受影响的行数。 19 | 20 | .. note:: 在 MySQL 中执行 "DELETE FROM TABLE" 语句返回受影响的行数为 0 。 21 | 为了让这个方法返回正确的受影响行数,数据库类对此做了一点小 hack。 22 | 默认情况下,这个 hack 是启用的,你可以在数据库驱动文件中关闭它。 23 | 24 | **$this->db->last_query()** 25 | 26 | 该方法返回上一次执行的查询语句(是查询语句,不是结果)。 27 | 举例:: 28 | 29 | $str = $this->db->last_query(); 30 | 31 | // Produces: SELECT * FROM sometable.... 32 | 33 | 34 | .. note:: 将数据库配置文件中的 **save_queries** 设置为 FALSE 可以让这个方法无效。 35 | 36 | 关于数据库的信息 37 | =============================== 38 | 39 | **$this->db->count_all()** 40 | 41 | 该方法用于获取数据表的总行数,第一个参数为表名,例如:: 42 | 43 | echo $this->db->count_all('my_table'); 44 | 45 | // Produces an integer, like 25 46 | 47 | **$this->db->platform()** 48 | 49 | 该方法输出你正在使用的数据库平台(MySQL,MS SQL,Postgres 等):: 50 | 51 | echo $this->db->platform(); 52 | 53 | **$this->db->version()** 54 | 55 | 该方法输出你正在使用的数据库版本:: 56 | 57 | echo $this->db->version(); 58 | 59 | 让你的查询更简单 60 | ========================== 61 | 62 | **$this->db->insert_string()** 63 | 64 | 这个方法简化了 INSERT 语句的书写,它返回一个正确格式化的 INSERT 语句。 65 | 举例:: 66 | 67 | $data = array('name' => $name, 'email' => $email, 'url' => $url); 68 | 69 | $str = $this->db->insert_string('table_name', $data); 70 | 71 | 第一个参数为表名,第二个参数是一个关联数组,表示待插入的数据。 72 | 上面的例子生成的 SQL 语句如下:: 73 | 74 | INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com') 75 | 76 | .. note:: 所有的值自动被转义,生成安全的查询语句。 77 | 78 | **$this->db->update_string()** 79 | 80 | 这个方法简化了 UPDATE 语句的书写,它返回一个正确格式化的 UPDATE 语句。 81 | 举例:: 82 | 83 | $data = array('name' => $name, 'email' => $email, 'url' => $url); 84 | 85 | $where = "author_id = 1 AND status = 'active'"; 86 | 87 | $str = $this->db->update_string('table_name', $data, $where); 88 | 89 | 第一个参数是表名,第二个参数是一个关联数组,表示待更新的数据,第三个参数 90 | 是个 WHERE 子句。上面的例子生成的 SQL 语句如下:: 91 | 92 | UPDATE table_name SET name = 'Rick', email = 'rick@example.com', url = 'example.com' WHERE author_id = 1 AND status = 'active' 93 | 94 | .. note:: 所有的值自动被转义,生成安全的查询语句。 95 | -------------------------------------------------------------------------------- /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 开源许可协议授权,你可以任意使用。阅读 :doc:`许可协议 <../license>` 了解更多内容。 18 | 19 | CodeIgniter 是轻量级的 20 | =========================== 21 | 22 | 真正的轻量级。我们的核心系统只需要一些非常小的库,这和那些 23 | 需要大量资源的框架完全相反。而且,库都是根据请求动态加载, 24 | 你需要什么才加载什么,所以核心系统是个非常轻快的系统。 25 | 26 | CodeIgniter 是快速的 27 | ====================== 28 | 29 | 真正的快速。我们保证你很难找到一个比 CodeIgniter 性能更好的框架。 30 | 31 | CodeIgniter 使用 M-V-C 架构 32 | ============================ 33 | 34 | CodeIgniter 使用了模型-视图-控制器 架构,它能很好的将逻辑层和表示层分离。 35 | 特别是对于那些使用了模板文件的项目来说更好,它能减少模板文件中的代码量。 36 | 我们在介绍 MVC 架构的页面有更详细的介绍。 37 | 38 | CodeIgniter 生成干净的 URL 39 | ================================ 40 | 41 | CodeIgniter 生成的 URL 非常干净,而且对搜索引擎友好。不同于标准的 42 | “查询字符串” 方法, CodeIgniter 使用了基于段的方法:: 43 | 44 | example.com/news/article/345 45 | 46 | .. note:: 默认 URL 中会包含 *index.php* 文件,但是可以通过更改 *.htaccess* 文件来去掉它。 47 | 48 | CodeIgniter 功能强大 49 | ========================= 50 | 51 | CodeIgniter 拥有全面的类库,能满足大多数 Web 开发任务的需要, 52 | 例如:访问数据库,发送邮件,验证表单数据,会话管理,处理图像, 53 | 处理 XML-RPC 数据,等等等等。 54 | 55 | CodeIgniter 是可扩展的 56 | ========================= 57 | 58 | 系统可以非常简单的通过你自己的类库和辅助函数来扩展,也可以通过 59 | 类扩展或系统钩子来实现。 60 | 61 | CodeIgniter 不需要模板引擎 62 | ============================================== 63 | 64 | 尽管 CodeIgniter 自带了一个非常简单的可选的模板解析器,但并不强制你 65 | 使用模板。模板引擎的性能无法和原生的 PHP 代码相比,另外使用模板引擎 66 | 还需要学习一种新的语法,而使用原生 PHP 代码只需要你掌握基本的 PHP 67 | 语法即可。看下面的 PHP 代码:: 68 | 69 |
    70 | 71 |
  • 72 | 73 |
74 | 75 | 再来看看使用模板引擎的代码(伪代码):: 76 | 77 |
    78 | {foreach from=$addressbook item="name"} 79 |
  • {$name}
  • 80 | {/foreach} 81 |
82 | 83 | 的确,模板引擎中的代码要清晰一点,但是它是以性能为代价的, 84 | 因为模板引擎中的伪代码必须要转换回 PHP 代码才能运行。 85 | 我们的一个目标是: *性能最大化* ,所以,我们决定不使用模板引擎。 86 | 87 | CodeIgniter 拥有全面的文档 88 | ==================================== 89 | 90 | 程序员们都喜欢写代码而讨厌写文档,当然,我们也不例外。 91 | 但是由于文档和代码是一样重要的,所以我们尽力来做好它。 92 | 我们的代码非常简洁并且注释也非常全面。 93 | 94 | CodeIgniter 拥有一个友好的用户社区 95 | ============================================= 96 | 97 | 你可以看到我们的社区用户在不断的增长,在 98 | `社区论坛 `_ 里活跃的参与着各种话题。 99 | -------------------------------------------------------------------------------- /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/_themes/sphinx_rtd_theme/pulldown.html: -------------------------------------------------------------------------------- 1 | 13 | 18 | -------------------------------------------------------------------------------- /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/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 | :: 56 | 57 | $query = $this->db->query('SELECT name FROM my_table LIMIT 1'); 58 | $row = $query->row(); 59 | echo $row->name; 60 | 61 | 上面的 ``row()`` 函数返回一个**对象**。例如:``$row->name`` 62 | 63 | 单结果标准查询(数组形式) 64 | ================================================= 65 | 66 | :: 67 | 68 | $query = $this->db->query('SELECT name FROM my_table LIMIT 1'); 69 | $row = $query->row_array(); 70 | echo $row['name']; 71 | 72 | 上面的 ``row_array()`` 函数返回一个**数组**。例如:``$row['name']`` 73 | 74 | 标准插入 75 | =============== 76 | 77 | :: 78 | 79 | $sql = "INSERT INTO mytable (title, name) VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")"; 80 | $this->db->query($sql); 81 | echo $this->db->affected_rows(); 82 | 83 | 使用查询构造器查询数据 84 | =========================== 85 | 86 | :doc:`查询构造器模式 ` 提供给我们一种简单的查询数据的途径:: 87 | 88 | $query = $this->db->get('table_name'); 89 | 90 | foreach ($query->result() as $row) 91 | { 92 | echo $row->title; 93 | } 94 | 95 | 上面的 ``get()`` 函数从给定的表中查询出所有的结果。:doc:`查询构造器 ` 提供了所有数据库操作的快捷函数。 96 | 97 | 使用查询构造器插入数据 98 | =========================== 99 | 100 | :: 101 | 102 | $data = array( 103 | 'title' => $title, 104 | 'name' => $name, 105 | 'date' => $date 106 | ); 107 | 108 | // 109 | // 生成这样的SQL代码: 110 | // INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}') 111 | // 112 | $this->db->insert('mytable', $data); 113 | 114 | -------------------------------------------------------------------------------- /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 | .. php: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);
105 | 


--------------------------------------------------------------------------------
/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)
 68 | 
 69 | 	:param	string	$level: Log level: 'error', 'debug' or 'info'
 70 | 	:param	string	$message: Message to log
 71 | 	:rtype:	void
 72 | 
 73 | 	该函数用于向你的日志文件中写入信息,第一个参数你必须提供
 74 | 	三个信息级别中的一个,用于指定记录的是什么类型的信息(调试,
 75 | 	错误和一般信息),第二个参数为信息本身。
 76 | 
 77 | 	示例::
 78 | 
 79 | 		if ($some_var == '')
 80 | 		{
 81 | 			log_message('error', 'Some variable did not contain a value.');
 82 | 		}
 83 | 		else
 84 | 		{
 85 | 			log_message('debug', 'Some variable was correctly set');
 86 | 		}
 87 | 
 88 | 		log_message('info', 'The purpose of some variable is to provide some value.');
 89 | 
 90 | 	有三种信息类型:
 91 | 
 92 | 	#. 错误信息。这些是真正的错误,例如 PHP 错误或用户错误。
 93 | 	#. 调试信息。这些信息帮助你调试程序,例如,你可以在一个类
 94 | 	   初始化的地方记录下来作为调试信息。
 95 | 	#. 一般信息。这些是最低级别的信息,简单的给出程序运行过程中的一些信息。
 96 | 
 97 | 	.. note:: 为了保证日志文件被正确写入,*logs/* 目录必须设置为可写的。
 98 | 		此外,你必须要设置 *application/config/config.php* 文件中的
 99 | 		"threshold"  参数,举个例子,例如你只想记录错误信息,而不想
100 | 		记录另外两种类型的信息,可以通过这个参数来控制。如果你将
101 | 		该参数设置为 0 ,日志就相当于被禁用了。
102 | 


--------------------------------------------------------------------------------
/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_off()`` 方法来实现::
 71 | 
 72 | 	$this->db->trans_off();
 73 | 
 74 | 	$this->db->trans_start();
 75 | 	$this->db->query('AN SQL QUERY...');
 76 | 	$this->db->trans_complete();
 77 | 
 78 | 当事务被禁用时,你的查询会自动提交,就跟没有使用事务一样, ``trans_start()`` 和 ``trans_complete()`` 等方法调用也将被忽略。
 79 | 
 80 | 测试模式(Test Mode)
 81 | ======================
 82 | 
 83 | 你可以选择性的将你的事务系统设置为 “测试模式”,这将导致你的所有
 84 | 查询都被回滚,就算查询成功执行也一样。要使用 “测试模式”,你只需要
 85 | 将 $this->db->trans_start() 函数的第一个参数设置为 TRUE 即可::
 86 | 
 87 | 	$this->db->trans_start(TRUE); // Query will be rolled back
 88 | 	$this->db->query('AN SQL QUERY...');
 89 | 	$this->db->trans_complete();
 90 | 
 91 | 手工运行事务
 92 | =============================
 93 | 
 94 | 如果你想手工运行事务,可以像下面这样做::
 95 | 
 96 | 	$this->db->trans_begin();
 97 | 
 98 | 	$this->db->query('AN SQL QUERY...');
 99 | 	$this->db->query('ANOTHER QUERY...');
100 | 	$this->db->query('AND YET ANOTHER QUERY...');
101 | 
102 | 	if ($this->db->trans_status() === FALSE)
103 | 	{
104 | 		$this->db->trans_rollback();
105 | 	}
106 | 	else
107 | 	{
108 | 		$this->db->trans_commit();
109 | 	}
110 | 
111 | .. note:: 手动运行事务时,请务必使用 $this->db->trans_begin() 方法,
112 | 	**而不是** $this->db->trans_start() 方法。
113 | 


--------------------------------------------------------------------------------
/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 | 20 | 42 | 43 | {% endif %} 44 |
45 | {% endif %} 46 | 47 |
48 | 49 |
50 |

51 | {%- if show_copyright %} 52 | {%- if hasdoc('copyright') %} 53 | {% trans path=pathto('copyright'), copyright=copyright|e %}© 版权所有 {{ copyright }}.{% endtrans %} 54 | {%- else %} 55 | {% trans copyright=copyright|e %}© 版权所有 {{ copyright }}.{% endtrans %} 56 | {%- endif %} 57 | {%- endif %} 58 | 59 | {%- if last_updated %} 60 | {% trans last_updated=last_updated|e %} 最后修改: {{ last_updated }}.{% endtrans %} 61 | {%- endif %} 62 |

63 | 64 |

aneasystone 制作的手册为基础构建

65 |
66 | 67 | {% trans %} 68 |

基于 Sphinx 并使用 Read the Docs 提供的风格构建

69 |

70 | Github 简体中文翻译 71 | · 72 | 离线版压缩包下载 73 | · 74 | PDF 版下载 75 |

76 | {% endtrans %} 77 | 78 |
79 | -------------------------------------------------------------------------------- /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 | 你也可以使用 lambda 表达式/匿名函数(或闭包)作为钩子,这样写起来更简单:: 51 | 52 | $hook['post_controller'] = function() 53 | { 54 | /* do something here */ 55 | }; 56 | 57 | 多次调用同一个挂钩点 58 | =============================== 59 | 60 | 如果你想在同一个挂钩点处添加多个脚本,只需要将钩子数组变成二维数组即可,像这样:: 61 | 62 | $hook['pre_controller'][] = array( 63 | 'class' => 'MyClass', 64 | 'function' => 'MyMethod', 65 | 'filename' => 'Myclass.php', 66 | 'filepath' => 'hooks', 67 | 'params' => array('beer', 'wine', 'snacks') 68 | ); 69 | 70 | $hook['pre_controller'][] = array( 71 | 'class' => 'MyOtherClass', 72 | 'function' => 'MyOtherMethod', 73 | 'filename' => 'Myotherclass.php', 74 | 'filepath' => 'hooks', 75 | 'params' => array('red', 'yellow', 'blue') 76 | ); 77 | 78 | 注意数组索引后面多了个中括号:: 79 | 80 | $hook['pre_controller'][] 81 | 82 | 这可以让你在同一个挂钩点处执行多个脚本,多个脚本执行顺序就是你定义数组的顺序。 83 | 84 | 挂钩点 85 | =========== 86 | 87 | 以下是所有可用挂钩点的一份列表: 88 | 89 | - **pre_system** 90 | 在系统执行的早期调用,这个时候只有 基准测试类 和 钩子类 被加载了, 91 | 还没有执行到路由或其他的流程。 92 | - **pre_controller** 93 | 在你的控制器调用之前执行,所有的基础类都已加载,路由和安全检查也已经完成。 94 | - **post_controller_constructor** 95 | 在你的控制器实例化之后立即执行,控制器的任何方法都还尚未调用。 96 | - **post_controller** 97 | 在你的控制器完全运行结束时执行。 98 | - **display_override** 99 | 覆盖 ``_display()`` 方法,该方法用于在系统执行结束时向浏览器发送最终的页面结果。 100 | 这可以让你有自己的显示页面的方法。注意你可能需要使用 ``$this->CI =& get_instance()`` 101 | 方法来获取 CI 超级对象,以及使用 ``$this->CI->output->get_output()`` 方法来 102 | 获取最终的显示数据。 103 | - **cache_override** 104 | 使用你自己的方法来替代 :doc:`输出类 <../libraries/output>` 中的 ``_display_cache()`` 105 | 方法,这让你有自己的缓存显示机制。 106 | - **post_system** 107 | 在最终的页面发送到浏览器之后、在系统的最后期被调用。 108 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | .. image:: https://travis-ci.org/CodeIgniter-Chinese/codeigniter-user-guide.svg?branch=master 2 | :target: https://travis-ci.org/CodeIgniter-Chinese/codeigniter-user-guide 3 | 4 | ######################## 5 | CodeIgniter 3.x 中文手册 6 | ######################## 7 | 8 | 这里是 CodeIgniter 3.x 的中文手册,翻译自 CodeIgniter `官方的英文手册 `_ , 9 | 以 `aneasystone `_ 翻译的手册为基础制作。 10 | 11 | 如果想修改或翻译本手册,请在 Github 上提交 Issues ,或者 Fork 本项目作出修改,然后提交 Pull Request , 12 | 感谢大家为手册做出的贡献。 13 | 14 | ******** 15 | 安装步骤 16 | ******** 17 | 18 | CodeIgniter 的用户指南是使用 Sphinx 软件进行管理,并可以生成各种不同的格式。 19 | 所有的页面都是采用 `ReStructured Text `_ 20 | 格式书写,这种格式非常方便人们阅读。 21 | 22 | 安装条件 23 | ======== 24 | 25 | Sphinx 软件依赖于 Python,如果你使用的是 OS X 系统,则系统已经自带 Python 了。 26 | 你可以在终端中执行不带参数的 ``python`` 命令,以确认你的系统是否已安装 Python 。 27 | 如果你已安装,会显示出你当前所使用的版本。 28 | 如果显示的不是2.7以上版本,你可以去这里下载并安装2.7.2 29 | http://python.org/download/releases/2.7.2/ 30 | 31 | 安装 32 | ==== 33 | 34 | 1. 安装 `easy_install `_ 35 | 2. ``easy_install "sphinx==1.2.3"`` 36 | 3. ``easy_install "sphinxcontrib-phpdomain==0.1.3.post1"`` 37 | 4. 安装 CI Lexer,它可以高亮文档中的 PHP, HTML, CSS, 和 JavaScript 代码 (参见 *cilexer/README*) 38 | 5. 返回代码库根目录 39 | 6. ``make html`` 40 | 41 | 译注: 42 | 43 | 1. Ubuntu 系统上安装 easy_install 可以直接:``sudo apt-get install python-setuptools`` 44 | 2. easy_install 需要 root 权限,前面加上 sudo 45 | 46 | 支持中文搜索(可选) 47 | ================== 48 | 49 | 以 Ubuntu 16.10 为例,其它系统类似: 50 | 51 | 1. 执行 ``cd /usr/local/lib/python2.7/dist-packages/Sphinx-1.2.3-py2.7.egg/sphinx/search`` 52 | 2. 复制文档目录下的 ``zh_CN.py`` 到当前目录 53 | 3. 编辑当前目录下的 ``__init__.py`` 54 | 找到: 55 | :: 56 | 57 | from sphinx.search import en, ja 58 | languages = { 59 | 'en': en.SearchEnglish, 60 | 'ja': ja.SearchJapanese, 61 | } 62 | 63 | 修改成: 64 | :: 65 | 66 | from sphinx.search import en, ja, zh_CN 67 | languages = { 68 | 'en': en.SearchEnglish, 69 | 'ja': ja.SearchJapanese, 70 | 'zh_CN': zh_CN.SearchChinese, 71 | } 72 | 73 | 编辑并创建文档 74 | ============== 75 | 76 | 所有的源文件都在 *source/* 目录下,在这里你可以添加新的文档或修改已有的文档。 77 | 78 | 那么,HTML 文档在哪里? 79 | ======================= 80 | 81 | 很显然,HTML 文档才是我们最关心的,因为这毕竟才是用户最终看到的。 82 | 由于对自动生成的文件进行版本控制没有意义,所以它们并不在版本控制之下。 83 | 你如果想要预览 HTML 文档,你可以重新生成它们。生成 HTML 文档非常简单, 84 | 首先进入你的用户指南目录,然后执行上面安装步骤中的最后一步:: 85 | 86 | make html 87 | 88 | 你将会看到正在编译中的信息,编译成功后,生成的用户指南和图片都位于 *build/html/* 目录下。 89 | 在 HTML 第一次编译之后,后面将只会针对修改的文件进行重编译,这将大大的节约我们的时间。 90 | 如果你想再重新全部编译一次,只需删除 *build* 目录然后编译即可。 91 | 92 | 不想自己编译? 93 | ============== 94 | 95 | 如果不想自己编译,那么可以直接 `在线访问 `_ 、 `打包下载 `_ 或者 `下载PDF版 `_。 96 | 97 | 98 | ******** 99 | 风格指南 100 | ******** 101 | 102 | 使用 Sphinx 为 CodeIgniter 编写文档,请参考 source/documentation/index.rst 的一般准则。 103 | -------------------------------------------------------------------------------- /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/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 | | https://codeigniter.com/user_guide/general/core_classes.html 53 | | https://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/_themes/sphinx_rtd_theme/static/css/theme_cn.css: -------------------------------------------------------------------------------- 1 | .highlighted { 2 | padding: 0px !important; 3 | font-weight: inherit !important; 4 | background-color: #f1d40f !important; 5 | } 6 | 7 | #nav { 8 | background-color: #494949; 9 | margin: 0; 10 | padding: 0; 11 | display: none; 12 | } 13 | 14 | #nav2 { 15 | background: url(data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAMgAzAwERAAIRAQMRAf/EAFkAAQADAQAAAAAAAAAAAAAAAAABBQcIAQEAAAAAAAAAAAAAAAAAAAAAEAABAgYDAAAAAAAAAAAAAAAAAVERAtMEFJRVBxgRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AMRAAAAAAAA7a87dZcCu3e1wHnbrLgV272uA87dZcCu3e1wHnbrLgV272uA87dZcCu3e1wHnbrLgV272uA87dZcCu3e1wN/wJGAYEjAMCRgGBIwDAkYBgSMAwJGAsoIwCCMAgjAIIwCCMAgjAIIwEgAAAAAAAAAAAAAAAAAAAAAAAH//2Q==) repeat-x scroll left top transparent; 16 | margin: 0; 17 | padding: 0 310px 0 0; 18 | text-align: right; 19 | display: none; 20 | } 21 | 22 | #nav_inner { 23 | background-color: transparent; 24 | /*font-family: "\5FAE\8F6F\96C5\9ED1","Microsoft Yahei", Lucida Grande,Verdana,Geneva,sans-serif;*/ 25 | font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, WenQuanYi Micro Hei, Microsoft Yahei, Lucida Grande,Verdana,Geneva,sans-serif; 26 | font-size: 12px; 27 | margin: 0; 28 | padding: 8px 12px 0 20px; 29 | } 30 | 31 | div#pulldown-menu { 32 | -moz-column-count: 5; 33 | -moz-column-gap: 20px; 34 | -webkit-column-count: 5; 35 | -webkit-column-gap: 20px; 36 | column-count: 5; 37 | column-gap: 20px; 38 | -webkit-column-rule: 1px groove #b8b8b8; 39 | -moz-column-rule: 1px groove #b8b8b8; 40 | column-rule: 1px groove #b8b8b8; 41 | } 42 | 43 | #pulldown-menu > ul { 44 | padding-top: 10px; 45 | padding-bottom: 10px; 46 | -webkit-column-break-inside: avoid; /*Chrome, Safari*/ 47 | display: table; /*Firefox*/ 48 | break-inside: avoid; /*IE 10+ theoretically*/ 49 | } 50 | 51 | #pulldown-menu ul li.toctree-l2 { 52 | font-size: 0.82em; 53 | margin-left: 20px; 54 | list-style-image: url(data:image/gif;base64,R0lGODlhCwAJALMJAO7u7uTk5PLy8unp6fb29t7e3vj4+Li4uIWFheTk5AAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAkALAAAAAALAAkAAAQoMJ1JqTQ4Z3SI98jHCWSJkByArCyiHkMsIzEX3DeCc0Xv+4hEa5iIAAA7); 55 | } 56 | 57 | #pulldown-menu ul li.toctree-l1 a { 58 | color: #ffffff; 59 | text-decoration: none; 60 | font-size: 14px; 61 | font-family: "Roboto Slab","ff-tisa-web-pro",-apple-system, BlinkMacSystemFont, Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, WenQuanYi Micro Hei, Microsoft Yahei, sans-serif; 62 | font-weight: 700; 63 | line-height: 2em; 64 | } 65 | 66 | #pulldown-menu ul li.toctree-l2 a { 67 | text-decoration: none; 68 | font-size: 12px; 69 | line-height: 1.5em; 70 | font-weight: 300; 71 | font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, WenQuanYi Micro Hei, Microsoft Yahei, Lucida Grande,Verdana,Geneva,sans-serif; 72 | color: #aaaaaa; 73 | } 74 | 75 | /*hide pulldown menu on mobile devices*/ 76 | @media (max-width: 768px) { /*tablet size defined by theme*/ 77 | #closeMe { 78 | display: none; 79 | } 80 | 81 | #pulldown { 82 | display: none; 83 | } 84 | 85 | #openToc { 86 | display: none; 87 | } 88 | } 89 | 90 | .rst-footer-buttons .fa-arrow-circle-left { 91 | margin-right: 5px; 92 | } 93 | 94 | .rst-footer-buttons .fa-arrow-circle-right { 95 | margin-left: 5px; 96 | } 97 | 98 | #notes { 99 | margin-top: 40px; 100 | margin-bottom: 40px; 101 | } 102 | #notes .reward { 103 | text-align: center; 104 | } 105 | em { 106 | font-style: normal; 107 | } 108 | -------------------------------------------------------------------------------- /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 get_last_ten_entries() 23 | { 24 | $query = $this->db->get('entries', 10); 25 | return $query->result(); 26 | } 27 | 28 | public function insert_entry() 29 | { 30 | $this->title = $_POST['title']; // please read the below note 31 | $this->content = $_POST['content']; 32 | $this->date = time(); 33 | 34 | $this->db->insert('entries', $this); 35 | } 36 | 37 | public function update_entry() 38 | { 39 | $this->title = $_POST['title']; 40 | $this->content = $_POST['content']; 41 | $this->date = time(); 42 | 43 | $this->db->update('entries', $this, array('id' => $_POST['id'])); 44 | } 45 | 46 | } 47 | 48 | .. note:: 上面的例子中使用了 :doc:`查询构造器 <../database/query_builder>` 数据库方法。 49 | 50 | .. note:: 为了保证简单,我们在这个例子中直接使用了 ``$_POST`` 数据,这其实是个不好的实践, 51 | 一个更通用的做法是使用 :doc:`输入库 <../libraries/input>` 的 ``$this->input->post('title')``。 52 | 53 | 剖析模型 54 | ================== 55 | 56 | 模型类位于你的 **application/models/** 目录下,如果你愿意,也可以在里面创建子目录。 57 | 58 | 模型类的基本原型如下:: 59 | 60 | class Model_name extends CI_Model { 61 | 62 | public function __construct() 63 | { 64 | parent::__construct(); 65 | // Your own constructor code 66 | } 67 | 68 | } 69 | 70 | 其中,**Model_name** 是类的名字,类名的第一个字母 **必须** 大写,其余部分小写。确保你的类 71 | 继承 CI_Model 基类。 72 | 73 | 文件名和类名应该一致,例如,如果你的类是这样:: 74 | 75 | class User_model extends CI_Model { 76 | 77 | public function __construct() 78 | { 79 | parent::__construct(); 80 | // Your own constructor code 81 | } 82 | 83 | } 84 | 85 | 那么你的文件名应该是这样:: 86 | 87 | application/models/User_model.php 88 | 89 | 加载模型 90 | =============== 91 | 92 | 你的模型一般会在你的 :doc:`控制器 ` 的方法中加载并调用, 93 | 你可以使用下面的方法来加载模型:: 94 | 95 | $this->load->model('model_name'); 96 | 97 | 如果你的模型位于一个子目录下,那么加载时要带上你的模型所在目录的相对路径, 98 | 例如,如果你的模型位于 *application/models/blog/Queries.php* , 99 | 你可以这样加载它:: 100 | 101 | $this->load->model('blog/queries'); 102 | 103 | 加载之后,你就可以通过一个和你的类同名的对象访问模型中的方法。 104 | :: 105 | 106 | $this->load->model('model_name'); 107 | 108 | $this->model_name->method(); 109 | 110 | 如果你想将你的模型对象赋值给一个不同名字的对象,你可以使用 ``$this->load->model()`` 111 | 方法的第二个参数:: 112 | 113 | $this->load->model('model_name', 'foobar'); 114 | 115 | $this->foobar->method(); 116 | 117 | 这里是一个例子,该控制器加载一个模型,并处理一个视图:: 118 | 119 | class Blog_controller extends CI_Controller { 120 | 121 | public function blog() 122 | { 123 | $this->load->model('blog'); 124 | 125 | $data['query'] = $this->blog->get_last_ten_entries(); 126 | 127 | $this->load->view('blog', $data); 128 | } 129 | } 130 | 131 | 132 | 模型的自动加载 133 | =================== 134 | 135 | 如果你发现你有一个模型需要在整个应用程序中使用,你可以让 CodeIgniter 136 | 在系统初始化时自动加载它。打开 **application/config/autoload.php** 文件, 137 | 并将该模型添加到 autoload 数组中。 138 | 139 | 连接数据库 140 | =========================== 141 | 142 | 当模型加载之后,它 **并不会** 自动去连接你的数据库,下面是一些关于 143 | 数据库连接的选项: 144 | 145 | - 你可以在控制器或模型中使用 :doc:`标准的数据库方法 <../database/connecting>` 连接数据库。 146 | - 你可以设置第三个参数为 TRUE 让模型在加载时自动连接数据库,会使用你的数据库配置文件中的配置:: 147 | 148 | $this->load->model('model_name', '', TRUE); 149 | 150 | - 你还可以通过第三个参数传一个数据库连接配置:: 151 | 152 | $config['hostname'] = 'localhost'; 153 | $config['username'] = 'myusername'; 154 | $config['password'] = 'mypassword'; 155 | $config['database'] = 'mydatabase'; 156 | $config['dbdriver'] = 'mysqli'; 157 | $config['dbprefix'] = ''; 158 | $config['pconnect'] = FALSE; 159 | $config['db_debug'] = TRUE; 160 | 161 | $this->load->model('model_name', '', $config); 162 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | --------------------------------------------------------------------------------