├── .drone.yml ├── .editorconfig ├── .gitignore ├── Makefile ├── README.md ├── cilexer ├── README ├── cilexer │ ├── __init__.py │ └── cilexer.py └── setup.py └── source ├── DCO.rst ├── _themes └── sphinx_rtd_theme │ ├── LICENSE │ ├── __init__.py │ ├── breadcrumbs.html │ ├── footer.html │ ├── layout.html │ ├── layout_old.html │ ├── search.html │ ├── searchbox.html │ ├── static │ ├── css │ │ ├── badge_only.css │ │ └── theme.css │ ├── fonts │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff │ └── js │ │ └── theme.js │ ├── theme.conf │ └── versions.html ├── changelog.rst ├── conf.py ├── contributing └── index.rst ├── database ├── caching.rst ├── call_function.rst ├── configuration.rst ├── connecting.rst ├── db_driver_reference.rst ├── examples.rst ├── forge.rst ├── helpers.rst ├── index.rst ├── metadata.rst ├── queries.rst ├── query_builder.rst ├── results.rst ├── transactions.rst └── utilities.rst ├── documentation ├── ELDocs.tmbundle.zip └── index.rst ├── general ├── alternative_php.rst ├── ancillary_classes.rst ├── autoloader.rst ├── caching.rst ├── cli.rst ├── common_functions.rst ├── compatibility_functions.rst ├── controllers.rst ├── core_classes.rst ├── creating_drivers.rst ├── creating_libraries.rst ├── credits.rst ├── drivers.rst ├── environments.rst ├── errors.rst ├── helpers.rst ├── hooks.rst ├── index.rst ├── libraries.rst ├── managing_apps.rst ├── models.rst ├── profiling.rst ├── requirements.rst ├── reserved_names.rst ├── routing.rst ├── security.rst ├── styleguide.rst ├── urls.rst ├── views.rst └── welcome.rst ├── helpers ├── array_helper.rst ├── captcha_helper.rst ├── cookie_helper.rst ├── date_helper.rst ├── directory_helper.rst ├── download_helper.rst ├── email_helper.rst ├── file_helper.rst ├── form_helper.rst ├── html_helper.rst ├── index.rst ├── inflector_helper.rst ├── language_helper.rst ├── number_helper.rst ├── path_helper.rst ├── security_helper.rst ├── smiley_helper.rst ├── string_helper.rst ├── text_helper.rst ├── typography_helper.rst ├── url_helper.rst └── xml_helper.rst ├── images ├── appflowchart.gif ├── arrow.gif ├── ci-icon.ico ├── ci_logo.jpg ├── ci_logo_flame.jpg ├── file.gif ├── folder.gif └── smile.gif ├── index.rst ├── installation ├── downloads.rst ├── index.rst ├── troubleshooting.rst ├── upgrade_120.rst ├── upgrade_130.rst ├── upgrade_131.rst ├── upgrade_132.rst ├── upgrade_133.rst ├── upgrade_140.rst ├── upgrade_141.rst ├── upgrade_150.rst ├── upgrade_152.rst ├── upgrade_153.rst ├── upgrade_154.rst ├── upgrade_160.rst ├── upgrade_161.rst ├── upgrade_162.rst ├── upgrade_163.rst ├── upgrade_170.rst ├── upgrade_171.rst ├── upgrade_172.rst ├── upgrade_200.rst ├── upgrade_201.rst ├── upgrade_202.rst ├── upgrade_203.rst ├── upgrade_210.rst ├── upgrade_211.rst ├── upgrade_212.rst ├── upgrade_213.rst ├── upgrade_214.rst ├── upgrade_220.rst ├── upgrade_221.rst ├── upgrade_222.rst ├── upgrade_223.rst ├── upgrade_300.rst ├── upgrade_301.rst ├── upgrade_302.rst ├── upgrade_303.rst ├── upgrade_304.rst ├── upgrade_305.rst ├── upgrade_306.rst ├── upgrade_310.rst ├── upgrade_311.rst ├── upgrade_312.rst ├── upgrade_313.rst ├── upgrade_314.rst ├── upgrade_315.rst ├── upgrade_316.rst ├── upgrade_b11.rst └── upgrading.rst ├── libraries ├── benchmark.rst ├── caching.rst ├── calendar.rst ├── cart.rst ├── config.rst ├── email.rst ├── encrypt.rst ├── encryption.rst ├── file_uploading.rst ├── form_validation.rst ├── ftp.rst ├── image_lib.rst ├── index.rst ├── input.rst ├── javascript.rst ├── language.rst ├── loader.rst ├── migration.rst ├── output.rst ├── pagination.rst ├── parser.rst ├── security.rst ├── sessions.rst ├── table.rst ├── trackback.rst ├── typography.rst ├── unit_testing.rst ├── uri.rst ├── user_agent.rst ├── xmlrpc.rst └── zip.rst ├── license.rst ├── overview ├── appflow.rst ├── at_a_glance.rst ├── features.rst ├── getting_started.rst ├── goals.rst ├── index.rst └── mvc.rst └── tutorial ├── conclusion.rst ├── create_news_items.rst ├── index.rst ├── news_section.rst └── static_pages.rst /.drone.yml: -------------------------------------------------------------------------------- 1 | clone: 2 | git: 3 | image: plugins/git 4 | depth: 50 5 | tags: true 6 | 7 | pipeline: 8 | build: 9 | image: appleboy/codeigniter-docs 10 | pull: true 11 | commands: 12 | - locale 13 | - make pygments 14 | - make html 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # unifying the coding style for different editors and IDEs => editorconfig.org 2 | 3 | ; indicate this is the root of the project 4 | root = true 5 | 6 | ########################################################### 7 | ; common 8 | ########################################################### 9 | 10 | [*] 11 | charset = utf-8 12 | 13 | end_of_line = LF 14 | insert_final_newline = true 15 | trim_trailing_whitespace = true 16 | 17 | indent_style = space 18 | indent_size = 2 19 | 20 | ########################################################### 21 | ; make 22 | ########################################################### 23 | 24 | [Makefile] 25 | indent_style = tab 26 | 27 | [makefile] 28 | indent_style = tab 29 | 30 | ########################################################### 31 | ; markdown 32 | ########################################################### 33 | 34 | [*.md] 35 | trim_trailing_whitespace = false 36 | 37 | ########################################################### 38 | ; golang 39 | ########################################################### 40 | 41 | [*.go] 42 | indent_style = tab -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .idea/ 3 | cilexer/dist 4 | cilexer/pycilexer.egg-info 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeIgniter 台灣繁體中文文件 2 | 3 | ## 翻譯準則 4 | 5 | 繁體中文翻譯請遵守 [Chinese Copywriting Guidelines](https://github.com/sparanoid/chinese-copywriting-guidelines)。 6 | 7 | * [線上翻譯手冊 2](http://codeigniter.org.tw/user_guide/) 8 | * [線上翻譯手冊 3](http://codeigniter.org.tw/userguide3/) 9 | 10 | ## 尚未翻譯列表 11 | 12 | 一般主題 13 | 14 | * [x] PHP Style Guide 15 | 16 | 函示庫 17 | 18 | * [x] Benchmarking Class 19 | * [x] Caching Driver 20 | * [x] Calendaring Class 21 | * [x] Shopping Cart Class 22 | * [x] Config Class 23 | * [x] Email Class 24 | * [ ] Encrypt Class 25 | * [ ] Encryption Library 26 | * [ ] File Uploading Class 27 | * [ ] Form Validation 28 | * [ ] FTP Class 29 | * [ ] Image Manipulation Class 30 | * [ ] Input Class 31 | * [ ] Javascript Class 32 | * [ ] Language Class 33 | * [ ] Loader Class 34 | * [ ] Migrations Class 35 | * [ ] Output Class 36 | * [ ] Pagination Class 37 | * [ ] Template Parser Class 38 | * [ ] Security Class 39 | * [ ] Session Driver 40 | * [x] HTML Table Class 41 | * [x] Trackback Class 42 | * [x] Typography Class 43 | * [x] Unit Testing Class 44 | * [x] URI Class 45 | * [x] User Agent Class 46 | * [x] XML-RPC and XML-RPC Server Classes 47 | * [x] Zip Encoding Class 48 | 49 | 資料庫 50 | 51 | * [x] 查詢補助函式 52 | * [x] 查詢生成器類別 53 | * [ ] 交易 54 | * [ ] 取得資料表資訊 55 | * [ ] 自訂函數 56 | * [ ] 查詢快取 57 | * [ ] 使用 Database Forge 管理資料庫 58 | * [ ] Database Utilities 類別 59 | * [ ] Database Driver 參考 60 | 61 | 補助函式 62 | 63 | * [x] Array Helper 64 | * [x] CAPTCHA Helper 65 | * [x] Cookie Helper 66 | * [x] Date Helper 67 | * [ ] Directory Helper 68 | * [ ] Download Helper 69 | * [ ] Email Helper 70 | * [ ] File Helper 71 | * [ ] Form Helper 72 | * [ ] HTML Helper 73 | * [ ] Inflector Helper 74 | * [x] Language Helper 75 | * [ ] Number Helper 76 | * [ ] Path Helper 77 | * [ ] Security Helper 78 | * [ ] Smiley Helper 79 | * [ ] String Helper 80 | * [ ] Text Helper 81 | * [ ] Typography Helper 82 | * [ ] URL Helper 83 | * [ ] XML Helper 84 | 85 | 貢獻翻譯 86 | 87 | * [ ] Writing CodeIgniter Documentation 88 | * [ ] Developer’s Certificate of Origin 1.1 89 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /cilexer/cilexer/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /cilexer/cilexer/cilexer.py: -------------------------------------------------------------------------------- 1 | # CodeIgniter 2 | # https://codeigniter.com 3 | # # An open source application development framework for PHP 4 | # 5 | # This content is released under the MIT License (MIT) 6 | # 7 | # Copyright (c) 2014 - 2016, British Columbia Institute of Technology 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining a copy 10 | # of this software and associated documentation files (the "Software"), to deal 11 | # in the Software without restriction, including without limitation the rights 12 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | # copies of the Software, and to permit persons to whom the Software is 14 | # furnished to do so, subject to the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be included in 17 | # all copies or substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | # THE SOFTWARE. 26 | # 27 | # Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) 28 | # Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) 29 | # 30 | # http://opensource.org/licenses/MIT MIT License 31 | 32 | import re 33 | import copy 34 | 35 | from pygments.lexer import DelegatingLexer 36 | from pygments.lexers.web import PhpLexer, HtmlLexer 37 | 38 | __all__ = ['CodeIgniterLexer'] 39 | 40 | 41 | class CodeIgniterLexer(DelegatingLexer): 42 | """ 43 | Handles HTML, PHP, JavaScript, and CSS is highlighted 44 | PHP is highlighted with the "startline" option 45 | """ 46 | 47 | name = 'CodeIgniter' 48 | aliases = ['ci', 'codeigniter'] 49 | filenames = ['*.html', '*.css', '*.php', '*.xml', '*.static'] 50 | mimetypes = ['text/html', 'application/xhtml+xml'] 51 | 52 | def __init__(self, **options): 53 | super(CodeIgniterLexer, self).__init__(HtmlLexer, 54 | PhpLexer, 55 | startinline=True) 56 | -------------------------------------------------------------------------------- /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/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/_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/_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/_themes/sphinx_rtd_theme/breadcrumbs.html: -------------------------------------------------------------------------------- 1 |
2 | 18 |
19 |
20 | -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/footer.html: -------------------------------------------------------------------------------- 1 | 37 | 38 | 48 | -------------------------------------------------------------------------------- /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 = _('Search') %} 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 | 30 | 31 | {% if search_performed %} 32 |

搜尋結果

33 | {% if not search_results %} 34 |

您的搜尋沒有符合使用手冊當中的資料。請確定您沒有輸入錯別字,並且已經選擇了足夠的類別。

35 | {% endif %} 36 | {% endif %} 37 |
38 | {% if search_results %} 39 | 47 | {% endif %} 48 |
49 | {% endblock %} 50 | -------------------------------------------------------------------------------- /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/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/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/_themes/sphinx_rtd_theme/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/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-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/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-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/_themes/sphinx_rtd_theme/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /source/_themes/sphinx_rtd_theme/static/js/theme.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/_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/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 | 38 | -------------------------------------------------------------------------------- /source/database/call_function.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | Custom Function Calls 3 | ##################### 4 | 5 | $this->db->call_function(); 6 | ============================ 7 | 8 | This function enables you to call PHP database functions that are not 9 | natively included in CodeIgniter, in a platform independent manner. For 10 | example, let's say you want to call the mysql_get_client_info() 11 | function, which is **not** natively supported by CodeIgniter. You could 12 | do so like this:: 13 | 14 | $this->db->call_function('get_client_info'); 15 | 16 | You must supply the name of the function, **without** the mysql\_ 17 | prefix, in the first parameter. The prefix is added automatically based 18 | on which database driver is currently being used. This permits you to 19 | run the same function on different database platforms. Obviously not all 20 | function calls are identical between platforms, so there are limits to 21 | how useful this function can be in terms of portability. 22 | 23 | Any parameters needed by the function you are calling will be added to 24 | the second parameter. 25 | 26 | :: 27 | 28 | $this->db->call_function('some_function', $param1, $param2, etc..); 29 | 30 | Often, you will either need to supply a database connection ID or a 31 | database result ID. The connection ID can be accessed using:: 32 | 33 | $this->db->conn_id; 34 | 35 | The result ID can be accessed from within your result object, like this:: 36 | 37 | $query = $this->db->query("SOME QUERY"); 38 | 39 | $query->result_id; 40 | -------------------------------------------------------------------------------- /source/database/connecting.rst: -------------------------------------------------------------------------------- 1 | ############## 2 | 連接您的資料庫 3 | ############## 4 | 5 | 有兩種方法可以連接資料庫: 6 | 7 | 自動連接 8 | ======== 9 | 10 | "自動連接"就是在每個頁面都載入讀取資料庫類別。 11 | 要啟用自動連接,請修改底下檔案,增加 database 字串到 library 陣列裡面: 12 | 13 | application/config/autoload.php 14 | 15 | 手動連接 16 | ======== 17 | 18 | 假如只有部份網頁需要用到資料庫連接,您可以增加底下這段程式碼到需要的函式裡面,或者是可以在建構子宣告給該類別全部函式使用。 19 | 20 | :: 21 | 22 | $this->load->database(); 23 | 24 | 假如上述函式第一個參數 **不包含** 任何資訊,它將會在系統指定的資料庫設定檔中尋找。 25 | 對於大多數人來說,這是第一首選方法。 26 | 27 | 可用參數 28 | -------- 29 | 30 | #. 資料庫連接設定值,用陣列或者是 DSN 字串表示。 31 | #. TRUE/FALSE (boolean). 是否回傳連線 ID 值(請繼續閱讀底下多重資料庫連接方式)。 32 | #. TRUE/FALSE (boolean). 是否啟用查詢生成器類別. 預設值為 TRUE。 33 | 34 | 手動連接到一個資料庫 35 | -------------------- 36 | 37 | 第一個參數是可以 **選擇性** 的設定,可以從您的設定檔裡面指定要連接的名稱,或者是您可以自行定義資料庫參數,此設定參數並非在您的設定檔裡面。範例: 38 | 39 | 從設定檔裡面選擇指定的資料庫,您可以使用下面方式 40 | 41 | :: 42 | 43 | $this->load->database('group_name'); 44 | 45 | group_name 指的是您的設定檔裡面所存在的連接資料庫名稱。 46 | 47 | 要手動連接到需要的資料庫,可以指定底下的參數陣列 48 | 49 | :: 50 | 51 | $config['hostname'] = 'localhost'; 52 | $config['username'] = 'myusername'; 53 | $config['password'] = 'mypassword'; 54 | $config['database'] = 'mydatabase'; 55 | $config['dbdriver'] = 'mysqli'; 56 | $config['dbprefix'] = ''; 57 | $config['pconnect'] = FALSE; 58 | $config['db_debug'] = TRUE; 59 | $config['cache_on'] = FALSE; 60 | $config['cachedir'] = ''; 61 | $config['char_set'] = 'utf8'; 62 | $config['dbcollat'] = 'utf8_general_ci'; 63 | $this->load->database($config); 64 | 65 | 想要瞭解每個參數的屬性,可以參考 :doc:`資料庫設定頁面 `。 66 | 67 | .. 注意:: 當使用 PDO 模式, 你必須使用 $config['dsn'] 設定來取代 "hostname" 和 "database": 68 | | 69 | | $config['dsn'] = 'mysql:host=localhost;dbname=mydatabase'; 70 | 71 | 或者是您可以用 Data Source Name 來連接資料庫。 DSNs 設定方式必需如下: 72 | 73 | :: 74 | 75 | $dsn = 'dbdriver://username:password@hostname/database'; 76 | $this->load->database($dsn); 77 | 78 | 當使用 DSN 字串來連接資料庫時,為了覆蓋系統預設值,可以用查詢字串的方式來增加設定值。 79 | 80 | :: 81 | 82 | $dsn = 'dbdriver://username:password@hostname/database?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=/path/to/cache'; 83 | $this->load->database($dsn); 84 | 85 | 連接多重資料庫 86 | ============== 87 | 88 | 假如想要同時使用多個資料庫,您可以使用底下方式: 89 | 90 | :: 91 | 92 | $DB1 = $this->load->database('group_one', TRUE); 93 | $DB2 = $this->load->database('group_two', TRUE); 94 | 95 | 注意: 更改上面字串 "group_one" 和 "group_two" 為您所要指定的連接資料庫名稱(或者是您也可以使用如上所述的參數連接值)。 96 | 97 | 藉由設定第二個參數為 TRUE (boolean) ,此函式將會回傳資料庫物件。 98 | 99 | .. 注意:: 當您使用此方法,您將會使用物件名稱來取代本手冊中介紹的方法。 100 | 換句話說,不是使用下面方式: 101 | 102 | | 103 | | $this->db->query(); 104 | | $this->db->result(); 105 | | etc... 106 | | 107 | | You will instead use: 108 | | 109 | | $DB1->query(); 110 | | $DB1->result(); 111 | | etc... 112 | 113 | .. 注意:: 你不需要建立一個特別的資料庫設定,如果你只是要在一個連線當中使用不同的資料庫。 114 | 當你需要切換到不同的資料庫,你可以這樣做: 115 | 116 | | $this->db->db_select($database2_name); 117 | 118 | 重新連結 / 保持存活的連線 119 | ========================= 120 | 121 | 如果資料庫伺服器的閒置逾時超過了一些你執行複雜的 php 運算(例如 圖像處理),你應該考慮在進行查詢之前先使用 reconnect() 來偵測伺服器狀態。 122 | 他可以持續使用存活的連線或是重新建立他。 123 | 124 | :: 125 | 126 | $this->db->reconnect(); 127 | 128 | 手動關閉連線 129 | ============ 130 | 131 | 當 CodeIgniter 會自動的進行資料庫連線的關閉,你也可以強制關閉連線。 132 | 133 | :: 134 | 135 | $this->db->close(); 136 | -------------------------------------------------------------------------------- /source/database/examples.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | 資料庫 快速入門:範例程式 3 | ######################### 4 | 5 | 以下的頁面包含了示範如何使用資料庫類別的範例程式。請閱讀各個函數的說明頁面來了解完整的細節。 6 | 7 | 起始化資料庫類別 8 | ================ 9 | 10 | 以下的程式根據你 :doc:`設定檔 ` 中的設定載入並初始化資料類別: 11 | 12 | :: 13 | 14 | $this->load->database(); 15 | 16 | 類別一旦載入,就可以像下面說明這樣使用: 17 | 18 | 注意:如果你的所有的頁面都需要存取資料,你可以設定自動連線資料庫,參閱 :doc:`連線資料庫 ` 來了解細節。 19 | 20 | 標準的多結果查詢(物件版) 21 | ========================== 22 | 23 | :: 24 | 25 | $query = $this->db->query('SELECT name, title, email FROM my_table'); 26 | 27 | foreach ($query->result() as $row) 28 | { 29 | echo $row->title; 30 | echo $row->name; 31 | echo $row->email; 32 | } 33 | 34 | echo 'Total Results: ' . $query->num_rows(); 35 | 36 | 以上的 result() 函數返回一個 **物件** 陣列。範例:$row->title 。 37 | 38 | 標準的多結果查詢(陣列版) 39 | ========================== 40 | 41 | :: 42 | 43 | $query = $this->db->query('SELECT name, title, email FROM my_table'); 44 | 45 | foreach ($query->result_array() as $row) 46 | { 47 | echo $row['title']; 48 | echo $row['name']; 49 | echo $row['email']; 50 | } 51 | 52 | 以上 result_array() 函數返回一個標準的索引陣列。範例:$row['title'] 。 53 | 54 | 標準的單一結果查詢(物件版) 55 | ============================ 56 | 57 | :: 58 | 59 | $query = $this->db->query('SELECT name FROM my_table LIMIT 1'); 60 | $row = $query->row(); 61 | echo $row->name; 62 | 63 | 上例中 row() 函數返回一個 **物件**。範例:$row->name 。 64 | 65 | 標準的單一結果查詢(陣列版) 66 | ============================ 67 | 68 | :: 69 | 70 | $query = $this->db->query('SELECT name FROM my_table LIMIT 1'); 71 | $row = $query->row_array(); 72 | echo $row['name']; 73 | 74 | 上例中 row_array() 函數傳回一個 **陣列** 。範例:$row['name'] 。 75 | 76 | 標準新增 77 | ======== 78 | 79 | :: 80 | 81 | $sql = "INSERT INTO mytable (title, name) VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")"; 82 | $this->db->query($sql); 83 | echo $this->db->affected_rows(); 84 | 85 | 查詢生成器 查詢 86 | =============== 87 | 88 | :doc:`查詢生成器 ` 給你一個取得資料的簡單方法: 89 | 90 | :: 91 | 92 | $query = $this->db->get('table_name'); 93 | 94 | foreach ($query->result() as $row) 95 | { 96 | echo $row->title; 97 | } 98 | 99 | 上例中 get() 函數傳回指定的資料表中所有的結果。 :doc:`查詢生成器 ` 類別包含完整的資料操作方法。 100 | 101 | 查詢生成器 新增 102 | =============== 103 | 104 | :: 105 | 106 | $data = array( 107 | 'title' => $title, 108 | 'name' => $name, 109 | 'date' => $date 110 | ); 111 | 112 | $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}') 113 | 114 | -------------------------------------------------------------------------------- /source/database/helpers.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | 查詢補助函式 3 | ############ 4 | 5 | 獲取查詢執行的資訊 6 | ================== 7 | 8 | **$this->db->insert_id()** 9 | 10 | 進行資料庫插入時的插入ID數字。 11 | 12 | .. note:: 如果使用了 PDO 驅動連接 PostgreSQL 或是使用 InterBase 驅動程式,這個函式會需要一個 $name 參數,用來指定適當的序列來檢查插入的 id 。 13 | 14 | **$this->db->affected_rows()** 15 | 16 | 顯示會執行 "寫入" 類型的查詢所影響的列數( insert, update 等)。 17 | 18 | .. note:: 在 MySQL , "DELETE FROM TABLE" 回傳受影響的列數會是 0 。資料庫類別做了一點小 hack ,讓他可以傳回正確的數字。預設這個 hack 是開啟的,不過也可以從資料庫驅動程式檔案中將它關閉。 19 | 20 | **$this->db->last_query()** 21 | 22 | 回傳最近一次執行的查詢(查詢字串,不是查詢結果)。 23 | 例如: 24 | 25 | :: 26 | 27 | $str = $this->db->last_query(); 28 | 29 | // 產生: SELECT * FROM sometable.... 30 | 31 | 32 | .. note:: 在資料庫設定中取消 **save_queries** 設定,會使這個函式失效 33 | 34 | 取得資料庫的資訊 35 | ================ 36 | 37 | **$this->db->count_all()** 38 | 39 | 讓你可以確知一個資料表中資料的列數。使用資料表名稱作為第一個參數。例如: 40 | 41 | :: 42 | 43 | echo $this->db->count_all('my_table'); 44 | 45 | // 產生一個整數,像是 25 46 | 47 | **$this->db->platform()** 48 | 49 | 輸出目前在運行的資料庫平台( MySQL, MS SQL, Postgres 等): 50 | 51 | :: 52 | 53 | echo $this->db->platform(); 54 | 55 | **$this->db->version()** 56 | 57 | 輸出目前在運行的資料庫版本: 58 | 59 | :: 60 | 61 | echo $this->db->version(); 62 | 63 | 讓查詢更容易 64 | ============ 65 | 66 | **$this->db->insert_string()** 67 | 68 | 這個函式簡化了插入資料到資料庫的過程。它會回傳一個正確格式的 SQL 插入字串。例如: 69 | 70 | :: 71 | 72 | $data = array('name' => $name, 'email' => $email, 'url' => $url); 73 | 74 | $str = $this->db->insert_string('table_name', $data); 75 | 76 | 第一個參數是資料表名稱,第二個參數是要插入資料的關聯陣列。上面的例子會產生: 77 | 78 | :: 79 | 80 | INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com') 81 | 82 | .. note:: 值會被自動跳脫,以產生較安全的查詢。 83 | 84 | **$this->db->update_string()** 85 | 86 | 這個函式簡化了撰寫資料庫更新的過程。它會回傳一個正確格式的 SQL 更新字串。例如: 87 | 88 | :: 89 | 90 | $data = array('name' => $name, 'email' => $email, 'url' => $url); 91 | 92 | $where = "author_id = 1 AND status = 'active'"; 93 | 94 | $str = $this->db->update_string('table_name', $data, $where); 95 | 96 | 第一個參數是資料表名稱,第二個參數是要更新資料的關連陣列,第三個則是 "where" 子句。上面的例子會產生: 97 | 98 | :: 99 | 100 | UPDATE table_name SET name = 'Rick', email = 'rick@example.com', url = 'example.com' WHERE author_id = 1 AND status = 'active' 101 | 102 | .. note:: 值會被自動跳脫,以產生較安全的查詢。 103 | -------------------------------------------------------------------------------- /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 | Database Utilities 類別 24 | Database Driver 參考 25 | -------------------------------------------------------------------------------- /source/database/metadata.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | Database Metadata 3 | ################# 4 | 5 | ************** 6 | Table MetaData 7 | ************** 8 | 9 | These functions let you fetch table information. 10 | 11 | List the Tables in Your Database 12 | ================================ 13 | 14 | **$this->db->list_tables();** 15 | 16 | Returns an array containing the names of all the tables in the database 17 | you are currently connected to. Example:: 18 | 19 | $tables = $this->db->list_tables(); 20 | 21 | foreach ($tables as $table) 22 | { 23 | echo $table; 24 | } 25 | 26 | 27 | Determine If a Table Exists 28 | =========================== 29 | 30 | **$this->db->table_exists();** 31 | 32 | Sometimes it's helpful to know whether a particular table exists before 33 | running an operation on it. Returns a boolean TRUE/FALSE. Usage example:: 34 | 35 | if ($this->db->table_exists('table_name')) 36 | { 37 | // some code... 38 | } 39 | 40 | .. note:: Replace *table_name* with the name of the table you are looking for. 41 | 42 | 43 | ************** 44 | Field MetaData 45 | ************** 46 | 47 | List the Fields in a Table 48 | ========================== 49 | 50 | **$this->db->list_fields()** 51 | 52 | Returns an array containing the field names. This query can be called 53 | two ways: 54 | 55 | 1. You can supply the table name and call it from the $this->db-> 56 | object:: 57 | 58 | $fields = $this->db->list_fields('table_name'); 59 | 60 | foreach ($fields as $field) 61 | { 62 | echo $field; 63 | } 64 | 65 | 2. You can gather the field names associated with any query you run by 66 | calling the function from your query result object:: 67 | 68 | $query = $this->db->query('SELECT * FROM some_table'); 69 | 70 | foreach ($query->list_fields() as $field) 71 | { 72 | echo $field; 73 | } 74 | 75 | 76 | Determine If a Field is Present in a Table 77 | ========================================== 78 | 79 | **$this->db->field_exists()** 80 | 81 | Sometimes it's helpful to know whether a particular field exists before 82 | performing an action. Returns a boolean TRUE/FALSE. Usage example:: 83 | 84 | if ($this->db->field_exists('field_name', 'table_name')) 85 | { 86 | // some code... 87 | } 88 | 89 | .. note:: Replace *field_name* with the name of the column you are looking 90 | for, and replace *table_name* with the name of the table you are 91 | looking for. 92 | 93 | 94 | Retrieve Field Metadata 95 | ======================= 96 | 97 | **$this->db->field_data()** 98 | 99 | Returns an array of objects containing field information. 100 | 101 | Sometimes it's helpful to gather the field names or other metadata, like 102 | the column type, max length, etc. 103 | 104 | .. note:: Not all databases provide meta-data. 105 | 106 | Usage example:: 107 | 108 | $fields = $this->db->field_data('table_name'); 109 | 110 | foreach ($fields as $field) 111 | { 112 | echo $field->name; 113 | echo $field->type; 114 | echo $field->max_length; 115 | echo $field->primary_key; 116 | } 117 | 118 | If you have run a query already you can use the result object instead of 119 | supplying the table name:: 120 | 121 | $query = $this->db->query("YOUR QUERY"); 122 | $fields = $query->field_data(); 123 | 124 | The following data is available from this function if supported by your 125 | database: 126 | 127 | - name - column name 128 | - max_length - maximum length of the column 129 | - primary_key - 1 if the column is a primary key 130 | - type - the type of the column 131 | -------------------------------------------------------------------------------- /source/database/queries.rst: -------------------------------------------------------------------------------- 1 | ######## 2 | 執行查詢 3 | ######## 4 | 5 | ******** 6 | 查詢基礎 7 | ******** 8 | 9 | 常規的查詢 10 | ========== 11 | 12 | 可以使用下 **query** 來提交查詢: 13 | 14 | :: 15 | 16 | $this->db->query('YOUR QUERY HERE'); 17 | 18 | 當使用 "讀取" 模式來進行查詢,query() 函數以 **object** 型態回傳資料庫的 :doc:`產生查詢結果 ` 。 19 | 當使用 "寫入" 模式來進行查詢,會依據執行成功或失敗來回傳 TRUE 或 FALSE。 20 | 當檢索資料的時候,通常使用一個變數接收查詢的結果,例如: 21 | 22 | :: 23 | 24 | $query = $this->db->query('YOUR QUERY HERE'); 25 | 26 | 簡單化的查詢 27 | ============ 28 | 29 | **simple_query** 方法是 $this->db->query() 的簡化版。 30 | 他 **不會** 回傳資料庫結果集合,不會設定查詢計時器,或者編譯數據,或是儲存您的查詢以便除錯。 31 | 簡單的說,它只是讓你提交查詢。大多數用戶很少會使用此功能。 32 | 33 | 他回傳 database drivers 中 "執行" 函數的回傳結果。 34 | 通常是 TRUE 或 FALSE 依據寫入查詢(INSERT, DELETE or UPDATE(合適的實際應用時機))的成功或失敗。 35 | 並將成功的查詢轉為可以使用的資源/物件。 36 | 37 | :: 38 | 39 | if ($this->db->simple_query('YOUR QUERY')) 40 | { 41 | echo "Success!"; 42 | } 43 | else 44 | { 45 | echo "Query failed!"; 46 | } 47 | 48 | .. 注意:: PostgreSQL's ``pg_exec()`` 函數(舉例)總是再成功的查詢返回資源,即使是寫入的查詢。 49 | 將這件事情緊記在心,當你在找尋 boolean 值的時候。 50 | 51 | ****************** 52 | 手動設定資料庫前綴 53 | ****************** 54 | 55 | 如果你有設定資料庫前綴,且希望將他加入到資料表名稱,例如當你使用原生 SQL ,可使用以下的語法: 56 | 57 | :: 58 | 59 | $this->db->dbprefix('tablename'); // outputs prefix_tablename 60 | 61 | 如果因為某些原因你需要修改前綴,並不需要建立一個新的連結,可使用以下方法: 62 | 63 | :: 64 | 65 | $this->db->set_dbprefix('newprefix'); 66 | $this->db->dbprefix('tablename'); // outputs newprefix_tablename 67 | 68 | 69 | ************ 70 | 保護標識符號 71 | ************ 72 | 73 | 在眾多資料庫中最好對資料表跟欄位名稱使用保護 - 例如 MySQL 使用反引號 backticks (``)。 74 | **查詢生成器會自動的提供保護**,如果你需要手動保護這些標識符號可以使用: 75 | 76 | :: 77 | 78 | $this->db->protect_identifiers('table_name'); 79 | 80 | .. 重要:: 雖然查詢生成器會嘗試提供對任何你提供的欄位與資料表名稱提供最好的保護,注意他 **不是** 設計對任何用戶的輸入提供保護的。 81 | 請 **不要** 提供任何未經檢查過濾的使用者輸入資料。 82 | 83 | 根據資料庫設定檔裡面的前綴設定,此函數會在資料表前面加上前綴。 84 | 您可以透過設定第二個參數為 TRUE (boolen) 來啟動前綴設定: 85 | 86 | :: 87 | 88 | $this->db->protect_identifiers('table_name', TRUE); 89 | 90 | 91 | ******** 92 | 跳脫查詢 93 | ******** 94 | 95 | 這是一個非常良好安全習慣在你提交資料到資料庫之前進行資料跳脫。 96 | CodeIgniter 提供三個方法可以幫助您做到這一點: 97 | 98 | #. **$this->db->escape()** 此函數根據資料型態來運作,所以他只會對字串型態的資料進行跳脫。 99 | 它會自動增加單引號在資料的兩側,所以你不必加上單引號: 100 | :: 101 | 102 | $sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")"; 103 | 104 | #. **$this->db->escape_str()** 此函數可以跳脫任何資料型態。 105 | 在大多數的情況底下,你使用上述的函數多於使用此函數。此函數用法如下: 106 | :: 107 | 108 | $sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; 109 | 110 | #. **$this->db->escape_like_str()** 此函數可以用在字串將使用於 SQL Like 語法當中,像是萬用字元('%', '_')在此函數中也會被跳脫。 111 | :: 112 | 113 | $search = '20% raise'; 114 | $sql = "SELECT id FROM table WHERE column LIKE '%".$this->db->escape_like_str($search)."%'"; 115 | 116 | 117 | ******** 118 | 封裝查詢 119 | ******** 120 | 121 | 封裝可以簡化你的查詢語法,讓系統幫忙為您的查詢放入資料. 請參照底下範例: 122 | 123 | :: 124 | 125 | $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; 126 | $this->db->query($sql, array(3, 'live', 'Rick')); 127 | 128 | 這些問號會自動改為查詢函數的第二個參數陣列資料值。 129 | 130 | 封裝也支援陣列參數,他將轉換成 IN 使用的集合: 131 | :: 132 | 133 | $sql = "SELECT * FROM some_table WHERE id IN ? AND status = ? AND author = ?"; 134 | $this->db->query($sql, array(array(3, 6), 'live', 'Rick')); 135 | 136 | 轉換後的查詢結果如下: 137 | :: 138 | 139 | SELECT * FROM some_table WHERE id IN (3,6) AND status = 'live' AND author = 'Rick' 140 | 141 | 使用封裝的第二個好處是系統會自動幫忙跳脫字串,形成較安全的查詢語法。 142 | 您就不需要手動的處理這些資料;系統將會自動的幫忙處理。 143 | 144 | ******** 145 | 錯誤處理 146 | ******** 147 | 148 | **$this->db->error();** 149 | 150 | 當你需要取得最後一次發生的錯誤,error() 方法將會用一個陣列回傳錯誤的編號與訊息。一個簡單的範例: 151 | :: 152 | 153 | if ( ! $this->db->simple_query('SELECT `example_field` FROM `example_table`')) 154 | { 155 | $error = $this->db->error(); // Has keys 'code' and 'message' 156 | } 157 | 158 | -------------------------------------------------------------------------------- /source/database/transactions.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | Transactions 3 | ############ 4 | 5 | CodeIgniter's database abstraction allows you to use transactions with 6 | databases that support transaction-safe table types. In MySQL, you'll 7 | need to be running InnoDB or BDB table types rather than the more common 8 | MyISAM. Most other database platforms support transactions natively. 9 | 10 | If you are not familiar with transactions we recommend you find a good 11 | online resource to learn about them for your particular database. The 12 | information below assumes you have a basic understanding of 13 | transactions. 14 | 15 | CodeIgniter's Approach to Transactions 16 | ====================================== 17 | 18 | CodeIgniter utilizes an approach to transactions that is very similar to 19 | the process used by the popular database class ADODB. We've chosen that 20 | approach because it greatly simplifies the process of running 21 | transactions. In most cases all that is required are two lines of code. 22 | 23 | Traditionally, transactions have required a fair amount of work to 24 | implement since they demand that you keep track of your queries and 25 | determine whether to commit or rollback based on the success or failure 26 | of your queries. This is particularly cumbersome with nested queries. In 27 | contrast, we've implemented a smart transaction system that does all 28 | this for you automatically (you can also manage your transactions 29 | manually if you choose to, but there's really no benefit). 30 | 31 | Running Transactions 32 | ==================== 33 | 34 | To run your queries using transactions you will use the 35 | $this->db->trans_start() and $this->db->trans_complete() functions as 36 | follows:: 37 | 38 | $this->db->trans_start(); 39 | $this->db->query('AN SQL QUERY...'); 40 | $this->db->query('ANOTHER QUERY...'); 41 | $this->db->query('AND YET ANOTHER QUERY...'); 42 | $this->db->trans_complete(); 43 | 44 | You can run as many queries as you want between the start/complete 45 | functions and they will all be committed or rolled back based on success 46 | or failure of any given query. 47 | 48 | Strict Mode 49 | =========== 50 | 51 | By default CodeIgniter runs all transactions in Strict Mode. When strict 52 | mode is enabled, if you are running multiple groups of transactions, if 53 | one group fails all groups will be rolled back. If strict mode is 54 | disabled, each group is treated independently, meaning a failure of one 55 | group will not affect any others. 56 | 57 | Strict Mode can be disabled as follows:: 58 | 59 | $this->db->trans_strict(FALSE); 60 | 61 | Managing Errors 62 | =============== 63 | 64 | If you have error reporting enabled in your config/database.php file 65 | you'll see a standard error message if the commit was unsuccessful. If 66 | debugging is turned off, you can manage your own errors like this:: 67 | 68 | $this->db->trans_start(); 69 | $this->db->query('AN SQL QUERY...'); 70 | $this->db->query('ANOTHER QUERY...'); 71 | $this->db->trans_complete(); 72 | 73 | if ($this->db->trans_status() === FALSE) 74 | { 75 | // generate an error... or use the log_message() function to log your error 76 | } 77 | 78 | Disabling Transactions 79 | ====================== 80 | 81 | If you would like to disable transactions you can do so using 82 | ``$this->db->trans_off()``:: 83 | 84 | $this->db->trans_off(); 85 | 86 | $this->db->trans_start(); 87 | $this->db->query('AN SQL QUERY...'); 88 | $this->db->trans_complete(); 89 | 90 | When transactions are disabled, your queries will be auto-committed, just as 91 | they are when running queries without transactions, practically ignoring 92 | any calls to ``trans_start()``, ``trans_complete()``, etc. 93 | 94 | Test Mode 95 | ========= 96 | 97 | You can optionally put the transaction system into "test mode", which 98 | will cause your queries to be rolled back -- even if the queries produce 99 | a valid result. To use test mode simply set the first parameter in the 100 | $this->db->trans_start() function to TRUE:: 101 | 102 | $this->db->trans_start(TRUE); // Query will be rolled back 103 | $this->db->query('AN SQL QUERY...'); 104 | $this->db->trans_complete(); 105 | 106 | Running Transactions Manually 107 | ============================= 108 | 109 | If you would like to run transactions manually you can do so as follows:: 110 | 111 | $this->db->trans_begin(); 112 | 113 | $this->db->query('AN SQL QUERY...'); 114 | $this->db->query('ANOTHER QUERY...'); 115 | $this->db->query('AND YET ANOTHER QUERY...'); 116 | 117 | if ($this->db->trans_status() === FALSE) 118 | { 119 | $this->db->trans_rollback(); 120 | } 121 | else 122 | { 123 | $this->db->trans_commit(); 124 | } 125 | 126 | .. note:: Make sure to use $this->db->trans_begin() when running manual 127 | transactions, **NOT** $this->db->trans_start(). 128 | -------------------------------------------------------------------------------- /source/documentation/ELDocs.tmbundle.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/documentation/ELDocs.tmbundle.zip -------------------------------------------------------------------------------- /source/general/alternative_php.rst: -------------------------------------------------------------------------------- 1 | ################################### 2 | 替代 View 檔案的 PHP 的語法 3 | ################################### 4 | 5 | 如果你不使用 CodeIgniter 的 :doc:`樣板引擎(template engine) <../libraries/parser>` ,就得在 View files 用純 PHP 句法 。為了最少化 PHP 程式碼在這檔案中的比重,以及要讓 View files 可以比較簡單的辨識出程式碼區塊,我們會建議你使用變換 PHP 句法的功能 ,這樣就可以利用較簡易的控制結構以及 short tag 語法。如果你不熟悉這些句法,你也可以選擇不要使用。 6 | 7 | 自動支援 Short Tag 8 | =========================== 9 | 10 | .. note:: 如果你發現在這章節中的句法,無法在你的伺服器運作的話,這有可能是在你的 PHP ini 檔案裡頭,其中的 short tags 功能被關閉了。就算你的伺服器不支援這個功能,你還是能夠依照需求修改 config/config.php,讓 CodeIgniter 可以啟用語法支援。 11 | 12 | 請留意如果你啟用了這個功能的話,假設你的 View files 發生 PHP 錯誤的話,錯誤訊息 以及實際的行號則不會確實顯示出來。所有的錯誤則會被當成是 ``eval()`` 錯誤。 13 | 14 | 替代 Echos 15 | ================= 16 | 17 | 一般使用 echo 或是印出變數的作法: :: 18 | 19 | 20 | 21 | 使用變換句法後,你就可以換成這個表達方式: :: 22 | 23 | 24 | 25 | 替代控制結構 26 | ============================== 27 | 28 | 控制結構,像是 if,for,foreach,以及 while 也可被寫程簡單的格式。這裡有個範例使用 ``foreach`` 的控制結構: :: 29 | 30 |
    31 | 32 | 33 | 34 |
  • 35 | 36 | 37 | 38 |
39 | 40 | 請注意這邊沒有結束括號,而是以 ``endforeach`` 來取代。下列的所有控制結構有相同的結束句法(closing syntax): ``endif`` , ``endfor`` , ``endforeach`` ,以及 ``endwhile`` 41 | 42 | 也請注意到,在每個結構之後(除了最後一個)不使用的分號(;),而是冒號(:)。這很容易搞錯,這個非常重要! 43 | 44 | 這邊還有其它範例,使用 ``if``/``elseif``/``else``,請留意冒號: :: 45 | 46 | 47 | 48 |

Hi Sally

49 | 50 | 51 | 52 |

Hi Joe

53 | 54 | 55 | 56 |

Hi unknown user

57 | 58 | 59 | -------------------------------------------------------------------------------- /source/general/ancillary_classes.rst: -------------------------------------------------------------------------------- 1 | ########################## 2 | 新增配套類別 3 | ########################## 4 | 5 | 在某些情況下,你可能需要開發一個類別,這個類別能使用 Codeigniter 一部分在控制器(Controller)已經現有的功能。 6 | 這是很簡單做到的,請看下面。 7 | 8 | get_instance() 9 | ============== 10 | 11 | .. function:: get_instance() 12 | 13 | :returns: object of class CI_Controller 14 | 15 | **所有在你的控制器(Controller)方法裡已經實例化的類別即可存取 Codeigniter 本地的資源** 簡單地通過使用 ``get_instance()`` 函數。這個函數回傳 Codeigniter 主物件。 16 | 17 | 一般來說,要呼叫 Codeigniter 的方法,你會使用 ``$this``: :: 18 | 19 | $this->load->helper('url'); 20 | $this->load->library('session'); 21 | $this->config->item('base_url'); 22 | // etc. 23 | 24 | ``$this`` ,只能在你的 Controllers、Models、Views 裡面執行,如果你想要在你的類別裡面使用 Codeigniter 類別,你可以參考下面作法: : 25 | 26 | 第一步,賦值給 CodeIgniter 物件到一個變數裡: :: 27 | 28 | $CI =& get_instance(); 29 | 30 | 一旦你已經賦值一個物件到變數上,你將會使用這個變數 *取代* 掉 ``$this`` : :: 31 | 32 | $CI =& get_instance(); 33 | 34 | $CI->load->helper('url'); 35 | $CI->load->library('session'); 36 | $CI->config->item('base_url'); 37 | // etc. 38 | 39 | .. note:: 在上面這個例子,你會注意到 get_instance() ``函數`` 是傳入參考: :: 40 | 41 | $CI =& get_instance(); 42 | 43 | 這是非常重要的。賦予參考值允許你使用最原始 CodeIgniter 物件,而不是建立一個副本。 44 | 45 | 此外,如果你會使用 ``get_instance()`` 到其它類別上,賦予參考到變數上,是較好的行為。 46 | 這個方法你將不需要在每個方法裡面呼叫一次 ``get_instance()`` 。 47 | 48 | 例如: :: 49 | 50 | class Example { 51 | 52 | protected $CI; 53 | 54 | // We'll use a constructor, as you can't directly call a function 55 | // from a property definition. 56 | public function __construct() 57 | { 58 | // Assign the CodeIgniter super-object 59 | $this->CI =& get_instance(); 60 | } 61 | 62 | public function foo() 63 | { 64 | $this->CI->load->helper('url'); 65 | redirect(); 66 | } 67 | 68 | public function bar() 69 | { 70 | $this->CI->config->item('base_url'); 71 | } 72 | 73 | } 74 | 75 | 在上面的例子,在你實例化 Example 類別的時候,方法 ``foo()`` 以及 ``bar()`` 即可使用,不需要在其它地方再去呼叫 ``get_instance()`` 函數。 76 | -------------------------------------------------------------------------------- /source/general/autoloader.rst: -------------------------------------------------------------------------------- 1 | ###################### 2 | 自動載入資源 3 | ###################### 4 | 5 | CodeIgniter 具有”自動載入(auto-load)“的功能,可允許程式庫、輔助函式、Model 模組在每次系統啟動時自動載入。如果你需要某個資源可在 application 被全域(globally)使用的話,你應該考慮使用自動載入的功能。 6 | 7 | 8 | 底下的項目可以被自動載入: 9 | 10 | - 位在 *libraries/* 目錄下的核心類別檔(core classes) 11 | - 位在 *helpers/* 目錄下的補助函式檔(helpers) 12 | - 位在 *config/* 目錄下的自訂設定檔(config) 13 | - 位在 *system/language/* 目錄下的語言檔(language) 14 | - 位在 *models/* 目錄下的資料庫檔(models) 15 | 16 | 要自動載入資源,請開啟 **application/config/autoload.php** 的檔案,然後將要自動載入的項目置於 autoload array 裡頭。你可以位不同的載入項目,找到相關的的說明。 17 | 18 | .. note:: 當新增載入項目至 autoload array 時,不需要包含檔案的副檔名(.php)。 19 | 20 | 此外,如果你想要在 CodeIgniter 中使用 `Composer `_ 21 | 自動載入器,只要設定 ``$config['composer_autoload']`` 成 ``TRUE`` 或者 22 | 設定客製化路徑 **application/config/config.php** 設定檔。 23 | -------------------------------------------------------------------------------- /source/general/caching.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 網頁快取 3 | ################ 4 | 5 | CodeIgniter 讓你快取自己的網頁,為了要達到最大效能。 6 | 7 | 雖然 CodeIgniter 相當快,呈現在網頁中的動態資訊取決於於伺服器所擁有的資源、記憶體、處理器的使用率、都會影響到你的網頁處理速度。藉由快取(Caching)你的網頁的方式,只需快取下來就可以發揮功用,可說是達到近乎是靜態網頁的效能。 8 | 9 | 快取是如何運作的呢? 10 | ====================== 11 | 12 | 快取可以把單頁為最小單位,你可以設定頁面的保留時間、何時該被重新更新(Refresh)。當頁面首次載入時,快取檔案則會寫 applocation/cache 目錄之中。下個頁面則由快取檔案取出,接者把這個頁面傳送給對伺服器送出請求(Request)的瀏覽器。假如請求的檔案已經過期(Expired),那麼舊的快取頁面則會被刪除,然後伺服器更新快取後,才會把頁面傳送給瀏覽器。 13 | 14 | .. note: Benchmark 標籤並沒有被快取下來,所以當快取功能啟動的時候,你還是可以看到頁面載入的速度。 15 | 16 | 啟動快取 17 | ================ 18 | 19 | 啟動快取功能的方式,把下列的語句放到你的控制器(Controller)裡的任何方法(function)位置: :: 20 | 21 | $this->output->cache($n); 22 | 23 | ``n`` 代表的是你的頁面預期要保留到更新(remain cached between refreshes)的 **分鐘(minutes)** 。 24 | 25 | 上面的快取語句可以隨意放在(Controller)的方法(function)裡頭,不會影響到呈現的順序,所以放在你覺得最合理的地方即可。 26 | 27 | .. important:: CodeIgniter 採用的是輸出後,才會儲存內容的設計方式,也就是快取(Caching)只會在你的控制器(Controller)要求 :doc:`View <./views>` 的時候,它才會被建立出來。 28 | 29 | .. important:: If you change configuration options that might affect 30 | your output, you have to manually delete your cache files. 31 | 32 | .. note:: 為了讓快取檔案可以被寫入到 *application/cache* 目錄,請務必將該目錄開啟為可以被寫入的權限。 33 | 34 | 刪除快取 35 | =============== 36 | 37 | 如果不再需要某些快取檔案,你可以移除快取語句,這樣在快取檔過期之後就不會再被更新了。 38 | 39 | .. note:: 移除語句之後,快取不會被直接移除,還是會被保留下來到原先設定的時間到逾期為止。 40 | 41 | 如果要提前刪除快取資料,你可以使用 ``delete_cache()`` 函數: :: 42 | 43 | // 對現在請求的 URI 刪除快取 44 | $this->output->delete_cache(); 45 | 46 | // 刪除快取 /foo/bar 47 | $this->output->delete_cache('/foo/bar'); 48 | -------------------------------------------------------------------------------- /source/general/cli.rst: -------------------------------------------------------------------------------- 1 | ################### 2 | 透過 CLI 執行 CodeIgniter 3 | ################### 4 | 5 | 就如同透過瀏覽器呼叫 applications :doc:`控制器(Controllers) <./controllers>` 6 | 一樣,我們也可以透過 command-line interface(CLI)呼叫程式。 7 | 8 | .. contents:: Page Contents 9 | 10 | CLI 是什麼? 11 | ================ 12 | 13 | Command-line interface 是透過文字介面跟操作者溝通 更多詳細資訊,請參考 `Wikipedia 文章 `_ 。 14 | 15 | 為什麼透過 CLI 執行? 16 | ============================= 17 | 18 | 這裡有許多原因透過 command-line 去執行 CodeIgniter,但是它們總是被忽略。 19 | 20 | - 透過 CLI 去執行您的 cron-jobs 而不需要使用 *wget* 或 *curl* 。 21 | - 藉由檢查 :func:`is_cli()` 函數返回值,讓你的 cron-jobs 不可存取被載入的 URL 。 22 | - 互動式“tasks”工作,像是動態改變權限、清除 cache 目錄、執行備份...等。 23 | - 可以利用其他語言整合其他相關應用,例如:亂數 C++ 程式可以呼叫一個指令和在您的 Model 裡面執行程式! 24 | 25 | 讓我們來嘗試:Hello World! 26 | ========================== 27 | 28 | 讓我們建立一支簡單的控制器來當作範例,利用您的編輯器新增檔案 Tools.php,並且將底下程式碼寫入到檔案裡面: :: 29 | 30 | 13 | 14 | .. function:: is_php($version) 15 | 16 | :param string $version: 版本號 17 | :returns: TRUE 如果當前 PHP 版本至少是你提供的版本號,否則 FALSE 18 | :rtype: bool 19 | 20 | 確定是否正在使用的PHP版本大於提供的版本號。 21 | 22 | 例子: :: 23 | 24 | if (is_php('5.3')) 25 | { 26 | $str = quoted_printable_encode($str); 27 | } 28 | 29 | 如果系統的 PHP 版本等於或高於你所提供的版本,本函數將返回布林值 TRUE。如果系統的 PHP 版本低於你所提供的那個版本,本函數將返回 FALSE。 30 | 31 | .. function:: is_really_writable($file) 32 | 33 | :param string $file: 檔案路徑 34 | :returns: TRUE 如果路徑是可以被寫入的,否則 FALSE 35 | :rtype: bool 36 | 37 | 在 Windows 伺服器上,除非檔案屬性標示成唯讀否則作業系統不會傳回 FALSE,結果就是即使你真的無法寫入檔案 ``is_writable()`` 仍然可能返回 TRUE。這個函數會先嘗試寫入檔案來確認它是否真的可以寫入。一般只有在平台不可靠時才建議你是用這個函數。 38 | 39 | 這個函數第一步嘗試寫入檔案來確認是否檔案真的可以被寫入。一般只會在推薦的平台上使用這個函數。這個信息可能是不可靠的。 40 | 41 | 例子: :: 42 | 43 | if (is_really_writable('file.txt')) 44 | { 45 | echo "I could write to this if I wanted to"; 46 | } 47 | else 48 | { 49 | echo "File is not writable"; 50 | } 51 | 52 | .. note:: 另請參見 `PHP bug #54709 `_ 查看更多訊息。 53 | 54 | .. function:: config_item($key) 55 | 56 | :param string $key: 配置項目的鍵 57 | :returns: 配置訊息的鍵值,如果找不到則 NULL 58 | :rtype: mixed 59 | 60 | :doc:`Config 函式庫 <../libraries/config>` 為獲取配置信息的首選方式,因為 ``config_item()`` 可用於檢索單個鍵。查看 :doc:`Config 函式庫 <../libraries/config>` 61 | 查看更多訊息。 62 | 63 | .. :noindex: function:: show_error($message, $status_code[, $heading = 'An Error Was Encountered']) 64 | 65 | :param mixed $message: Error message 66 | :param int $status_code: HTTP Response status code 67 | :param string $heading: Error page heading 68 | :rtype: void 69 | 70 | This function calls ``CI_Exception::show_error()``. For more info, 71 | please see the :doc:`Error Handling ` documentation. 72 | 73 | .. :noindex: function:: show_404([$page = ''[, $log_error = TRUE]]) 74 | 75 | :param string $page: URI string 76 | :param bool $log_error: Whether to log the error 77 | :rtype: void 78 | 79 | This function calls ``CI_Exception::show_404()``. For more info, 80 | please see the :doc:`Error Handling ` documentation. 81 | 82 | .. :noindex: function:: log_message($level, $message) 83 | 84 | :param string $level: Log level: 'error', 'debug' or 'info' 85 | :param string $message: Message to log 86 | :rtype: void 87 | 88 | This function is an alias for ``CI_Log::write_log()``. For more info, 89 | please see the :doc:`Error Handling ` documentation. 90 | 91 | .. function:: set_status_header($code[, $text = '']) 92 | 93 | :param int $code: HTTP 回應狀態碼 94 | :param string $text: 客製化狀態碼訊息 95 | :rtype: void 96 | 97 | 允許你操作設定伺服器標頭狀態。例如: :: 98 | 99 | set_status_header(401); 100 | // 設定標頭狀態成: Unauthorized 101 | 102 | `查看 `_ 獲得完整標頭列表。 103 | 104 | .. function:: remove_invisible_characters($str[, $url_encoded = TRUE]) 105 | 106 | :param string $str: 輸入字串 107 | :param bool $url_encoded: 是否移除 URL-編碼 字元 108 | :returns: 已過濾字串 109 | :rtype: string 110 | 111 | 這個函數防止插入 NULL 字元,在 ASCII 112 | 字元之間,像是 Java\\0script 。 113 | 114 | 例子: :: 115 | 116 | remove_invisible_characters('Java\\0script'); 117 | // Returns: 'Javascript' 118 | 119 | .. function:: html_escape($var) 120 | 121 | :param mixed $var: 要跳脫的變數(字串或陣列) 122 | :returns: 已跳脫的 HTML 字串 123 | :rtype: mixed 124 | 125 | 這個函數作為一個 PHP 的原生函數 ``htmlspecialchars()`` 的別名,好處是可以接受字串陣列。 126 | 127 | 這是一個有效防止跨站腳本攻擊的函數(XSS)。 128 | 129 | .. function:: get_mimes() 130 | 131 | :returns: 關聯檔案型態的陣列 132 | :rtype: array 133 | 134 | 這個函數回傳一個 *參考* 它是 MIMEs 陣列來自於 135 | *application/config/mimes.php* 。 136 | 137 | .. function:: is_https() 138 | 139 | :returns: TRUE 如果當前連線使用 HTTP-over-SSL,否則 FALSE 140 | :rtype: bool 141 | 142 | 回傳 TRUE 如果當前是安全(HTTPS)連線,否則 FALSE 143 | 在其它情況下(包含 non-HTTP 請求)。 144 | 145 | .. function:: is_cli() 146 | 147 | :returns: TRUE 如果當前連線是在 CLI 底下,否則 FALSE 148 | :rtype: bool 149 | 150 | Returns TRUE 如果應用程式執行在命令列底下,否則 FALSE。 151 | 152 | .. note:: 這個函數檢查,變數 ``PHP_SAPI`` 值是 'cli' 153 | 或者如果常數 ``STDIN`` 是已經被定義的,則為判斷是在 CLI 底下執行。 154 | 155 | .. function:: function_usable($function_name) 156 | 157 | :param string $function_name: 函數名稱 158 | :returns: TRUE 如果這個函數可以被使用,否則 FALSE 159 | :rtype: bool 160 | 161 | 回傳 TRUE 如果這個函數是存在的以及可用的,否則 FALSE。 162 | 163 | 這個函數執行一個 ``function_exists()`` 函數來檢查是否 164 | `Suhosin extension ` 是被載入的, 165 | 檢查是否它沒有關閉這個函數被檢查的功能。 166 | 167 | 如果你想要檢查你的函數可否使用,這個方法是非常有用的,像是 ``eval()`` 以及 ``exec()`` , 168 | 這兩個函數是非常危險的,在高度嚴格的安全策略服務器可能被禁用。 169 | 170 | .. note:: 此功能被引入,因為了 Suhosin 終止腳本執行,但事實證明這是一個錯誤。這個修復已經有一段時間了(版本0.9.34),但遺憾的是還沒有發布。 171 | -------------------------------------------------------------------------------- /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 | - 類別宣告必須繼承(extend)父類別 54 | - 你的新類別名稱與檔名必須使用 MY\_ 前置字串(這是可設定的,請見下述)。 55 | 56 | 例如,要擴充一個內建的 Input 類別,你要先新增檔名為 application/core/MY_Input.php 的檔案,然後這樣宣告你的類別: :: 57 | 58 | class MY_Input extends CI_Input { 59 | 60 | } 61 | 62 | .. note:: 如果你需要在你的類別中使用建構函數(Constructor),確定有在裡面擴充父類別的建構函數(Constructor): 63 | 64 | :: 65 | 66 | class MY_Input extends CI_Input { 67 | 68 | public function __construct() 69 | { 70 | parent::__construct(); 71 | } 72 | } 73 | 74 | **Tip:** 你類別中任何與父類別中相同名稱的函數,將會取代父類別的(這一般叫做“方法覆蓋 method overriding”)。這個方式允許你實質上改變 CodeIgniter 的核心。 75 | 76 | 如果你要擴充控制器(Controller)核心類別,請確定有在你的應用程式控制器(Controller)的建構函數(Constructor)中擴充你的新類別。 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/general/creating_drivers.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 自建驅動器 3 | ################ 4 | 5 | Driver 目錄和檔案架構 6 | =================================== 7 | 8 | 底下是簡單 driver 目錄和檔案架構設計: 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 目錄名稱第一個字母必須為大寫 ``ucfirst()``。 20 | 21 | .. note:: 驅動器類別的架構是無法 extends 的,所以它不會繼承主驅動器類別的變數以及方法。 22 | -------------------------------------------------------------------------------- /source/general/credits.rst: -------------------------------------------------------------------------------- 1 | ####### 2 | Credits 3 | ####### 4 | 5 | CodeIgniter was originally developed by `Rick Ellis `_ 6 | (CEO of `EllisLab, Inc. `_). The framework was written for 7 | performance in the real world, with many of the class libraries, helpers, and 8 | sub-systems borrowed from the code-base of `ExpressionEngine 9 | `_. 10 | 11 | It was, for years, developed and maintained by EllisLab, the ExpressionEngine 12 | Development Team and a group of community members called the Reactor Team. 13 | 14 | In 2014, CodeIgniter was acquired by the `British Columbia Institute of Technology 15 | `_ and was then officially announced as a community-maintaned 16 | project. 17 | 18 | Bleeding edge development is spearheaded by the handpicked contributors 19 | of the Reactor Team. 20 | 21 | A hat tip goes to Ruby on Rails for inspiring us to create a PHP framework, and 22 | for bringing frameworks into the general consciousness of the web community. 23 | -------------------------------------------------------------------------------- /source/general/drivers.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | 使用 CodeIgniter 驅動器 3 | ######################### 4 | 5 | 驅動器是集合了一個父類別和複數個有關係子類別的特殊程式庫。子類別會使用到父類別的一些功能,但是他們不是父子關係(繼承)。驅動器在各種類別庫得益於或需要分拆成不同類別的情況下,提供在 :doc:`控制器(Controllers) ` 中能夠以優雅的方式撰寫。 6 | 7 | 驅動器位於 *system/libraries* 的檔案裡面, 它們會被歸類在與父類別相同名稱的目錄底下,同時所有相關的子類別會存放在一個名為 drivers 附屬檔案中。 8 | 9 | 當你需要使用驅動器時, 你必須使用以下的函數來進行初式化的動作:: 10 | 11 | $this->load->driver('class_name'); 12 | 13 | 上面的 class\_name 是你要調用驅動器的名稱。例如,加載一個名為 "Some Parent" 驅動器的範例如下:: 14 | 15 | $this->load->driver('some_parent'); 16 | 17 | 下面示範調用該類別的方法:: 18 | 19 | $this->some_parent->some_method(); 20 | 21 | 此外,我們還能夠透過父類別呼叫隸屬於該驅動器的子類別,而無須額外進行初始化:: 22 | 23 | $this->some_parent->child_one->some_method(); 24 | $this->some_parent->child_two->another_method(); 25 | 26 | 新增屬於自己的 Drivers 27 | ========================= 28 | 29 | 請先仔細閱讀手冊 :doc:`自建驅動器 ` 章節。 30 | -------------------------------------------------------------------------------- /source/general/environments.rst: -------------------------------------------------------------------------------- 1 | ############################## 2 | 處理多環境變數 3 | ############################## 4 | 5 | 程式開發者常常根據目前是開發階段或者是產品階段來調整系統狀況。舉例來說錯誤輸出對於開發階段是非常有用的,但是如果產品”上線“了,這錯誤訊息就是代表著系統漏洞甚至安全訊息的疑慮。 6 | 7 | ENVIRONMENT 常數 8 | ======================== 9 | 10 | CodeIgniter 自帶一個環境常數 ``$_SERVER['CI_ENV']`` 預設將環境變數設定為‘development’。在 index.php 頂端你會發現底下程式碼: :: 11 | 12 | define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); 13 | 14 | 這個伺服器變數可以被設定在你的 .htaccess 檔案,或者 Apache 15 | 設定於 `SetEnv `_。 16 | 用於 nginx 以及其它伺服器的方法,你可以完全地移除這個邏輯然後基於伺服器 IP 位置設定常數。 17 | 18 | 除了影響一些基本框架的行為(見下一節),你可以使用這個常數在開發之間區分什麼樣的環境正在運行。 19 | 20 | 預設框架行為的影響 21 | ===================================== 22 | 23 | 在原始 CodeIgniter 系統裡面,此變數備用在某些地方,此章節會描述環境變數 ENVIRONMENT 所帶來的影響。 24 | 25 | 錯誤回報 26 | --------------- 27 | 28 | 設定 ENVIRONMENT 值為‘development’將會打開所有錯誤訊息,遇到 PHP 錯誤,瀏覽器將會顯示其訊息,相反地,如果設定為‘production’,系統將會關閉錯誤訊息。關閉錯誤訊息是 :doc:`好的安全實作 ` 。 29 | 30 | 設定檔 31 | ------------------- 32 | 33 | 此功能可以選擇性的使用,您可以讀取特定的 environment 設定檔,對於需要多種環境的開發者來說相當方便,使用方式可以參考 `Config 類別 <../libraries/config.html#environments>`_ 文件。 34 | -------------------------------------------------------------------------------- /source/general/errors.rst: -------------------------------------------------------------------------------- 1 | ############## 2 | 錯誤處理 3 | ############## 4 | 5 | CodeIgniter 讓你使用下列的函數來在你的應用程式中建立錯誤報告。 6 | 此外,它還有一個 logging 類別來讓錯誤以及除錯訊息可以存成文字檔。 7 | 8 | .. note:: CodeIgniter 預設會顯示所有PHP錯誤訊息。 9 | 你可能會希望在開發過程完畢後改變這個行為。 10 | 你可以在主要的 index.php 檔案的開頭找到 error_reporting() 這個函數。 11 | 即使取消錯誤報告,錯誤仍然會寫入 log 檔。 12 | 13 | 不像大部分 CodeIgniter 的系統,錯誤處理函數只是在整個系統中都可以直接呼叫的程序式函數介面。 14 | 這個方式讓你觸發錯誤訊息時不必擔心 class/function 的有效範圍。 15 | 16 | CodeIgniter 也會回傳狀態碼無論系統核心何時呼叫 ``exit()`` 函數。 17 | 這個結束狀態碼是分隔 HTTP 狀態碼,並作為一個給其它程序的通知服務, 18 | 這個服務監視其他程序是否代碼成功地執行完成,或者導致代碼執行終止的問題。 19 | 這個變數定義於 *application/config/constants.php* 。While 結束狀態碼在 CLI 設定是最有用的, 20 | 回傳適當的狀態碼幫助伺服器軟體保持追蹤你的腳本以及應用程式的健康。 21 | 22 | 這個函數讓你用下列的錯誤訊息模板來顯示給予的錯誤訊息: 23 | 24 | .. php:function:: show_error($message, $status_code, $heading = 'An Error Was Encountered') 25 | 26 | :param mixed $message: 錯誤訊息 27 | :param int $status_code: HTTP 回應狀態碼 28 | :param string $heading: 錯誤頁面標頭 29 | :rtype: void 30 | 31 | 這個函數將顯示錯誤訊息使用以下模板提供給你: :: 32 | 33 | application/views/errors/error_general.php 34 | 35 | 在錯誤訊息中這個可選的參數 ``$status_code`` 決定什麼 HTTP 狀態碼應該被傳送。 36 | 如果 ``$status_code`` 小於 100,HTTP 狀態碼將會被設定為 500,然後結束狀態碼將會被設定成 37 | ``$status_code + EXIT__AUTO_MIN`` 。如果這個值大於 38 | ``EXIT__AUTO_MAX`` ,或者如果 ``$status_code`` 是 100 或者更高,結束狀態碼將會被設定為 ``EXIT_ERROR`` 。 39 | 你可以檢查 *application/config/constants.php* 以獲得更多細節。 40 | 41 | .. php:function:: show_404($page = '', $log_error = TRUE) 42 | 43 | :param string $page: URI 字串 44 | :param bool $log_error: 是否紀錄錯誤 45 | :rtype: void 46 | 47 | 這個函數將會顯示 404 錯誤訊息,提供以下錯誤訊息模板: :: 48 | 49 | application/views/errors/error_404.php 50 | 51 | 傳遞給該函數需要的字符串是未找到頁面的文件路徑。 52 | 結束狀態碼將被設定在 ``EXIT_UNKNOWN_FILE`` 。 53 | 注意如果控制器(Controller)未找到,CodeIgniter 自動地顯示 404 訊息。 54 | 55 | CodeIgniter 自動地記錄所有 ``show_404()`` 呼叫。設定第二個參數選項 FALSE 將不會做記錄。 56 | 57 | ... php:function:: log_message($level, $message) 58 | 59 | :param string $level: 記錄層級: 'error','debug' 或者 'info' 60 | :param string $message: 記錄的訊息 61 | :rtype: void 62 | 63 | 這個函數讓你寫錯誤訊息到你的記錄檔案內。 64 | 你一定三選一中要提供一個 "levels" 到第一個參數內,指定這個錯誤是屬於哪種形態(debug、error、info), 65 | 到第二個參數。 66 | 67 | 例子: :: 68 | 69 | if ($some_var == '') 70 | { 71 | log_message('error', 'Some variable did not contain a value.'); 72 | } 73 | else 74 | { 75 | log_message('debug', 'Some variable was correctly set'); 76 | } 77 | 78 | log_message('info', 'The purpose of some variable is to provide some value.'); 79 | 80 | 這裡有三種錯誤訊息型態: 81 | 82 | #. Error 訊息。這裡是實際上的錯誤,像是 PHP 錯誤或者使用者錯誤。 83 | #. Debug 訊息。這裡的訊息是除錯用的。例如,如果一個類別被初始化,你可以記錄它當作除錯訊息。 84 | #. Informational 訊息。這裡是最低優先權的訊息,簡單地給對於一些過程信息。CodeIgniter 本身不產生 85 | info 訊息,如果你要做是可以做的。 86 | 87 | .. note:: 為了實際被寫入記錄文件, *logs* 目錄必須設為可以寫入。 88 | 除此之外,你一定要設定“threshold”來做記錄在這邊設定 *application/config/config.php* 。你可能,例如,只需要 error 訊息被記錄,以及不需要其他兩個型態的記錄。如果你設定他為 0 ,記錄將會被關閉。 89 | -------------------------------------------------------------------------------- /source/general/helpers.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | 輔助函式 3 | ################ 4 | 5 | 輔助,顧名思義,幫助您的任務。每個輔助函式是一個簡單的功能,在特定類別的集合。 **URL 輔助函式** ,可以幫助我們創建連接,有 Form 輔助函式可以幫助您創建表單元素, **Text 輔助函式** 進行各種文本格式的程序, **Cookie 輔助函式** 設置和讀取cookie, **File 輔助函式** 幫你處理文件,等等。 6 | 7 | 不像大多數其它系統中,輔助函式不是用物件導向的格式。他們是簡單的,程序的功能。每個輔助函式處理一個特定的任務,與其他功能無依賴性。 8 | 9 | CodeIgniter 在預設情況下不讀取任何輔助檔案,所以使用輔助函式第一步就是讀取它們。一旦讀取它們,就會成為全域變數可以通過 :doc:`控制器 Controller <../general/controllers>` 以及 10 | :doc:`Views <../general/views>` 操作它們。 11 | 12 | 輔助函式通常儲存在你的 **system/helpers** 目錄或 **application/helpers** 目錄。 CodeIgniter 會先找 **application/helpers** 目錄。 如果目錄不存在,或者目錄下不存在這個輔助函式ㄊ,CI 將轉為讀取 **system/helpers/** 目錄下的輔助函式。 13 | 14 | 載入輔助函式 15 | ================ 16 | 17 | 載入一個輔助函式是相當簡單的使用下面的方法: :: 18 | 19 | $this->load->helper('name'); 20 | 21 | 這個 **name** 輔助函式的檔案名稱,不需要 .php 後綴名稱 或者 ”helper“ 字串。 22 | 23 | 例如,要載入 **URL 輔助函式** 檔案,他的檔案名稱是 **url_helper.php** ,你可以這樣做: :: 24 | 25 | $this->load->helper('url'); 26 | 27 | 輔助函式可以在任何地方被載入,從您的 Controller 方法內(甚至在您 View 的文件,雖然這不是一個很好的做法),只要你使用它之前,你加載它就可以了。你可以加載你的輔助函式在你的 Contoller 建構子,使他們在任何函式內都可以自動地使用,或者您也可以在需要它的特定功能加載一個輔助函式。 28 | 29 | .. note:: 輔助函式載入時如上述方法沒有返回值,所以不要嘗試將它分配給一個變數。只要使用它,如上所示。 30 | 31 | 載入多個輔助函式 32 | ======================== 33 | 34 | 如果你需要加載多個輔助函式,你可以在一個陣列,像這樣指定它們: :: 35 | 36 | $this->load->helper( 37 | array('helper1', 'helper2', 'helper3') 38 | ); 39 | 40 | 自動載入輔助函式 41 | ==================== 42 | 43 | 如果你發現你需要在全域使用特定輔助函式,你可以在 CodeIgniter 的系統初始化過程中自動加載它。這是通過 **application/config/autoload.php** 文件並添加輔助函式的自動加載陣列 **$autoload['helper']** 來完成。 44 | 45 | 使用輔助函式 46 | ============== 47 | 48 | 一旦你載入了想要使用的輔助函式文件,你會將它視為一個標準的PHP函式。 49 | 50 | 例如,創造一個連接,使用 ``anchor()`` 函式,放到你的 View 檔案裡,你可以這樣做: :: 51 | 52 | 53 | 54 | 其中 "Click Here" 是連接的名字,然後 "blog/comments" 是通過 URI 去連接到 controller/method 。 55 | 56 | “擴展” 輔助函式 57 | =================== 58 | 59 | 為了 “擴展” 輔助函式,創立一個檔案到 **application/helpers/** 資料夾內 且文件具有與現存輔助函式相同名稱,但是前綴要寫 **MY\_** (該名稱是可配置的,見下文。)。 60 | 61 | 如果你需要做的就是在現有的輔助函式上添加一些功能,也許增加一個或兩個功能,或者更改特定的輔助函式工作 - 您如果替換掉整個輔助函式那就太不值得。在這種情況下,最好是 ”擴展“ 的輔助函式。 62 | 63 | .. note:: 術語 "extend" 是寬鬆地,因為輔助函式是程序化的且獨立的以及不能用傳統的程式設計的意義去擴展它。在底層下,這項功能給你一個能力去增加或替換掉輔助函式提供的功能。 64 | 65 | 例如,為了擴展原生的 **Array 輔助函式** 你要創立一個檔案名為 **application/helpers/MY_array_helper.php** 然後新增一個函式複寫掉原本的函式: :: 66 | 67 | // any_in_array() 並不在 Array 補助函式中,所以要定義一個新函式 68 | function any_in_array($needle, $haystack) 69 | { 70 | $needle = is_array($needle) ? $needle : array($needle); 71 | 72 | foreach ($needle as $item) 73 | { 74 | if (in_array($item, $haystack)) 75 | { 76 | return TRUE; 77 | } 78 | } 79 | 80 | return FALSE; 81 | } 82 | 83 | // random_element() 已包含在 Array 補助函式中,所以會覆蓋原有的函式 84 | function random_element($array) 85 | { 86 | shuffle($array); 87 | return array_pop($array); 88 | } 89 | 90 | 設定你自己的前綴 91 | ----------------------- 92 | 93 | 檔案名稱的前綴是 "擴展" 輔助函式,同樣也是或展 函式庫 以及 核心類別。 為了要設定自己的前綴,請打開 **application/config/config.php** 檔案然後尋找這個設定:: 94 | 95 | $config['subclass_prefix'] = 'MY_'; 96 | 97 | 請注意所有的原生 CodeIgniter 函式庫的字首是 **CI\_** 所以不要使用這個字串當做你的前綴。 98 | 99 | 現在該做什麼? 100 | ========= 101 | 102 | 在目錄表,你會發現所有可用的輔助函式的列表。瀏覽每一個看到他們做了什麼。 103 | -------------------------------------------------------------------------------- /source/general/hooks.rst: -------------------------------------------------------------------------------- 1 | #################################### 2 | Hooks-擴充核心 3 | #################################### 4 | 5 | CodeIgniter 的 Hooks 機制提供了一個方法來進入並改變框架的內部作業而不用修改核心檔案。當 CodeIgniter 執行時,它會遵循在 :doc:`程式流程圖 <../overview/appflow>` 頁面中圖示的流程。不過在一些實例中,你也許會想要在流程的特定的階段執行特定的動作。例如,你可能會想要在你的控制器(Controller)載入前後執行一些程式,或是在其他位置觸發你自己的程式。 6 | 7 | 啟動 Hooks 8 | ============== 9 | 10 | Hooks 機制可以透過下列 **application/config/config.php** 檔案中的設定項目來啟動: :: 11 | 12 | $config['enable_hooks'] = TRUE; 13 | 14 | 定義一個 Hook 15 | =============== 16 | 17 | Hooks 定義在 **application/config/hooks.php** 檔案中。每一個hook都用下面陣列的方式來指定: 18 | 19 | :: 20 | 21 | $hook['pre_controller'] = array( 22 | 'class' => 'MyClass', 23 | 'function' => 'Myfunction', 24 | 'filename' => 'Myclass.php', 25 | 'filepath' => 'hooks', 26 | 'params' => array('beer', 'wine', 'snacks') 27 | ); 28 | 29 | **Notes:** 30 | 31 | 陣列索引的名稱與你要使用的特定的 hook 插入點相對應。在上例中,hook 插入點是 pre_controller 。本頁底下可以找到一個hook插入點的清單。另外,以下的項目必須在hook的關係陣列中定義好: 32 | 33 | - **class** 你想要執行的類別名稱。如果你想要使用一個函數而不是類別,就保持空白。 34 | - **function** 你要呼叫的函數名稱。 35 | - **filename** 你的類別/函數所在的檔案名稱。 36 | - **filepath** 包含你程式的目錄名稱。注意:程式必須在你的 application 目錄內,所以這個目錄名稱是相對於 application 的路徑。例如,如果你的程式放在 *application/hooks* ,那你只要用 hooks 當作 ‘filepath’。如果你的程式放在 *application/hooks/utilities*,那你要用 hooks/utilities 作為 ‘filepath’。路徑最後不用加斜線。 37 | - **params** 任何你希望傳遞給程式的參數,這是非必須的選項。 38 | 39 | 你也可以使用 lambda/anoymous 函數(或者閉包函數)寫 hooks,使用簡單的語法: :: 40 | 41 | $hook['post_controller'] = function() 42 | { 43 | /* do something here */ 44 | }; 45 | 46 | 在同一的 Hook 中多次呼叫 47 | =============================== 48 | 49 | 如果要在一個hook插入多個程式,只要把陣列宣告成多維的就可以。像這樣: :: 50 | 51 | $hook['pre_controller'][] = array( 52 | 'class' => 'MyClass', 53 | 'function' => 'MyMethod', 54 | 'filename' => 'Myclass.php', 55 | 'filepath' => 'hooks', 56 | 'params' => array('beer', 'wine', 'snacks') 57 | ); 58 | 59 | $hook['pre_controller'][] = array( 60 | 'class' => 'MyOtherClass', 61 | 'function' => 'MyOtherMethod', 62 | 'filename' => 'Myotherclass.php', 63 | 'filepath' => 'hooks', 64 | 'params' => array('red', 'yellow', 'blue') 65 | ); 66 | 67 | 注意要在陣列索引後加上中括號: :: 68 | 69 | $hook['pre_controller'][] 70 | 71 | 這樣就可以讓你在一個 hook 中插入多個程式。程式執行的順序就是你在陣列中定義的順序。 72 | 73 | Hook 插入點 74 | =========== 75 | 76 | 以下是可用的 hook 插入點清單。 77 | 78 | - **pre_system** 79 | 在系統執行的初期執行。這時只有benchmark及hook類別被載入。路由或其他程序都還沒執行。 80 | - **pre_controller** 81 | 在所有的控制器(Controller)呼叫之前執行。此時所有的基礎類別、路由、安全檢查都已經完成。 82 | - **post_controller_constructor** 83 | 在控制器(controller)實例化之後但是任何方法都還未呼叫之前立刻執行。 84 | - **post_controller** 85 | 在控制器(Controller)執行完畢之後立刻執行。 86 | - **display_override** 87 | 覆蓋用來在系統執行完畢後向瀏覽器送出完成的頁面的 ``_display()`` 函數。這樣就允許你用你自己定義的顯示方法。注意,你必須用 ``$this->CI =& get_instance()`` 取得CI參考物件然後才可透過呼叫 ``$this->CI->output->get_output()`` 來使用完成的頁面資料。 88 | - **cache_override** 89 | 讓你可以呼叫自己定義的函數而非 :doc:`Output 函式庫 <../libraries/output>` 中的 ``_display_cache()`` 函數。這讓你可以使用自己的 cache 顯示機制。 90 | - **post_system** 91 | 在完成的頁面送到瀏覽器之後呼叫。在系統執行結束時,完成的資料已送到瀏覽器之後執行。 92 | -------------------------------------------------------------------------------- /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 | PHP Style Guide 34 | -------------------------------------------------------------------------------- /source/general/libraries.rst: -------------------------------------------------------------------------------- 1 | ########################### 2 | 使用 CodeIgniter 函式庫 3 | ########################### 4 | 5 | 所有可用的函式庫置於 system/libraries 目錄之下。大部份情況,其中的類別可透過 :doc:`controller ` 使用下列函式來啟用:: 6 | 7 | $this->load->library('class_name'); 8 | 9 | 其中 'class_name' 為你想取的類別名稱。舉例來說,你可以底下方式來載入 :doc:`Form Validation Library 10 | <../libraries/form_validation>` 類別:: 11 | 12 | $this->load->library('form_validation'); 13 | 14 | 只要載入後,你就可以依照教學手冊的相關章節來使用它。 15 | 16 | 你還可以一次載入多個函式庫,只要傳入一個包含多個函式庫的陣列即可。 17 | 18 | 例如:: 19 | 20 | $this->load->library(array('email', 'table')); 21 | 22 | 建立自己的函式庫 23 | =========================== 24 | 25 | 請閱讀使用手冊的相關章節來學習如何 26 | :doc:`create your own libraries `. 27 | -------------------------------------------------------------------------------- /source/general/managing_apps.rst: -------------------------------------------------------------------------------- 1 | ########################## 2 | 管理你的應用程式 3 | ########################## 4 | 5 | 預設情況是假設你的 CodeIgniter 只打算用 Codeigniter 管理一個 application,其位在 *application/* 目錄之下。讓多組 application 來共享單一的 CodeIgniter 安裝環境是可行的,也許以更改或是移動 application 目錄至它處亦可。 6 | 7 | 更改 Application 目錄名稱 8 | ================================== 9 | 10 | 如果想要更改 application 目錄名稱,你也必須要修改 index.php 檔案中的 ``$application_folder`` 變數部份: :: 11 | 12 | $application_folder = 'application'; 13 | 14 | 移動 Application 目錄 15 | ===================================== 16 | 17 | 也可以移動 application 目錄到伺服器的預設的目錄以外的地方。若要這樣的話,請修改 index.php 然後設定 完整伺服器路徑放到 ``$application_folder`` 變數: :: 18 | 19 | $application_folder = '/path/to/your/application'; 20 | 21 | 執行多組 application 共享單一 CodeIgniter 安裝環境 22 | =============================================================== 23 | 24 | 若有意共享單一 CodeIgniter 環境,來管理多組的 applications 的話,只需要把在 application 裡的所有目錄,複製到其他的以目錄底下。 25 | 26 | 假如,你要新增兩個名為“foo”以及”bar“的 application。你的 application 的目錄結構應該會像這樣: :: 27 | 28 | applications/foo/ 29 | applications/foo/config/ 30 | applications/foo/controllers/ 31 | applications/foo/libraries/ 32 | applications/foo/models/ 33 | applications/foo/views/ 34 | applications/bar/ 35 | applications/bar/config/ 36 | applications/bar/controllers/ 37 | applications/bar/libraries/ 38 | applications/bar/models/ 39 | applications/bar/views/ 40 | 41 | 只要用某個 application 的話,請編輯 index.php 檔案然後設定 ``$application_folder`` 變數。 例如,選用”foo“ application 來用的話,你則需要這麼做: :: 42 | 43 | $application_folder = 'applications/foo'; 44 | 45 | .. note:: 每個 application 都需要自己的 index.php 檔案, 其負責呼叫自己所需要的 application。這個 index.php 可以隨你開心來改名。 46 | -------------------------------------------------------------------------------- /source/general/models.rst: -------------------------------------------------------------------------------- 1 | ########### 2 | 模型 Models 3 | ########## 4 | 5 | 模型(Models)是給傳統 MVC 架構更多 **可選地** 提供使用。 6 | 7 | .. contents:: 頁面內容 8 | 9 | 什麼是 Model? 10 | ================ 11 | 12 | Models 是 PHP 類別,它是被設計來存取資料庫用的。比如說,使用 CodeIgniter 去管理部落格。你可以有一個 Model 類別它包含函式去 insert,update,還有 retrieve 你的部落格資料。這裡有個例子,來看看 Model 類別是怎麼樣的: :: 13 | 14 | class Blog_model extends CI_Model { 15 | 16 | public $title; 17 | public $content; 18 | public $date; 19 | 20 | public function __construct() 21 | { 22 | parent::__construct(); 23 | // Your own constructor code 24 | } 25 | 26 | public function get_last_ten_entries() 27 | { 28 | $query = $this->db->get('entries', 10); 29 | return $query->result(); 30 | } 31 | 32 | public function insert_entry() 33 | { 34 | $this->title = $_POST['title']; // please read the below note 35 | $this->content = $_POST['content']; 36 | $this->date = time(); 37 | 38 | $this->db->insert('entries', $this); 39 | } 40 | 41 | public function update_entry() 42 | { 43 | $this->title = $_POST['title']; 44 | $this->content = $_POST['content']; 45 | $this->date = time(); 46 | 47 | $this->db->update('entries', $this, array('id' => $_POST['id'])); 48 | } 49 | 50 | } 51 | 52 | .. note:: 在上述例子我們使用 :doc:`Query Builder <../database/query_builder>` 方法去存取資料庫。 53 | 54 | .. note:: 為簡單起見,在本實施例中,我們直接地使用 ``$_POST`` 。這通常是不好的做法,更好的方法將是使用 :doc:`Input 函式庫 <../libraries/input>` ``$this->input->post('title')`` 。 55 | 56 | 剖析 Model 57 | ================== 58 | 59 | Model 類別是儲存在 **application/models/** 目錄。 它們可以巢狀的包含在子目錄中,如果你想要分類組織了話,這是個好方法。 60 | 61 | 基本的 Model 類別原型長這樣: :: 62 | 63 | class Model_name extends CI_Model { 64 | 65 | public function __construct() 66 | { 67 | parent::__construct(); 68 | } 69 | 70 | } 71 | 72 | 這個 **Model_name** 是你的類別名稱。 類別名稱 **一定要** 第一個字母大寫的,其餘部分小寫的。請確認你的類別擴展基本的 Model 類別。 73 | 74 | 檔案名稱要跟類別名稱一樣。例如: :: 75 | 76 | class User_model extends CI_Model { 77 | 78 | public function __construct() 79 | { 80 | parent::__construct(); 81 | } 82 | 83 | } 84 | 85 | 你的檔案目錄會長這樣: :: 86 | 87 | application/models/User_model.php 88 | 89 | 載入 Model 90 | =============== 91 | 92 | 你的 models 會被呼叫,通過 :doc:`控制器 Controller ` 呼叫方法。 用以下方法載入 models: :: 93 | 94 | $this->load->model('model_name'); 95 | 96 | 如果你的 Model 位於子目錄,引入相關的路徑經由 Models 目錄。位於 *application/models/blog/Queries.php* 你將要讀取它,用法: :: 97 | 98 | $this->load->model('blog/queries'); 99 | 100 | 一旦載入,你會使用一個物件是具有相同於 Model 名稱的物件,它可以執行你 Model 的方法: :: 101 | 102 | $this->load->model('model_name'); 103 | 104 | $this->model_name->method(); 105 | 106 | 如果你想分配給 Model 不同的名稱,你可以通過傳入的第二個參數指定它: :: 107 | 108 | $this->load->model('model_name', 'foobar'); 109 | 110 | $this->foobar->method(); 111 | 112 | 這裡是一個 Controller,載入一個 Model 的例子,然後提供給一個 View: :: 113 | 114 | class Blog_controller extends CI_Controller { 115 | 116 | public function blog() 117 | { 118 | $this->load->model('blog'); 119 | 120 | $data['query'] = $this->blog->get_last_ten_entries(); 121 | 122 | $this->load->view('blog', $data); 123 | } 124 | } 125 | 126 | 127 | 自動載入 Models 128 | =================== 129 | 130 | 如果你想要在整個應用程式中全域加載,並使用某些 model 你可以打開 **application/config/autoload.php** 檔案,然後增加這些 model 到 $autoload['model'] 陣列裡。 131 | 132 | 連接資料庫 133 | =========================== 134 | 135 | 當 Model 被載入進來,但是 **還沒** 自動地連接到資料庫。 提供給您連接資料庫的選項在下面: 136 | 137 | - 您可以連接使用標準資料庫的方法 :doc:`這裡描述 <../database/connecting>` 無論你從 Controller 類別 或 Model 類別連接都可以。 138 | - 你可以告訴 Model 加載時自動連接資料庫,透過第三個參數傳遞TRUE(Boolean)自動連接和連接設置,在你的資料庫設定文件中定義將被使用:: 139 | 140 | $this->load->model('model_name', '', TRUE); 141 | 142 | - 您可以通過第三個參數通過手動資料庫連接設置: :: 143 | 144 | $config['hostname'] = 'localhost'; 145 | $config['username'] = 'myusername'; 146 | $config['password'] = 'mypassword'; 147 | $config['database'] = 'mydatabase'; 148 | $config['dbdriver'] = 'mysqli'; 149 | $config['dbprefix'] = ''; 150 | $config['pconnect'] = FALSE; 151 | $config['db_debug'] = TRUE; 152 | 153 | $this->load->model('model_name', '', $config); 154 | -------------------------------------------------------------------------------- /source/general/profiling.rst: -------------------------------------------------------------------------------- 1 | ########################## 2 | 應用程式效能分析 3 | ########################## 4 | 5 | 這個效能分析類別(Profiler Class)會顯示出 Benchmark 的查詢結果、然後將 ``$_POST`` 的資料置於頁面的尾端。這些資訊在進行開發時,用來協助除錯或是最佳化相當有用。 6 | 7 | 初始化類別 8 | ====================== 9 | 10 | .. important:: 這各類別不需要額外步驟將它初始化。他可由 :doc:`Output 函式庫 <../libraries/output>` 自動載入,效能分析功能就會啟動並顯示結果在頁面尾端。 11 | 12 | 啟動效能分析器 13 | ===================== 14 | 15 | 在 :doc:`控制器(Controller) ` 函數中,啟動效能分析器: :: 16 | 17 | $this->output->enable_profiler(TRUE); 18 | 19 | 啟動之後,效能結果就會被產生出來放入頁面尾端。 20 | 21 | 關閉效能分析器的方式: :: 22 | 23 | $this->output->enable_profiler(FALSE); 24 | 25 | 設定 Benchmark 點 26 | ======================== 27 | 28 | 為了使效能分析器去編譯以及顯示 Benchmark 資料,你一定標記 Benchmark 點。 29 | 30 | 請參考設定 Benchmark 點的分法 :doc:`Benchmark 函式庫 <../libraries/benchmark>` 頁面。 31 | 32 | 啟動和關閉效能分析器的區段 33 | ======================================== 34 | 35 | 分析資料中的每個字段可通過設置相應的控制變數 TRUE or FALSE 來啟用和關閉。其中的一個方法是:你可以在 *application/config/profiler.php* 設定文件裡設置整個程序的全域預設值。 36 | 37 | 例子: :: 38 | 39 | $config['config'] = FALSE; 40 | $config['queries'] = FALSE; 41 | 42 | 你可以在控制器中通過呼叫 ``set_profiler_sections()`` 來複寫預設的設定,詳細參考: :doc:`Output 函式庫 <../libraries/output>` : :: 43 | 44 | $sections = array( 45 | 'config' => TRUE, 46 | 'queries' => TRUE 47 | ); 48 | 49 | $this->output->set_profiler_sections($sections); 50 | 51 | 下表列出了可用的分析器資料字段和用來訪問這些字段的 key。 52 | 53 | ======================= =================================================================== ======== 54 | Key Description Default 55 | ======================= =================================================================== ======== 56 | **benchmarks** 在各個計時點花費的時間以及總時間 TRUE 57 | **config** CodeIgniter 設定變數 TRUE 58 | **controller_info** 被呼叫的方法以及所屬的控制器類別 TRUE 59 | **get** 請求所傳遞的所有 GET 資料 TRUE 60 | **http_headers** 本次請求的 HTTP 標頭 TRUE 61 | **memory_usage** 本次請求所消耗的總記憶體空間,用 bytes 來計算 TRUE 62 | **post** 請求所傳遞的所有 POST 資料 TRUE 63 | **queries** 列出資料庫操作的語句以及消耗的時間 TRUE 64 | **uri_string** 本次請求的 URI 字串 TRUE 65 | **session_data** 本次的資料儲存在 session TRUE 66 | **query_toggle_count** 在幾次資料庫語句執行,資料庫區塊預設為隱藏 25 67 | ======================= =================================================================== ======== 68 | 69 | .. note:: 從資料庫設定檔中關閉 :doc:`save_queries ` 設定將會有效關閉無用的資料庫’語句操作‘以及頁面呈現分析的消耗資源。你可以選擇性地複寫掉這個設定 ``$this->db->save_queries = TRUE;`` 。沒有這個設置,您將無法查看資料庫語句操作或者 `last_query ` 。 70 | -------------------------------------------------------------------------------- /source/general/requirements.rst: -------------------------------------------------------------------------------- 1 | ################### 2 | Server 需求 3 | ################### 4 | 5 | `PHP `_ 版本 5.6 或者更高版本。 6 | 7 | It should work on 5.3.7 as well, but we strongly advise you NOT to run 8 | such old versions of PHP, because of potential security and performance 9 | issues, as well as missing features. 10 | 11 | 大多網站數應用程式是需要資料庫的。 12 | 13 | 現在支持的資料庫: 14 | - MySQL (5.1+) via the *mysql* (棄用), *mysqli* and *pdo* drivers 15 | - Oracle via the *oci8* and *pdo* drivers 16 | - PostgreSQL via the *postgre* and *pdo* drivers 17 | - MS SQL via the *mssql*, *sqlsrv* (version 2005 and above only) and *pdo* drivers 18 | - SQLite via the *sqlite* (version 2), *sqlite3* (version 3) and *pdo* drivers 19 | - CUBRID via the *cubrid* and *pdo* drivers 20 | - Interbase/Firebird via the *ibase* and *pdo* drivers 21 | - ODBC via the *odbc* and *pdo* drivers (you should know that ODBC is actually an abstraction layer) 22 | -------------------------------------------------------------------------------- /source/general/reserved_names.rst: -------------------------------------------------------------------------------- 1 | ############## 2 | 保留名稱 3 | ############## 4 | 5 | 為了幫忙大家, CodeIgniter 使用了一系列的函式,方法,類別以及變數名稱在它們的操作之中。因為如此,所以有些名稱不能給開發者使用。下面列表是保留名稱,不可以使用。 6 | 7 | Controller 名稱 8 | ---------------- 9 | 10 | 因為你的 Controller 類別將擴展主要的應用程式 Controller 所以你一定要小心不要將方法命名成這些,否則你的原生方法會覆蓋它們。 下面是保留的名稱的列表。不要任何這些命名您的 Controller: 11 | 12 | - Controller 13 | - CI_Base 14 | - _ci_initialize 15 | - Default 16 | - index 17 | 18 | Functions 名稱 19 | --------------- 20 | 21 | - :func:`is_php()` 22 | - :func:`is_really_writable()` 23 | - ``load_class()`` 24 | - ``is_loaded()`` 25 | - ``get_config()`` 26 | - :func:`config_item()` 27 | - :func:`show_error()` 28 | - :func:`show_404()` 29 | - :func:`log_message()` 30 | - :func:`set_status_header()` 31 | - :func:`get_mimes()` 32 | - :func:`html_escape()` 33 | - :func:`remove_invisible_characters()` 34 | - :func:`is_https()` 35 | - :func:`function_usable()` 36 | - :func:`get_instance()` 37 | - ``_error_handler()`` 38 | - ``_exception_handler()`` 39 | - ``_stringify_attributes()`` 40 | 41 | Variables 名稱 42 | -------------- 43 | 44 | - ``$config`` 45 | - ``$db`` 46 | - ``$lang`` 47 | 48 | Constants 名稱 49 | -------------- 50 | 51 | - ENVIRONMENT 52 | - FCPATH 53 | - SELF 54 | - BASEPATH 55 | - APPPATH 56 | - VIEWPATH 57 | - CI_VERSION 58 | - MB_ENABLED 59 | - ICONV_ENABLED 60 | - UTF8_ENABLED 61 | - FILE_READ_MODE 62 | - FILE_WRITE_MODE 63 | - DIR_READ_MODE 64 | - DIR_WRITE_MODE 65 | - FOPEN_READ 66 | - FOPEN_READ_WRITE 67 | - FOPEN_WRITE_CREATE_DESTRUCTIVE 68 | - FOPEN_READ_WRITE_CREATE_DESTRUCTIVE 69 | - FOPEN_WRITE_CREATE 70 | - FOPEN_READ_WRITE_CREATE 71 | - FOPEN_WRITE_CREATE_STRICT 72 | - FOPEN_READ_WRITE_CREATE_STRICT 73 | - EXIT_SUCCESS 74 | - EXIT_ERROR 75 | - EXIT_CONFIG 76 | - EXIT_UNKNOWN_FILE 77 | - EXIT_UNKNOWN_CLASS 78 | - EXIT_UNKNOWN_METHOD 79 | - EXIT_USER_INPUT 80 | - EXIT_DATABASE 81 | - EXIT__AUTO_MIN 82 | - EXIT__AUTO_MAX 83 | -------------------------------------------------------------------------------- /source/general/routing.rst: -------------------------------------------------------------------------------- 1 | ########### 2 | URI 路由 3 | ########### 4 | 5 | 一般說來,在URL字串與對應的控制器(controller)class/function 之間有著一對一的關係。 通常這些在 URI 中的片段會遵照下列的模式::: 6 | 7 | example.com/class/function/id/ 8 | 9 | 不過在一些實例中,你可能想要重新映射這個關係好讓不同的 class/function 可以被呼叫,而不是原本對應到 URL 的 class/function。 10 | 11 | 例如,假設你要讓你的 URL 有以下的形式: :: 12 | 13 | example.com/product/1/ 14 | example.com/product/2/ 15 | example.com/product/3/ 16 | example.com/product/4/ 17 | 18 | 正常狀況下,URL的第二片段是保留給函數名稱,但是在上例中,它卻含有 product ID。 為了克服這個狀況,CodeIgniter 允許你重新對應 URL handler。 19 | 20 | 設定你自己的路由規則 21 | ============================== 22 | 23 | 路由規則定義在你的 *application/config/routes* 。你可以在裡面看到一個叫做 $route 的陣列,它允許你指定你自己的路由標準。路由可以用萬用字元或是正規式來指定。 24 | 25 | 萬用字元 26 | ========= 27 | 28 | 一個典型的萬用字元路由看起來會像這樣: :: 29 | 30 | $route['product/:num'] = 'catalog/product_lookup'; 31 | 32 | 在一個路由中,陣列的 key 包含了要被匹配的 URI,而陣列值則包含要被重導的目標。 在上例中,如果“product”這個字在 URL 的第一片段,而且第二片段是數字,則轉而使用“catalog”類別以及“product_lookup”方法。 33 | 34 | 你可以用文字的值或是兩種萬用字元來匹配: 35 | 36 | **(:num)** 將匹配只含有數字的一個片段。 37 | **(:any)** 將匹配含有任何字元的一個片段(除了 '/',這是區段界定符號)。 38 | 39 | .. note:: 萬用字元實際上是正規表達式的別名, 40 | **:any** 被翻譯成 **[^/]+** 以及 **:num** 被翻譯成 **[0-9]+** 。 41 | 42 | .. note:: 路由將依照被定義的順序去路由。 較優先的路由總是會優先於較後的路由。 43 | 44 | .. note:: 路由規則不是過濾器!設定規則像是 e.g. 45 | 'foo/bar/(:num)' 如果這是一個有效的路徑,不會防止控制器 *Foo* 以及方法 46 | *bar* 被非數字的直呼叫。 47 | 48 | 例子 49 | ======== 50 | 51 | 這裡有幾個路由的範例: :: 52 | 53 | $route['journals'] = 'blogs'; 54 | 55 | 一個在第一片段包含“journals”這個字的 URL,將被重新對應到”blogs“類別。 56 | :: 57 | 58 | $route['blog/joe'] = 'blogs/users/34'; 59 | 60 | 一個包含“blog/joe”片段的URL,將重新對應到”blogs“類別以及“users”方法。ID 將會設定成”34“。 61 | 62 | :: 63 | 64 | $route['product/(:any)'] = 'catalog/product_lookup'; 65 | 66 | 一個在第一片段是“product”而在第二片段是任何值的 URL,將重新對應到“catalog”類別以及“product_lookup”方法。 67 | 68 | :: 69 | 70 | $route['product/(:num)'] = 'catalog/product_lookup_by_id/$1'; 71 | 72 | 一個在第一片段為“product”而第二片段是任何數字的 URL 將重新對應到“catalog”類別以及“product_lookup_by_id”方法,匹配的數字將傳給這個函數作為變數。 73 | 74 | .. important:: 不要在開頭/結尾使用斜線。 75 | 76 | 正規表達式 77 | =================== 78 | 79 | 如果你偏好使用正規表達式來定義路由規則,任何合法的正規式都允許使用,包括 back-reference。 80 | 81 | .. note:: 如果使用 back-reference,你必須使用 $ 語法而不是 \\ 語法。 82 | 83 | 一個典型的正規表達式路由可能看起來像這樣::: 84 | 85 | $route['products/([a-z]+)/(\d+)'] = '$1/id_$2'; 86 | 87 | 在上例中,一個像 products/shirts/123 的 URL 會轉而呼叫“shirts”控制器(Controller)類別及 id_123 函數。 88 | 89 | 使用正規表達式,你也可以一次分隔多個區段的內容。 90 | 91 | 例如,如果使用者想存取你的 Web 應用程式被保護區域的密碼,在登入之後,你希望重導向它們回其他頁面, 92 | 你可以參考以下有用的範例: :: 93 | 94 | $route['login/(.+)'] = 'auth/login/$1'; 95 | 96 | 這些對於你不了解正規表達式,並且希望學習更多關於正規表達式,參考 `regular-expressions.info ` 可能是一個良好的啟點。 97 | 98 | .. note:: 你也可以使用正規表達式時混合以及匹配萬用字元。 99 | 100 | 回調 101 | ========= 102 | 103 | 你可以使用回調函數來取代一般的路由規則來處理 back-references。例子: :: 104 | 105 | $route['products/([a-zA-Z]+)/edit/(\d+)'] = function ($product_type, $id) 106 | { 107 | return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id; 108 | }; 109 | 110 | 路由中使用 HTTP 動詞 111 | ========================== 112 | 113 | 這是有可能的使用 HTTP 動詞(request method)去定義你的路由規則。 114 | 這是特別有用的當建立 RESTful 應用程式的時後。你可以使用標準的 HTTP 115 | 動詞(GET、PUT、POST、DELETE、PATCH)或者客製化的動詞像是(e.g. PURGE)。HTTP 動詞規則不區分大小寫。所有你需要做的路由,就是將動詞增加到你的陣列索引裡面。 116 | 117 | 例如: :: 118 | 119 | $route['products']['put'] = 'product/insert'; 120 | 121 | 上述例子,PUT 請求到 URI“products” 稱之為 ``Product::insert()`` 122 | 控制器方法。 123 | 124 | :: 125 | 126 | $route['products/(:num)']['DELETE'] = 'product/delete/$1'; 127 | 128 | DELETE 請求到 URL“products”第一個片段,數字在第二個片段將會重新映射到 ``Product::delete()`` 方法,傳入數值到第一個參數上。 129 | 130 | 使用 HTTP 動詞當然是可選的(非必要)。 131 | 132 | 保留的路由 133 | =============== 134 | 135 | 這裏有三個保留的路由: :: 136 | 137 | $route['default_controller'] = 'welcome'; 138 | 139 | 這個路由指定在 URI 裡沒有任何資料時要載入哪個控制器(Controller)類別,人們載入根 URL 時就是這個情況。在上例中,“welcome”類別將被載入。你要儘量有一個預設路由,否則預設會出現一個 404 頁面。 140 | 141 | :: 142 | 143 | $route['404_override'] = ''; 144 | 145 | 這個路由指定控制器類別應該被載入,如果請求控制器找不到的時候。 146 | 它將會複寫預設的 404 錯誤頁面。 147 | Same per-directory rules as with 'default_controller' apply here as well. 148 | 這不會影響 ``show_404()`` 函數,將依舊載入預設 *error_404.php* 檔案在 149 | *application/views/errors/error_404.php* 。 150 | 151 | 152 | :: 153 | 154 | $route['translate_uri_dashes'] = FALSE; 155 | 156 | 很顯然這是布林值,這不是真的路由。 157 | 這個選項使你自動地在控制器的方法中 URI 片段將底線替換掉破折號(’-‘),如果你需要做成這樣,從而節省您更多的路由項目。 158 | 這是必須的,因為破折號不是有效得類別或者方法名稱字元,如果你使用破折號,會導致重大錯誤。 159 | -------------------------------------------------------------------------------- /source/general/urls.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | CodeIgniter URLs 3 | ################ 4 | 5 | 在預設情況下,URLs 在 CodeIgniter 是被設計對搜尋引擎以及人類閱讀友善的方式。而不是用標準的 "query string" 的 URLs 同義動態系統,CodeIgniter 使用 6 | (分段式) **segment-based** 像是:: 7 | 8 | example.com/news/article/my_article 9 | 10 | .. note:: Query string URLs 是可以被啟動的,在下面會再敘述。 11 | 12 | URI 區段 13 | ============ 14 | 15 | 區段在 URL 中,是通過 Model-View-Controller 架構來完成,常常表示方式如下: :: 16 | 17 | example.com/class/function/ID 18 | 19 | #. 第一個區段被調用的是控制器 **class**。 20 | #. 第二個區段代表被稱為類別 **function** 或者方法。 21 | #. 第三個區段,以及所有額外的區段,代表ID以及所有以及後面的變數,它會傳送到 controller 裡面。 22 | 23 | :doc:`URI Library <../libraries/uri>` 以及 :doc:`URL Helper 24 | <../helpers/url_helper>` 包含了功能,可以很容易的使用 URI 資料。除此之外,你的 URLs 可以更彈性的被重映射 使用 25 | :doc:`URI Routing ` 功能。 26 | 27 | 移除掉 index.php 檔案 28 | =========================== 29 | 30 | 在預設情況下 **index.php** 檔案會被包好到你的 URLs: :: 31 | 32 | example.com/index.php/news/article/my_article 33 | 34 | 如果你的 Apache server 有啟動 **mod_rewrite** ,你可以很簡單的移除掉這個字串,使用簡單的規則通過修改 .htaccess 即可達成。這裡有簡單的範例檔案,使用”原生“方法,來重導向所有請求,除了指定的項目之外: 35 | 36 | :: 37 | 38 | .. code-block:: console 39 | 40 | RewriteEngine On 41 | RewriteCond %{REQUEST_FILENAME} !-f 42 | RewriteCond %{REQUEST_FILENAME} !-d 43 | RewriteRule ^(.*)$ index.php/$1 [L] 44 | 45 | 在上述的例子中,所有的 HTTP request 除了現有的資料夾以及現有的檔案,其他請求會被視為通過你的 index.php 去請求。 46 | 比方說如果你的專案在 http://localhost/CI/index.php 如果放在 CI 這個目錄下,您有個 images 資料夾、以及 index.php 還有 robots.txt 這三個東西必須公開存取的,那麼你可以這樣做: 47 | 48 | :: 49 | 50 | .. code-block:: console 51 | 52 | RewriteEngine on 53 | RewriteBase /CI 54 | RewriteCond $1 !^(index\.php|images|robots\.txt|$) 55 | RewriteRule ^(.*)$ index.php/$1 [L,QSA] 56 | 57 | 公開存取的檔案或資料夾,在 RewriteCond 中可以通過 | 來分隔公開存取的檔案或資料夾,如果專案是在 http://localhost 底下,那麼 RewriteBase 後面接 / 即可。 58 | 59 | 假設是使用 Nginx 伺服器,請參考底下設定: 60 | 61 | :: 62 | 63 | location / { 64 | try_files $uri $uri/ /index.php; 65 | } 66 | 67 | location ~ \.php$ { 68 | fastcgi_pass unix:/var/run/php5-fpm.sock; 69 | fastcgi_index index.php; 70 | fastcgi_split_path_info ^(.+\.php)(.*)$; 71 | include fastcgi_params; 72 | fastcgi_param HTTPS off; 73 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 74 | } 75 | 76 | .. note:: 這些具體的規則可能並不適用於所有 Server 配置工作。 77 | 78 | .. note:: 請務必遵從上面的規則,你可能需要從公開訪問的任何檔案或資料夾排除。 79 | 80 | 增加 URL 後綴 81 | =================== 82 | 83 | 在你的 **config/config.php** 檔案裡,你可以指定一個後綴來加入到所有的 URLs 產生中,通過 CodeIgniter。以下例子,如果你的 URL 是: :: 84 | 85 | example.com/index.php/products/view/shoes 86 | 87 | 通過修改參數 **$config['url_suffix']** 你可以增加一個後綴,像是 .html 讓頁面顯示如下例子: :: 88 | 89 | example.com/index.php/products/view/shoes.html 90 | 91 | 啟動 Query Strings 92 | ====================== 93 | 94 | 在一些例子中,如果你比較喜歡使用 query strings URLs 像是: :: 95 | 96 | index.php?c=products&m=view&id=345 97 | 98 | CodeIgniter 可選地支援這項功能,它可以被啟動,在你的 **application/config.php** 檔案裡。 如果你打開設定,你會看到以下項目: :: 99 | 100 | $config['enable_query_strings'] = FALSE; 101 | $config['controller_trigger'] = 'c'; 102 | $config['function_trigger'] = 'm'; 103 | 104 | 如果你修改了 "enable_query_strings" 成 TRUE 這個功能就會被啟動。 你的 controllers 和 functions 將會被通過 "觸發" 字串來存取,你所設定的調用 controllers 以及 methods: :: 105 | 106 | index.php?c=controller&m=method 107 | 108 | .. note:: 如果你使用 query strings 你將必須建立你自己的 URLs,而不能用 URL 輔助函式(以及其它輔助函式像是 form輔助函式 來產生 URLs)因為這些設計有基於分段 URL 工作的。 109 | -------------------------------------------------------------------------------- /source/general/views.rst: -------------------------------------------------------------------------------- 1 | ########## 2 | 視圖 Views 3 | ########## 4 | 5 | 視圖(View)只是簡單的網站頁面,或者片段頁面,像是 header, footer,sidebar,等等。事實上,Views 可以很彈性的嵌入到其它 Views(包含其它 views 等等)如果你需要這樣的層次結構。 6 | 7 | 8 | 視圖(Views)無法直接呼叫,他們一定要通過 :doc:`控制器 Controller ` 來呼叫。 記得在 MVC framework 時, :doc:`Controllers ` 像是交通警察一樣工作,所以他負責去抓取指定的視圖(View)。如果你還沒看過控制器(Controllers)頁面,你應該要先看過唷。 9 | 10 | 使用範例 :doc:`控制器 Controller ` 你會建立一個 Controller 頁面,讓你增加 View 到裡面。 11 | 12 | 建立一個 View 13 | =============== 14 | 15 | 用你的文字編輯器,建立一個檔案叫做 blogview.php ,然後把下面程式碼放進來: :: 16 | 17 | 18 | 19 | My Blog 20 | 21 | 22 |

Welcome to my Blog!

23 | 24 | 25 | 26 | 然後儲存檔案到 *application/views/* 目錄。 27 | 28 | 載入 View 29 | ============== 30 | 31 | 為了載入指定的 View 你可以跟隨下面操作放到 Controller 裡的方法裡: :: 32 | 33 | $this->load->view('name'); 34 | 35 | 它的名字就是你 View 檔案的名字。 36 | 37 | .. note:: 後綴 .php 是不需要的唷,除非你有其它或連續的 .php 。 38 | 39 | 現在,打開你的 Controller 目錄,你新增一個簡單的名稱叫做 Blog.php,用頁面讀取方法取道掉 echo 語句: :: 40 | 41 | load->view('blogview'); 47 | } 48 | } 49 | 50 | 你通過 URL 來拜訪你的網站,你將會看到你的頁面。這個 URL 大概長這樣: :: 51 | 52 | example.com/index.php/blog/ 53 | 54 | 載入多個 Views 55 | ====================== 56 | 57 | CodeIgniter 將會聰明地處理多個呼叫 ``$this->load->view()`` 從 Controller 裡面。如果呼叫超過一個,那麼它們會被連續附加在一起。例如,你可能有 header view,menu view,content view,以及 footer view。然後像這樣: :: 58 | 59 | load->view('header'); 67 | $this->load->view('menu'); 68 | $this->load->view('content', $data); 69 | $this->load->view('footer'); 70 | } 71 | 72 | } 73 | 74 | 從上述例子來看,我們運用了 “動態附加資料” ,您將會在下面看到。 75 | 76 | 儲存 Views 到子目錄 77 | ==================================== 78 | 79 | 你的 View 檔案可以被儲存到子目錄內,如果你喜歡分類組織了話。如果你這樣做你將需要去引入子目錄名稱來讀取 View。 例如: :: 80 | 81 | $this->load->view('directory_name/file_name'); 82 | 83 | 增加動態資料到 View 84 | =============================== 85 | 86 | 資料是使用 **陣列** 或 **物件** 從 Controller 傳送到 View 裡面,透過 View 讀取的方法傳入第二個參數內。這裡是運用陣列的方法: :: 87 | 88 | $data = array( 89 | 'title' => 'My Title', 90 | 'heading' => 'My Heading', 91 | 'message' => 'My Message' 92 | ); 93 | 94 | $this->load->view('blogview', $data); 95 | 96 | 然後這裡是運用物件的方法傳入: :: 97 | 98 | $data = new Someclass(); 99 | $this->load->view('blogview', $data); 100 | 101 | .. note:: 如果你是用物件,類別變數將會被轉成陣列元素。 102 | 103 | 讓我們試試看 增加到你的 Controller 檔案裡。 新增以下程式碼: :: 104 | 105 | load->view('blogview', $data); 114 | } 115 | } 116 | 117 | 現在打開你的 View 檔案然後改變字串替換成陣列的鍵值: :: 118 | 119 | 120 | 121 | <?php echo $title;?> 122 | 123 | 124 |

125 | 126 | 127 | 128 | 然後通過 URL 來讀取頁面, 你已經使用變數代替原本的字串了。 129 | 130 | 建立迴圈 131 | ============== 132 | 133 | 傳遞給你的 View 文件中的資料陣列並不局限於簡單的變量。你可以通過多維陣列,可以循環產生多個欄位資料。例如,如果你從資料庫中撈取資料,這時它通常是在一個多維陣列的形式。 134 | 135 | 這裡有一個簡單的例子。添加到您的 Controller: :: 136 | 137 | load->view('blogview', $data); 148 | } 149 | } 150 | 151 | 現在打開你的 View 文件,建立一個迴圈: :: 152 | 153 | 154 | 155 | <?php echo $title;?> 156 | 157 | 158 |

159 | 160 |

My Todo List

161 | 162 |
    163 | 164 | 165 |
  • 166 | 167 | 168 |
169 | 170 | 171 | 172 | 173 | .. note:: 你會注意到,在上面我們使用 PHP 的替代語法的例子。如果你不熟悉它,你可以閱讀一下 :doc:`這裡 ` 。 174 | 175 | 資料回傳到 views 176 | ======================= 177 | 178 | 這裡是第三個 **可選的** 參數,它返回讀取那個頁面的整個 HTML,而不是將其發送到瀏覽器。如果你在處理資料的狀況下,這個方法是很有用的。如果你設定成 TRUE(boolean)它就會回傳資料。預設是 false,那麼他就會將 View 發送到瀏覽器了。 如果你要有資料回傳,記得塞入這個變數: :: 179 | 180 | $string = $this->load->view('myfile', '', TRUE); 181 | -------------------------------------------------------------------------------- /source/general/welcome.rst: -------------------------------------------------------------------------------- 1 | ###################### 2 | 歡迎加入 CodeIgniter 3 | ###################### 4 | 5 | CodeIgniter 網站應用程式框架 - 給運用 PHP 開發網站工程師的一個工具。它的目標是使你在開發專案在一般需求功能時,提供一群豐富的函式庫以及函式庫介面和存取函式庫的邏輯結構,使你在開發一般功能時比從頭造輪子還快許多。 CodeIgniter 讓你專注於專案之上,使你寫出最小化的程式碼達到需要的功能。 6 | 7 | *********************** 8 | CodeIgniter 適合誰? 9 | *********************** 10 | 11 | 如果你是以下陳述,那麼 CodeIgniter 適合你: 12 | 13 | - 你想要一個佔用空間小的 Framework。 14 | - 你需要卓越的性能。 15 | - 你需要一個能夠在大部分主機上執行PHP變數以及設定的 Framework。 16 | - 你想要一個幾乎不用額外設定的 Framework。 17 | - 你想要一個不必下 Command 的 Framework。 18 | - 你想要一個不要求嚴格規範編碼規則的 Framework。 19 | - 你沒有興趣在 large-scale monolithic libraries 像是 PEAR。 20 | - 你不想去強迫學習一種模板語言(如果你需要一個,模板解析器還是可選使用的)。 21 | - 你喜歡簡單、討厭複雜的解決方法。 22 | - 你需要一份簡單且透徹的使用文件。 23 | -------------------------------------------------------------------------------- /source/helpers/array_helper.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | Array 輔助函式 3 | ############ 4 | 5 | Array 輔助函式包含了各種輔助陣列操作的相關函式。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 導入輔助函式 15 | =================== 16 | 17 | Array 輔助函式的載入語法如下: 18 | 19 | $this->load->helper('array'); 20 | 21 | 22 | 可用函式格式 23 | =================== 24 | 25 | 允許使用的函式格式如下: 26 | 27 | 28 | .. php:function:: element($item, $array[, $default = NULL]) 29 | 30 | :param string $item: 欲從來源陣列中取出的元素 31 | :param array $array: 來源陣列 32 | :param bool $default: 如果非有效來源陣列要回傳的值 33 | :returns: 失敗時回傳 NULL 成功時回傳陣列元素 34 | :rtype: 各種型態皆有 35 | 36 | 此輔助函式可讓你從來源陣列中提取元素,也可測試出陣列中是否具有索引和值,如果存在將會回傳該值,反之則回傳 NULL 或任何你標明在第三個參數當中的預設值。 37 | 38 | 範例 39 | :: 40 | 41 | $array = array( 42 | 'color' => 'red', 43 | 'shape' => 'round', 44 | 'size' => '' 45 | ); 46 | 47 | echo element('color', $array); // returns "red" 48 | echo element('size', $array, 'foobar'); // returns "foobar" 49 | 50 | 51 | .. php:function:: elements($items, $array[, $default = NULL]) 52 | 53 | :param string $item: 欲從來源陣列中取出的元素組 54 | :param array $array: 來源陣列 55 | :param bool $default: 如果非有效來源陣列要賦予的值 56 | :returns: 失敗時回傳 NULL 成功時回傳陣列元素組 57 | :rtype: 各種型態皆有 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 | 76 | array( 77 | 'color' => 'red', 78 | 'shape' => 'round', 79 | 'height' => NULL 80 | ); 81 | 82 | 第三個參數的預設賦予值可以依你喜好方式設置。 83 | :: 84 | 85 | $my_shape = elements(array('color', 'shape', 'height'), $array, 'foobar'); 86 | 87 | 上方程式碼執行後將會回傳此陣列: 88 | :: 89 | 90 | array(      91 | 'color' => 'red', 92 | 'shape' => 'round', 93 | 'height' => 'foobar' 94 | ); 95 | 96 | 此函式在傳送 ``$_POST`` 陣列至 Model 時相當有用,可以避免使用者混入額外的 POST data 進你的資料表。 97 | 98 | :: 99 | 100 | $this->load->model('post_model'); 101 | $this->post_model->update( 102 | elements(array('id', 'title', 'content'), $_POST) 103 | ); 104 | 105 | 可以保證只有 id、title、content 這三個欄位會被送出更新。 106 | 107 | 108 | .. php:function:: random_element($array) 109 | 110 | :param array $array: 來源陣列 111 | :returns: 來源陣列中的隨機元素 112 | :rtype: 各種型態皆有 113 | 114 | 在來源陣列中隨機挑選一個元素回傳。 115 | 116 | 範例 117 | :: 118 | 119 | $quotes = array( 120 | "I find that the harder I work, the more luck I seem to have. - Thomas Jefferson", 121 | "Don't stay in bed, unless you can make money in bed. - George Burns", 122 | "We didn't lose the game; we just ran out of time. - Vince Lombardi", 123 | "If everything seems under control, you're not going fast enough. - Mario Andretti", 124 | "Reality is merely an illusion, albeit a very persistent one. - Albert Einstein", 125 | "Chance favors the prepared mind - Louis Pasteur" 126 | ); 127 | 128 | echo random_element($quotes); 129 | -------------------------------------------------------------------------------- /source/helpers/captcha_helper.rst: -------------------------------------------------------------------------------- 1 | ############## 2 | CAPTCHA 輔助函式 3 | ############## 4 | 5 | CAPTCHA 輔助函式包含了各種輔助產生驗證圖片的相關函式。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | 導入輔助函式 15 | =================== 16 | 17 | CAPTCHA 輔助函式的載入語法如下: 18 | :: 19 | 20 | $this->load->helper('captcha'); 21 | 22 | 使用 CAPTCHA 輔助函式 23 | ======================== 24 | 25 | 準備好如下所示的語法後,就可以產生驗證碼: 26 | :: 27 | 28 | $vals = array( 29 | 'word' => 'Random word', 30 | 'img_path' => './captcha/', 31 | 'img_url' => 'http://example.com/captcha/', 32 | 'font_path' => './path/to/fonts/texb.ttf', 33 | 'img_width' => '150', 34 | 'img_height' => 30, 35 | 'expiration' => 7200, 36 | 'word_length' => 8, 37 | 'font_size' => 16, 38 | 'img_id' => 'Imageid', 39 | 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 40 | 41 | // White background and border, black text and red grid 42 | 'colors' => array( 43 | 'background' => array(255, 255, 255), 44 | 'border' => array(255, 255, 255), 45 | 'text' => array(0, 0, 0), 46 | 'grid' => array(255, 40, 40) 47 | ) 48 | ); 49 | 50 | $cap = create_captcha($vals); 51 | echo $cap['image']; 52 | 53 | - 驗證碼函式需要 GD 圖像函式庫。 54 | - 只有 **img_path** 與 **img_url** 是必填的。 55 | - 假設沒有填 **word**,函式會自動生成一個隨機的 ASCII 字串,當然你也可以從你自己準備的文字庫當中隨機挑選。 56 | - 如果你沒有標明字型檔的路徑,將會使用醜醜的預設字型。 57 | - “captcha” 資料夾必須是可以寫入的。 58 | - **expiration** (以秒數計) 標明出驗證碼圖示過多久之後會被刪除,預設是兩小時。 59 | - **word_length** 預設為 8,**pool** 預設為 ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’。 60 | - **font_size** 預設為 16,GD 字型有大小限制。如果要使用更大的字體請選用其他字型。 61 | - **img_id** 將是驗證碼圖示的 id。 62 | - 如果任一 **colors** 內的值不見了,將會以預設值代替。 63 | 64 | 建立驗證碼資料庫 65 | ----------------- 66 | 67 | 為了避免驗證碼被有心人士利用,你可以將 ``create_captcha()`` 所回傳的資訊加入到資料庫中。如此一來,當資料從使用者端送來的時候只需要驗證此筆資料是否存在且未過期即可。 68 | 69 | 資料表建置範例 70 | :: 71 | 72 | CREATE TABLE captcha (   73 | captcha_id bigint(13) unsigned NOT NULL auto_increment,   74 | captcha_time int(10) unsigned NOT NULL,   75 | ip_address varchar(45) NOT NULL,   76 | word varchar(20) NOT NULL,   77 | PRIMARY KEY `captcha_id` (`captcha_id`),   78 | KEY `word` (`word`) 79 | ); 80 | 81 | 這是搭配資料庫使用的範例語法。在頁面中驗證碼顯示的地方,你可以填入如下的語法: 82 | :: 83 | 84 | $this->load->helper('captcha'); 85 | $vals = array(      86 | 'img_path' => './captcha/',      87 | 'img_url' => 'http://example.com/captcha/'      88 | ); 89 | 90 | $cap = create_captcha($vals); 91 | $data = array(      92 | 'captcha_time' => $cap['time'],      93 | 'ip_address' => $this->input->ip_address(),      94 | 'word' => $cap['word']      95 | ); 96 | 97 | $query = $this->db->insert_string('captcha', $data); 98 | $this->db->query($query); 99 | 100 | echo 'Submit the word you see below:'; 101 | echo $cap['image']; 102 | echo ''; 103 | 104 | 然後,資料接收端頁面則填入如下語法: 105 | :: 106 | 107 | // 首先,刪除舊的驗證碼 108 | $expiration = time() - 7200; // Two hour limit 109 | $this->db->where('captcha_time < ', $expiration) 110 | ->delete('captcha'); 111 | 112 | // 確認驗證碼是否存在 113 | $sql = 'SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?'; 114 | $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); 115 | $query = $this->db->query($sql, $binds); 116 | $row = $query->row(); 117 | 118 | if ($row->count == 0) 119 | {      120 | echo 'You must submit the word that appears in the image.'; 121 | } 122 | 123 | 可用函式格式 124 | =================== 125 | 126 | 允許使用的函式格式如下: 127 | 128 | .. php:function:: create_captcha([$data = ''[, $img_path = ''[, $img_url = ''[, $font_path = '']]]]) 129 | 130 | :param array $data: 存有驗證碼資訊的陣列 131 | :param string $img_path: 建立驗證碼圖示的路徑 132 | :param string $img_url: 驗證碼圖示資料夾的 URL 133 | :param string $font_path: 字型檔的伺服器路徑 134 | :returns: array('word' => $word, 'time' => $now, 'image' => $img) 135 | :rtype: 陣列 136 | 137 | 取得輸入在陣列中的資訊生成驗證碼,且根據你的需求產生驗證碼圖示,並將圖示的相關資訊回傳。 138 | 139 | :: 140 | 141 | array( 142 | 'image' => IMAGE TAG 143 | 'time' => TIMESTAMP (in microtime) 144 | 'word' => CAPTCHA WORD 145 | ) 146 | 147 | 回傳的 **image** 是 HTML 圖示標籤: 148 | :: 149 | 150 | 151 | 152 | 回傳的 **time** 是被用來當作圖片檔名(沒有副檔名)的時間戳記,就像是這樣的數字:1139612155.3422 153 | 154 | 回傳的 **word** 是出現在驗證碼圖示中的文字,如果沒有指定特定字串給函式的話將會隨機挑選一個字串。 155 | -------------------------------------------------------------------------------- /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 | Cookie 輔助函式的載入語法如下: 18 | :: 19 | 20 | $this->load->helper('cookie'); 21 | 22 | 可用函式格式 23 | =================== 24 | 25 | 允許使用的函式格式如下: 26 | 27 | 28 | .. php:function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]]) 29 | 30 | :param mixed $name: Cookie 名稱或包含函式中所有有效參數的陣列 31 | :param string $value: Cookie 值 32 | :param int $expire: 有效期限秒數 33 | :param string $domain: Cookie 網域名稱(通常是:.yourdomain.com) 34 | :param string $path: Cookie 路徑 35 | :param string $prefix: Cookie 名稱前綴 36 | :param bool $secure: 是否只透過 HTTPS 傳送 Cookie 37 | :param bool $httponly: 是否對 JavaScript 隱藏 Cookie 38 | :rtype: 不回傳任何值 39 | 40 | 此輔助函式對於設置 Cookie 提供了相當友善的語法,可以參考 :doc:`Input Library <../libraries/input>` 敘述中所提到的用法,此函式相當於就是 ``CI_Input::set_cookie()`` 的別名。 41 | 42 | .. php:function:: get_cookie($index[, $xss_clean = NULL]) 43 | 44 | :param string $index: Cookie 名稱 45 | :param bool $xss_clean: 是否對回傳值啟用 XSS 過濾機制 46 | :returns: Cookie 的值或沒有找到就回傳 NULL 47 | :rtype: 各種型態皆有 48 | 49 | 此輔助函式對於取得 Cookie 提供了相當友善的語法,可以參考 :doc:`Input Library <../libraries/input>` 敘述中所提到的用法。此函式執行起來雖與 ``CI_Input::cookie()`` 很相像,但除此之外會加入你在 *application/config/config.php* 檔案中所設置的前綴 ``$config['cookie_prefix']``。 50 | 51 | .. php:function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]) 52 | 53 | :param string $name: Cookie 名稱 54 | :param string $domain: Cookie 網域名稱(通常是:.yourdomain.com) 55 | :param string $path: Cookie 路徑 56 | :param string $prefix: Cookie 名稱前綴 57 | :rtype: void 58 | 59 | 刪除 Cookie 時,除非你指定了路徑或其他值,否則只有具有 **name** 的 Cookie 會被刪除。 60 | :: 61 | 62 | delete_cookie('name'); 63 | 64 | 此函式在格式上除了沒有 **value** 跟 **expire** 這兩個參數之外,其實與 ``set_cookie()`` 不盡相同。你可以只對第一個參數送出一個的陣列或者你也可以個別設置參數。 65 | :: 66 | 67 | delete_cookie($name, $domain, $path, $prefix); 68 | -------------------------------------------------------------------------------- /source/helpers/directory_helper.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | Directory 輔助函式 3 | ################ 4 | 5 | Directory 輔助函式包含了各種處理目錄的相關函式。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | Loading this Helper 15 | =================== 16 | 17 | This helper is loaded using the following code: 18 | 19 | :: 20 | 21 | $this->load->helper('directory'); 22 | 23 | Available Functions 24 | =================== 25 | 26 | The following functions are available: 27 | 28 | 29 | .. php:function:: directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]]) 30 | 31 | :param string $source_dir: Path to the source directory 32 | :param int $directory_depth: Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) 33 | :param bool $hidden: Whether to include hidden directories 34 | :returns: An array of files 35 | :rtype: array 36 | 37 | Examples:: 38 | 39 | $map = directory_map('./mydirectory/'); 40 | 41 | .. note:: Paths are almost always relative to your main index.php file. 42 | 43 | 44 | Sub-folders contained within the directory will be mapped as well. If 45 | you wish to control the recursion depth, you can do so using the second 46 | parameter (integer). A depth of 1 will only map the top level directory:: 47 | 48 | $map = directory_map('./mydirectory/', 1); 49 | 50 | By default, hidden files will not be included in the returned array. To 51 | override this behavior, you may set a third parameter to true (boolean):: 52 | 53 | $map = directory_map('./mydirectory/', FALSE, TRUE); 54 | 55 | Each folder name will be an array index, while its contained files will 56 | be numerically indexed. Here is an example of a typical array:: 57 | 58 | Array ( 59 | [libraries] => Array 60 | ( 61 | [0] => benchmark.html 62 | [1] => config.html 63 | ["database/"] => Array 64 | ( 65 | [0] => query_builder.html 66 | [1] => binds.html 67 | [2] => configuration.html 68 | [3] => connecting.html 69 | [4] => examples.html 70 | [5] => fields.html 71 | [6] => index.html 72 | [7] => queries.html 73 | ) 74 | [2] => email.html 75 | [3] => file_uploading.html 76 | [4] => image_lib.html 77 | [5] => input.html 78 | [6] => language.html 79 | [7] => loader.html 80 | [8] => pagination.html 81 | [9] => uri.html 82 | ) 83 | -------------------------------------------------------------------------------- /source/helpers/download_helper.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | Download 輔助函式 3 | ############### 4 | 5 | Download 輔助函式讓您可以下載資料到桌面。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | Loading this Helper 15 | =================== 16 | 17 | This helper is loaded using the following code:: 18 | 19 | $this->load->helper('download'); 20 | 21 | Available Functions 22 | =================== 23 | 24 | The following functions are available: 25 | 26 | 27 | .. php:function:: force_download([$filename = ''[, $data = ''[, $set_mime = FALSE]]]) 28 | 29 | :param mixed $filename: Filename 30 | :param mixed $data: File contents 31 | :param bool $set_mime: Whether to try to send the actual MIME type 32 | :rtype: void 33 | 34 | Generates server headers which force data to be downloaded to your 35 | desktop. Useful with file downloads. The first parameter is the **name 36 | you want the downloaded file to be named**, the second parameter is the 37 | file data. 38 | 39 | If you set the second parameter to NULL and ``$filename`` is an existing, readable 40 | file path, then its content will be read instead. You may also set ``$filename`` 41 | as an associative array with a single element, where the key of that element would be 42 | the local file you are trying to read and where the value is the name of the downloadable 43 | file that will be sent to browser. An example of this is provided below. 44 | 45 | If you set the third parameter to boolean TRUE, then the actual file MIME type 46 | (based on the filename extension) will be sent, so that if your browser has a 47 | handler for that type - it can use it. 48 | 49 | Example:: 50 | 51 | $data = 'Here is some text!'; 52 | $name = 'mytext.txt'; 53 | force_download($name, $data); 54 | 55 | If you want to download an existing file from your server you'll need to 56 | do the following:: 57 | 58 | // Contents of photo.jpg will be automatically read 59 | force_download('/path/to/photo.jpg', NULL); 60 | -------------------------------------------------------------------------------- /source/helpers/email_helper.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | Email 輔助函式 3 | ############ 4 | 5 | The Email Helper provides some assistive functions for working with 6 | Email. For a more robust email solution, see CodeIgniter's :doc:`Email 7 | Class <../libraries/email>`. 8 | 9 | .. important:: The Email helper is DEPRECATED and is currently 10 | only kept for backwards compatibility. 11 | 12 | .. contents:: 13 | :local: 14 | 15 | .. raw:: html 16 | 17 |
18 | 19 | Loading this Helper 20 | =================== 21 | 22 | This helper is loaded using the following code:: 23 | 24 | $this->load->helper('email'); 25 | 26 | Available Functions 27 | =================== 28 | 29 | The following functions are available: 30 | 31 | 32 | .. php:function:: valid_email($email) 33 | 34 | :param string $email: E-mail address 35 | :returns: TRUE if a valid email is supplied, FALSE otherwise 36 | :rtype: bool 37 | 38 | Checks if the input is a correctly formatted e-mail address. Note that is 39 | doesn't actually prove that the address will be able recieve mail, but 40 | simply that it is a validly formed address. 41 | 42 | Example:: 43 | 44 | if (valid_email('email@somesite.com')) 45 | { 46 | echo 'email is valid'; 47 | } 48 | else 49 | { 50 | echo 'email is not valid'; 51 | } 52 | 53 | .. note:: All that this function does is to use PHP's native ``filter_var()``:: 54 | 55 | (bool) filter_var($email, FILTER_VALIDATE_EMAIL); 56 | 57 | .. php:function:: send_email($recipient, $subject, $message) 58 | 59 | :param string $recipient: E-mail address 60 | :param string $subject: Mail subject 61 | :param string $message: Message body 62 | :returns: TRUE if the mail was successfully sent, FALSE in case of an error 63 | :rtype: bool 64 | 65 | Sends an email using PHP's native `mail() `_ 66 | function. 67 | 68 | .. note:: All that this function does is to use PHP's native ``mail`` 69 | 70 | :: 71 | 72 | mail($recipient, $subject, $message); 73 | 74 | For a more robust email solution, see CodeIgniter's :doc:`Email Library 75 | <../libraries/email>`. 76 | -------------------------------------------------------------------------------- /source/helpers/index.rst: -------------------------------------------------------------------------------- 1 | ####### 2 | 輔助函式 3 | ####### 4 | 5 | .. toctree:: 6 | :glob: 7 | :titlesonly: 8 | 9 | * 10 | -------------------------------------------------------------------------------- /source/helpers/inflector_helper.rst: -------------------------------------------------------------------------------- 1 | ################## 2 | Inflector 輔助函式 3 | ################## 4 | 5 | The Inflector Helper file contains functions that permits you to change 6 | **English** words to plural, singular, camel case, etc. 7 | 8 | .. contents:: 9 | :local: 10 | 11 | .. raw:: html 12 | 13 |
14 | 15 | Loading this Helper 16 | =================== 17 | 18 | This helper is loaded using the following code:: 19 | 20 | $this->load->helper('inflector'); 21 | 22 | Available Functions 23 | =================== 24 | 25 | The following functions are available: 26 | 27 | 28 | .. php:function:: singular($str) 29 | 30 | :param string $str: Input string 31 | :returns: A singular word 32 | :rtype: string 33 | 34 | Changes a plural word to singular. Example:: 35 | 36 | echo singular('dogs'); // Prints 'dog' 37 | 38 | .. php:function:: plural($str) 39 | 40 | :param string $str: Input string 41 | :returns: A plural word 42 | :rtype: string 43 | 44 | Changes a singular word to plural. Example:: 45 | 46 | echo plural('dog'); // Prints 'dogs' 47 | 48 | .. php:function:: camelize($str) 49 | 50 | :param string $str: Input string 51 | :returns: Camelized string 52 | :rtype: string 53 | 54 | Changes a string of words separated by spaces or underscores to camel 55 | case. Example:: 56 | 57 | echo camelize('my_dog_spot'); // Prints 'myDogSpot' 58 | 59 | .. php:function:: underscore($str) 60 | 61 | :param string $str: Input string 62 | :returns: String containing underscores instead of spaces 63 | :rtype: string 64 | 65 | Takes multiple words separated by spaces and underscores them. 66 | Example:: 67 | 68 | echo underscore('my dog spot'); // Prints 'my_dog_spot' 69 | 70 | .. php:function:: humanize($str[, $separator = '_']) 71 | 72 | :param string $str: Input string 73 | :param string $separator: Input separator 74 | :returns: Humanized string 75 | :rtype: string 76 | 77 | Takes multiple words separated by underscores and adds spaces between 78 | them. Each word is capitalized. 79 | 80 | Example:: 81 | 82 | echo humanize('my_dog_spot'); // Prints 'My Dog Spot' 83 | 84 | To use dashes instead of underscores:: 85 | 86 | echo humanize('my-dog-spot', '-'); // Prints 'My Dog Spot' 87 | 88 | .. php:function:: is_countable($word) 89 | 90 | :param string $word: Input string 91 | :returns: TRUE if the word is countable or FALSE if not 92 | :rtype: bool 93 | 94 | Checks if the given word has a plural version. Example:: 95 | 96 | is_countable('equipment'); // Returns FALSE 97 | -------------------------------------------------------------------------------- /source/helpers/language_helper.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | Language 輔助函式 3 | ############### 4 | 5 | Language 輔助函式包含了各種輔助多國語言操作的相關函式。 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 | 27 | .. php:function:: lang($line[, $for = ''[, $attributes = array()]]) 28 | 29 | :param string $line: Language line key 30 | :param string $for: HTML "for" attribute (ID of the element we're creating a label for) 31 | :param array $attributes: 額外的 HTML 元素 32 | :returns: The language line; in an HTML label tag, if the ``$for`` parameter is not empty 33 | :rtype: string 34 | 35 | 此函示回傳顯示格式會比 ``CI_Lang::line()`` 更清楚易懂。 36 | 37 | 範例:: 38 | 39 | echo lang('language_key'); 40 | // Outputs: Language line 41 | 42 | echo lang('language_key', 'form_item_id', array('class' => 'myClass')); 43 | // 顯示: 44 | -------------------------------------------------------------------------------- /source/helpers/number_helper.rst: -------------------------------------------------------------------------------- 1 | ############# 2 | Number 輔助函式 3 | ############# 4 | 5 | The Number Helper file contains functions that help you work with 6 | numeric data. 7 | 8 | .. contents:: 9 | :local: 10 | 11 | .. raw:: html 12 | 13 |
14 | 15 | Loading this Helper 16 | =================== 17 | 18 | This helper is loaded using the following code:: 19 | 20 | $this->load->helper('number'); 21 | 22 | Available Functions 23 | =================== 24 | 25 | The following functions are available: 26 | 27 | 28 | .. php:function:: byte_format($num[, $precision = 1]) 29 | 30 | :param mixed $num: Number of bytes 31 | :param int $precision: Floating point precision 32 | :returns: Formatted data size string 33 | :rtype: string 34 | 35 | Formats numbers as bytes, based on size, and adds the appropriate 36 | suffix. Examples:: 37 | 38 | echo byte_format(456); // Returns 456 Bytes 39 | echo byte_format(4567); // Returns 4.5 KB 40 | echo byte_format(45678); // Returns 44.6 KB 41 | echo byte_format(456789); // Returns 447.8 KB 42 | echo byte_format(3456789); // Returns 3.3 MB 43 | echo byte_format(12345678912345); // Returns 1.8 GB 44 | echo byte_format(123456789123456789); // Returns 11,228.3 TB 45 | 46 | An optional second parameter allows you to set the precision of the 47 | result:: 48 | 49 | echo byte_format(45678, 2); // Returns 44.61 KB 50 | 51 | .. note:: The text generated by this function is found in the following 52 | language file: *language//number_lang.php* 53 | -------------------------------------------------------------------------------- /source/helpers/path_helper.rst: -------------------------------------------------------------------------------- 1 | ########### 2 | Path 輔助函式 3 | ########### 4 | 5 | The Path Helper file contains functions that permits you to work with 6 | file paths on the server. 7 | 8 | .. contents:: 9 | :local: 10 | 11 | .. raw:: html 12 | 13 |
14 | 15 | Loading this Helper 16 | =================== 17 | 18 | This helper is loaded using the following code:: 19 | 20 | $this->load->helper('path'); 21 | 22 | Available Functions 23 | =================== 24 | 25 | The following functions are available: 26 | 27 | 28 | .. php:function:: set_realpath($path[, $check_existance = FALSE]) 29 | 30 | :param string $path: Path 31 | :param bool $check_existance: Whether to check if the path actually exists 32 | :returns: An absolute path 33 | :rtype: string 34 | 35 | This function will return a server path without symbolic links or 36 | relative directory structures. An optional second argument will 37 | cause an error to be triggered if the path cannot be resolved. 38 | 39 | Examples:: 40 | 41 | $file = '/etc/php5/apache2/php.ini'; 42 | echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini' 43 | 44 | $non_existent_file = '/path/to/non-exist-file.txt'; 45 | echo set_realpath($non_existent_file, TRUE); // Shows an error, as the path cannot be resolved 46 | echo set_realpath($non_existent_file, FALSE); // Prints '/path/to/non-exist-file.txt' 47 | 48 | $directory = '/etc/php5'; 49 | echo set_realpath($directory); // Prints '/etc/php5/' 50 | 51 | $non_existent_directory = '/path/to/nowhere'; 52 | echo set_realpath($non_existent_directory, TRUE); // Shows an error, as the path cannot be resolved 53 | echo set_realpath($non_existent_directory, FALSE); // Prints '/path/to/nowhere' 54 | -------------------------------------------------------------------------------- /source/helpers/security_helper.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | Security 輔助函式 3 | ############### 4 | 5 | The Security Helper file contains security related functions. 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | Loading this Helper 15 | =================== 16 | 17 | This helper is loaded using the following code:: 18 | 19 | $this->load->helper('security'); 20 | 21 | Available Functions 22 | =================== 23 | 24 | The following functions are available: 25 | 26 | 27 | .. php:function:: xss_clean($str[, $is_image = FALSE]) 28 | 29 | :param string $str: Input data 30 | :param bool $is_image: Whether we're dealing with an image 31 | :returns: XSS-clean string 32 | :rtype: string 33 | 34 | Provides Cross Site Script Hack filtering. 35 | 36 | This function is an alias for ``CI_Input::xss_clean()``. For more info, 37 | please see the :doc:`Input Library <../libraries/input>` documentation. 38 | 39 | .. php:function:: sanitize_filename($filename) 40 | 41 | :param string $filename: Filename 42 | :returns: Sanitized file name 43 | :rtype: string 44 | 45 | Provides protection against directory traversal. 46 | 47 | This function is an alias for ``CI_Security::sanitize_filename()``. 48 | For more info, please see the :doc:`Security Library <../libraries/security>` 49 | documentation. 50 | 51 | 52 | .. php:function:: do_hash($str[, $type = 'sha1']) 53 | 54 | :param string $str: Input 55 | :param string $type: Algorithm 56 | :returns: Hex-formatted hash 57 | :rtype: string 58 | 59 | Permits you to create one way hashes suitable for encrypting 60 | passwords. Will use SHA1 by default. 61 | 62 | See `hash_algos() `_ 63 | for a full list of supported algorithms. 64 | 65 | Examples:: 66 | 67 | $str = do_hash($str); // SHA1 68 | $str = do_hash($str, 'md5'); // MD5 69 | 70 | .. note:: This function was formerly named ``dohash()``, which has been 71 | removed in favor of ``do_hash()``. 72 | 73 | .. note:: This function is DEPRECATED. Use the native ``hash()`` instead. 74 | 75 | 76 | .. php:function:: strip_image_tags($str) 77 | 78 | :param string $str: Input string 79 | :returns: The input string with no image tags 80 | :rtype: string 81 | 82 | This is a security function that will strip image tags from a string. 83 | It leaves the image URL as plain text. 84 | 85 | Example:: 86 | 87 | $string = strip_image_tags($string); 88 | 89 | This function is an alias for ``CI_Security::strip_image_tags()``. For 90 | more info, please see the :doc:`Security Library <../libraries/security>` 91 | documentation. 92 | 93 | 94 | .. php:function:: encode_php_tags($str) 95 | 96 | :param string $str: Input string 97 | :returns: Safely formatted string 98 | :rtype: string 99 | 100 | This is a security function that converts PHP tags to entities. 101 | 102 | .. note:: :php:func:`xss_clean()` does this automatically, if you use it. 103 | 104 | Example:: 105 | 106 | $string = encode_php_tags($string); 107 | -------------------------------------------------------------------------------- /source/helpers/typography_helper.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | Typography 輔助函式 3 | ################# 4 | 5 | The Typography Helper file contains functions that help your format text 6 | in semantically relevant ways. 7 | 8 | .. contents:: 9 | :local: 10 | 11 | .. raw:: html 12 | 13 |
14 | 15 | Loading this Helper 16 | =================== 17 | 18 | This helper is loaded using the following code:: 19 | 20 | $this->load->helper('typography'); 21 | 22 | Available Functions 23 | =================== 24 | 25 | The following functions are available: 26 | 27 | 28 | .. php:function:: auto_typography($str[, $reduce_linebreaks = FALSE]) 29 | 30 | :param string $str: Input string 31 | :param bool $reduce_linebreaks: Whether to reduce multiple instances of double newlines to two 32 | :returns: HTML-formatted typography-safe string 33 | :rtype: string 34 | 35 | Formats text so that it is semantically and typographically correct 36 | HTML. 37 | 38 | This function is an alias for ``CI_Typography::auto_typography()``. 39 | For more info, please see the :doc:`Typography Library 40 | <../libraries/typography>` documentation. 41 | 42 | Usage example:: 43 | 44 | $string = auto_typography($string); 45 | 46 | .. note:: Typographic formatting can be processor intensive, particularly if 47 | you have a lot of content being formatted. If you choose to use this 48 | function you may want to consider :doc:`caching <../general/caching>` your 49 | pages. 50 | 51 | 52 | .. php:function:: nl2br_except_pre($str) 53 | 54 | :param string $str: Input string 55 | :returns: String with HTML-formatted line breaks 56 | :rtype: string 57 | 58 | Converts newlines to
tags unless they appear within
 tags.
59 | 	This function is identical to the native PHP ``nl2br()`` function,
60 | 	except that it ignores 
 tags.
61 | 
62 | 	Usage example::
63 | 
64 | 		$string = nl2br_except_pre($string);
65 | 
66 | .. php:function:: entity_decode($str, $charset = NULL)
67 | 
68 | 	:param	string	$str: Input string
69 | 	:param	string	$charset: Character set
70 | 	:returns:	String with decoded HTML entities
71 | 	:rtype:	string
72 | 
73 | 	This function is an alias for ``CI_Security::entity_decode()``.
74 | 	Fore more info, please see the :doc:`Security Library
75 | 	<../libraries/security>` documentation.
76 | 


--------------------------------------------------------------------------------
/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 | Loading this Helper 15 | =================== 16 | 17 | This helper is loaded using the following code 18 | 19 | :: 20 | 21 | $this->load->helper('xml'); 22 | 23 | Available Functions 24 | =================== 25 | 26 | The following functions are available: 27 | 28 | .. php:function:: xml_convert($str[, $protect_all = FALSE]) 29 | 30 | :param string $str: the text string to convert 31 | :param bool $protect_all: Whether to protect all content that looks like a potential entity instead of just numbered entities, e.g. &foo; 32 | :returns: XML-converted string 33 | :rtype: string 34 | 35 | Takes a string as input and converts the following reserved XML 36 | characters to entities: 37 | 38 | - Ampersands: & 39 | - Less than and greater than characters: < > 40 | - Single and double quotes: ' " 41 | - Dashes: - 42 | 43 | This function ignores ampersands if they are part of existing numbered 44 | character entities, e.g. {. Example:: 45 | 46 | $string = '

Here is a paragraph & an entity ({).

'; 47 | $string = xml_convert($string); 48 | echo $string; 49 | 50 | outputs: 51 | 52 | .. code-block:: html 53 | 54 | <p>Here is a paragraph & an entity ({).</p> 55 | -------------------------------------------------------------------------------- /source/images/appflowchart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/appflowchart.gif -------------------------------------------------------------------------------- /source/images/arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/arrow.gif -------------------------------------------------------------------------------- /source/images/ci-icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/ci-icon.ico -------------------------------------------------------------------------------- /source/images/ci_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/ci_logo.jpg -------------------------------------------------------------------------------- /source/images/ci_logo_flame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/ci_logo_flame.jpg -------------------------------------------------------------------------------- /source/images/file.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/file.gif -------------------------------------------------------------------------------- /source/images/folder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/folder.gif -------------------------------------------------------------------------------- /source/images/smile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeIgniter-TW/CodeIgniter-UserGuide/282470ad4c0d53e3ef8e6d8dd334787a2270fc7b/source/images/smile.gif -------------------------------------------------------------------------------- /source/index.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | CodeIgniter 使用手冊 3 | #################### 4 | 5 | - :doc:`許可協議 ` 6 | - :doc:`版本紀錄 ` 7 | 8 | .. contents:: 9 | :local: 10 | :depth: 2 11 | 12 | **** 13 | 歡迎 14 | **** 15 | 16 | .. toctree:: 17 | :titlesonly: 18 | 19 | general/welcome 20 | 21 | ******** 22 | 基本資訊 23 | ******** 24 | 25 | - :doc:`general/requirements` 26 | - :doc:`general/credits` 27 | 28 | **** 29 | 安裝 30 | **** 31 | .. toctree:: 32 | :includehidden: 33 | :maxdepth: 2 34 | :titlesonly: 35 | 36 | installation/index 37 | 38 | **** 39 | 簡介 40 | **** 41 | 42 | .. toctree:: 43 | :titlesonly: 44 | 45 | overview/index 46 | 47 | ******** 48 | 指導手冊 49 | ******** 50 | 51 | .. toctree:: 52 | :includehidden: 53 | :titlesonly: 54 | 55 | tutorial/index 56 | 57 | ******** 58 | 一般主題 59 | ******** 60 | 61 | .. toctree:: 62 | :glob: 63 | :titlesonly: 64 | 65 | general/index 66 | 67 | ******** 68 | 類別參考 69 | ******** 70 | 71 | .. toctree:: 72 | :glob: 73 | :titlesonly: 74 | 75 | libraries/index 76 | 77 | ********** 78 | 資料庫參考 79 | ********** 80 | 81 | .. toctree:: 82 | :glob: 83 | :titlesonly: 84 | 85 | database/index 86 | 87 | ************ 88 | 輔助函式 89 | ************ 90 | 91 | .. toctree:: 92 | :glob: 93 | :titlesonly: 94 | 95 | helpers/index 96 | 97 | **************** 98 | 貢獻 CodeIgniter 99 | **************** 100 | 101 | .. toctree:: 102 | :glob: 103 | :titlesonly: 104 | 105 | contributing/index 106 | 107 | .. toctree:: 108 | :glob: 109 | :titlesonly: 110 | :hidden: 111 | 112 | * 113 | overview/index 114 | general/requirements 115 | general/welcome 116 | installation/index 117 | general/index 118 | libraries/index 119 | database/index 120 | helpers/index 121 | tutorial/index 122 | general/credits 123 | -------------------------------------------------------------------------------- /source/installation/index.rst: -------------------------------------------------------------------------------- 1 | ######################### 2 | 安裝指引 3 | ######################### 4 | 5 | CodeIgniter 安裝分 4 個部份: 6 | 7 | #. 解壓縮下載個安裝包。 8 | #. 上傳 Codeigniter 的目錄以及檔案到你的 Server,一般來說 *index.php* 會在 Server 的根目錄。 9 | #. 用文字編輯器或開發工具打開 *application/config/config.php* 然後設定你的 base URL。如果你想要設定 encryption 或 sessions,那就設定 encryption key。 10 | #. 如果你想要用 database,請打開 *application/config/database.php* 檔案,然後設定你的 database 設定。 11 | 12 | 如果你想要增加安全性以及隱藏 Codeigniter 的目錄位置,你可以重新命名 system 目錄以及 application 目錄。 13 | 如果你重新命名它們,你必須打開根目錄的 *index.php* 檔案然後設定 ``$system_path`` 以及 ``$application_folder`` 變數,改成你所改變目錄的名稱。 14 | 15 | 至於最安全的方法,讓放在 web 根目錄上的 system 以及所有 application 目錄,移動到瀏覽器無法直接存取的位置。 16 | 預設的方法是 *.htaccess* 檔案放在所有的資料夾來避免直接存取,如果 Server 設定不支持 *.htaccess*,那麼最好的方法還是把它們從公開存取的資料夾移走。 17 | 18 | 如果你想要保持你的 views 資料夾公開的,那麼也可能地請把它從 application 資料夾移出。 19 | 20 | 移開它們之後,請到根目錄修改 index.php 檔案以及設定 ``$system_path``、``$application_folder``、``$view_folder`` 變數,最好是完整的路徑,像是'*/www/MyUser/system*'。 21 | 22 | 除此之外一個額外的 production environments(在根目錄的index.php)預設是取消 PHP 錯誤訊息以及取消所有只允許開發者使用的功能。 23 | 可以在 CodeIgniter 中,通過設定 ``ENVIRONMENT`` 變數來達成,這裡有完整的描述 :doc:`security 24 | page <../general/security>`. 25 | 26 | 就這樣! 27 | 28 | 如果你是初學 CodeIgniter,請閱讀 :doc:`Getting 29 | Started <../overview/getting_started>` 章節,來開始學習如何建立一個動態的 PHP 應用程式。享受它吧! 30 | 31 | .. toctree:: 32 | :hidden: 33 | :titlesonly: 34 | 35 | downloads 36 | self 37 | upgrading 38 | troubleshooting 39 | 40 | -------------------------------------------------------------------------------- /source/installation/troubleshooting.rst: -------------------------------------------------------------------------------- 1 | ############### 2 | 故障排除 3 | ############### 4 | 5 | 如果無論如何對不同URL發出請求,你的網頁都在預設頁面讀取了話,有可能你的 Server 不支援 PATH_INFO 變數,它主要是為了增加搜尋引擎友好的 URLs。 6 | 第一步,打開 *application/config/config.php* 檔案然後尋找 URI Protocol 資訊。 7 | 它會建議你修改幾個設定。 如果修改了這些設定還是無法解決,你需要強制 CodeIgniter 去增加『?』到你的 URLs。打開你的 *application/config/config.php* 檔案以及修改它們:: 8 | 9 | $config['index_page'] = "index.php"; 10 | 11 | 改成:: 12 | 13 | $config['index_page'] = "index.php?"; 14 | 15 | -------------------------------------------------------------------------------- /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/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/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_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_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/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_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/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/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_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/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_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_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_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/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_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/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/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_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/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/upgrade_210.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.0.3 to 2.1.0 3 | ############################# 4 | 5 | Before performing an update you should take your site offline by 6 | replacing the index.php file with a static one. 7 | 8 | Step 1: Update your CodeIgniter files 9 | ===================================== 10 | 11 | Replace all files and directories in your "system" folder. 12 | 13 | .. note:: If you have any custom developed files in these folders please 14 | make copies of them first. 15 | 16 | Step 2: Replace config/user_agents.php 17 | ====================================== 18 | 19 | This config file has been updated to contain more user agent types, 20 | please copy it to *application/config/user_agents.php*. 21 | 22 | Step 3: Update your user guide 23 | ============================== 24 | 25 | Please also replace your local copy of the user guide with the new 26 | version. 27 | -------------------------------------------------------------------------------- /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 32 | -------------------------------------------------------------------------------- /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. 21 | -------------------------------------------------------------------------------- /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. 21 | -------------------------------------------------------------------------------- /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. 15 | -------------------------------------------------------------------------------- /source/installation/upgrade_220.rst: -------------------------------------------------------------------------------- 1 | ############################# 2 | Upgrading from 2.1.4 to 2.2.0 3 | ############################# 4 | 5 | .. note:: The :doc:`Encrypt Class ` now requires the 6 | Mcrypt extension. If you were previously using the Encrypt Class 7 | without Mcrypt, then this is a breaking change. You must install 8 | the Mcrypt extension in order to upgrade. For information on 9 | installing Mcrypt please see the PHP `documentation 10 | `. 11 | 12 | Before performing an update you should take your site offline by 13 | replacing the index.php file with a static one. 14 | 15 | Step 1: Update your CodeIgniter files 16 | ===================================== 17 | 18 | Replace all files and directories in your "system" folder. 19 | 20 | .. note:: If you have any custom developed files in these folders please 21 | make copies of them first. 22 | -------------------------------------------------------------------------------- /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. 15 | -------------------------------------------------------------------------------- /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. 15 | -------------------------------------------------------------------------------- /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. 15 | -------------------------------------------------------------------------------- /source/installation/upgrade_301.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.0.0 升級到 3.0.1 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1: 更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案。 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2: 更新你的 CLI 錯誤訊息樣板 15 | ================================= 16 | 17 | 取代所有 *application/views/errors/cli/* 目錄底下的所有檔案。 18 | -------------------------------------------------------------------------------- /source/installation/upgrade_302.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.0.1 升級到 3.0.2 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1: 更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案。 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2: 更新 application/config/constants.php 檔案 15 | ========================================================= 16 | 17 | *application/config/constants.php* 檔案已經更新。 18 | 在定義常數之前檢查是否經被定義,讓你更容易為特定的環境定義常數。 19 | 20 | .. 注意:: 假如您有修改此檔案,麻煩請先複製備份,並逐行檢查差異。 -------------------------------------------------------------------------------- /source/installation/upgrade_303.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.0.2 升級到 3.0.3 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1: 更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案。 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2: 確定你的 'base_url' 設定值不是空的 15 | ========================================== 16 | 17 | 當 ``$config['base_url']`` 未設定,CodeIgniter 將會嘗試的辨識你的網站網址是什麼。 18 | 這麼做單純的只是為了你在開發一個全新的應用的時候,可以很方便的開始。 19 | 20 | 自動偵測是一個很不可靠的方式,而且有安全性的隱憂。 21 | 這就是為什麼你 **始終應該** 手動的設定! 22 | 23 | CodeIgniter 3.0.3 的其中一個改變,就是如何自動化的辨識。 24 | 具體的說,將使用伺服器的 IP 位置取代原本由瀏覽器的請求網域名稱的作法。 25 | 因此,如果你原本是依靠自動偵測來設定,這將完全改變你網站的運作方式。 26 | 27 | 如果你需要允許多個網域名稱,例如 http:// 和 https:// 同時動態的根據請求來使用。 28 | *application/config/config.php* 依然是一個 PHP 檔案。 29 | 你可以用幾行的程式碼來建立一個動態設定的邏輯,例如:: 30 | 31 | $allowed_domains = array('domain1.tld', 'domain2.tld'); 32 | $default_domain = 'domain1.tld'; 33 | 34 | if (in_array($_SERVER['HTTP_HOST'], $allowed_domains, TRUE)) 35 | { 36 | $domain = $_SERVER['HTTP_HOST']; 37 | } 38 | else 39 | { 40 | $domain = $default_domain; 41 | } 42 | 43 | if ( ! empty($_SERVER['HTTPS'])) 44 | { 45 | $config['base_url'] = 'https://'.$domain; 46 | } 47 | else 48 | { 49 | $config['base_url'] = 'http://'.$domain; 50 | } -------------------------------------------------------------------------------- /source/installation/upgrade_304.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.0.3 升級到 3.0.4 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1: 更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案。 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | -------------------------------------------------------------------------------- /source/installation/upgrade_305.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.0.4 升級到 3.0.5 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1: 更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | -------------------------------------------------------------------------------- /source/installation/upgrade_306.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.0.5 升級到 3.0.6 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2:更新 index.php 檔案 (選擇性的) 15 | ============================================= 16 | 17 | We've made some tweaks to the index.php file, mostly related to proper 18 | usage of directory separators (i.e. use the ``DIRECTORY_SEPARATOR`` 19 | constant instead of a hard coded forward slash "/"). 20 | 21 | Nothing will break if you skip this step, but if you're running Windows 22 | or just want to be up to date with every change - we do recommend that 23 | you update your index.php file. 24 | 25 | *Tip: Just copy the ``ENVIRONMENT``, ``$system_path``, ``$application_folder`` 26 | and ``$view_folder`` declarations from the old file and put them into the 27 | new one, replacing the defaults.* 28 | 29 | 步驟 3:移除 'prep_for_form' 的使用 (強烈建議) 30 | ============================================== 31 | 32 | The :doc:`Form Validation Library <../libraries/form_validation>` has a 33 | ``prep_for_form()`` method, which is/can also be used as a rule in 34 | ``set_rules()`` to automatically perform HTML encoding on input data. 35 | 36 | Automatically encoding input (instead of output) data is a bad practice in 37 | the first place, and CodeIgniter and PHP itself offer other alternatives 38 | to this method anyway. 39 | For example, :doc:`Form Helper <../helpers/form_helper>` functions will 40 | automatically perform HTML escaping when necessary. 41 | 42 | 因此, *prep_for_form* 模組/規則 幾乎是沒有用處的,並將於 3.1 之後的版本將其移除。 43 | 44 | .. 注意:: 這方法依然可以使用,但我們強烈建議你盡快刪除這方法的使用。 45 | -------------------------------------------------------------------------------- /source/installation/upgrade_310.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.0.6 升級到 3.1.0 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2: 檢查你的 PHP 版本 15 | ========================= 16 | 17 | We recommend always running versions that are `currently supported 18 | `_, which right now is at least PHP 5.6. 19 | 20 | PHP 5.2.x versions are now officially not supported by CodeIgniter, and while 5.3.7+ 21 | may be at least runnable, we strongly discourage you from using any PHP versions below 22 | the ones listed on the `PHP.net Supported Versions `_ 23 | page. 24 | 25 | 步驟 3: If you're using the 'odbc' database driver, check for usage of Query Builder 26 | ==================================================================================== 27 | 28 | :doc:`Query Builder <../database/query_builder>` functionality and ``escape()`` can 29 | no longer be used with the 'odbc' database driver. 30 | 31 | This is because, due to its nature, the `ODBC extension for PHP `_ 32 | does not provide a function that allows to safely escape user-supplied strings for usage 33 | inside an SQL query (which our :doc:`Query Builder <../database/query_builder>` relies on). 34 | 35 | Thus, user inputs MUST be bound, as shown in :doc:`Running Queries <../database/queries>`, 36 | under the "Query Bindings" section. 37 | -------------------------------------------------------------------------------- /source/installation/upgrade_311.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.1.0 升級到 3.1.1 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 注意:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | -------------------------------------------------------------------------------- /source/installation/upgrade_312.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.1.1 升級到 3.1.2 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 提醒:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2: 更新 "ci_sessions" 資料表 15 | ================================= 16 | 17 | If you're using the :doc:`Session Library ` with the 18 | 'database' driver, you may have to ``ALTER`` your sessions table for your 19 | sessions to continue to work. 20 | 21 | .. note:: The table in question is not necessarily named "ci_sessions". 22 | It is what you've set as your ``$config['sess_save_path']``. 23 | 24 | This will only affect you if you've changed your ``session.hash_function`` 25 | *php.ini* setting to something like 'sha512'. Or if you've been running 26 | an older CodeIgniter version on PHP 7.1+. 27 | 28 | It is recommended that you do this anyway, just to avoid potential issues 29 | in the future if you do change your configuration. 30 | 31 | Just execute the one of the following SQL queries, depending on your 32 | database:: 33 | 34 | // MySQL: 35 | ALTER TABLE ci_sessions CHANGE id id varchar(128) NOT NULL; 36 | 37 | // PostgreSQL 38 | ALTER TABLE ci_sessions ALTER COLUMN id SET DATA TYPE varchar(128); 39 | -------------------------------------------------------------------------------- /source/installation/upgrade_313.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.1.2 升級到 3.1.3 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 提醒:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2: 移除輔助函式 nice_date() 的使用 (deprecation) 15 | ===================================================== 16 | 17 | The :doc:`Date Helper <../helpers/date_helper>` function ``nice_date()`` is 18 | no longer useful since the introduction of PHP's `DateTime classes 19 | `_ 20 | 21 | You can replace it with the following: 22 | :: 23 | 24 | DateTime::createFromFormat($input_format, $input_date)->format($desired_output_format); 25 | 26 | Thus, ``nice_date()`` is now deprecated and scheduled for removal in 27 | CodeIgniter 3.2+. 28 | 29 | .. 提醒:: The function is still available, but you're strongly encouraged 30 | to remove its usage sooner rather than later. 31 | 32 | 步驟 3: 移除 $config['standardize_newlines'] 的使用 33 | =================================================== 34 | 35 | The :doc:`Input Library <../libraries/input>` would optionally replace 36 | occurrences of `\r\n`, `\r`, `\n` in input data with whatever the ``PHP_EOL`` 37 | value is on your system - if you've set ``$config['standardize_newlines']`` 38 | to ``TRUE`` in your *application/config/config.php*. 39 | 40 | This functionality is now deprecated and scheduled for removal in 41 | CodeIgniter 3.2.+. 42 | 43 | .. 提醒:: The functionality is still available, but you're strongly 44 | encouraged to remove its usage sooner rather than later. 45 | -------------------------------------------------------------------------------- /source/installation/upgrade_314.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.1.3 升級到 3.1.4 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 提醒:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | -------------------------------------------------------------------------------- /source/installation/upgrade_315.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.1.4 升級到 3.1.5 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 提醒:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | -------------------------------------------------------------------------------- /source/installation/upgrade_316.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | 從 3.1.5 升級到 3.1.6 3 | ##################### 4 | 5 | 在執行升級之前,你應該更換 index.php 為靜態檔案,將網站導向此靜態網頁。 6 | 7 | 步驟 1:更新網站 CodeIgniter 檔案 8 | ================================= 9 | 10 | 取代 *system/* 目錄打下的所有目錄與檔案 11 | 12 | .. 提醒:: 假如您有修改此目錄底下的檔案,麻煩請先複製備份。 13 | 14 | 步驟 2: Remove usage of the APC Cache driver (deprecation) 15 | ========================================================== 16 | 17 | The :doc:`Cache Library <../libraries/caching>` APC driver is now 18 | deprecated, as the APC extension is effectively dead, as explained in its 19 | `PHP Manual page `_. 20 | 21 | If your application happens to be using it, you can switch to another 22 | cache driver, as APC support will be removed in a future CodeIgniter 23 | version. 24 | 25 | .. 提醒:: The driver is still available, but you're strongly encouraged 26 | to remove its usage sooner rather than later. 27 | -------------------------------------------------------------------------------- /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/installation/upgrading.rst: -------------------------------------------------------------------------------- 1 | ################################# 2 | 從先前的版本來更新 3 | ################################# 4 | 5 | 請仔細閱讀與您從各個相對應的版本升級說明。 6 | 7 | .. toctree:: 8 | :titlesonly: 9 | 10 | 從 3.1.5 升級到 3.1.6 11 | 從 3.1.4 升級到 3.1.5 12 | 從 3.1.3 升級到 3.1.4 13 | 從 3.1.2 升級到 3.1.3 14 | 從 3.1.1 升級到 3.1.2 15 | 從 3.1.0 升級到 3.1.1 16 | 從 3.0.6 升級到 3.1.0 17 | 從 3.0.5 升級到 3.0.6 18 | 從 3.0.4 升級到 3.0.5 19 | 從 3.0.3 升級到 3.0.4 20 | 從 3.0.2 升級到 3.0.3 21 | 從 3.0.1 升級到 3.0.2 22 | 從 3.0.0 升級到 3.0.1 23 | 從 2.2.x 升級到 3.0.0 24 | 從 2.2.2 升級到 2.2.3 25 | 從 2.2.1 升級到 2.2.2 26 | 從 2.2.0 升級到 2.2.1 27 | 從 2.1.4 升級到 2.2.0 28 | 從 2.1.3 升級到 2.1.4 29 | 從 2.1.2 升級到 2.1.3 30 | 從 2.1.1 升級到 2.1.2 31 | 從 2.1.0 升級到 2.1.1 32 | 從 2.0.3 升級到 2.1.0 33 | 從 2.0.2 升級到 2.0.3 34 | 從 2.0.1 升級到 2.0.2 35 | 從 2.0 升級到 2.0.1 36 | 從 1.7.2 升級到 2.0 37 | 從 1.7.1 升級到 1.7.2 38 | 從 1.7.0 升級到 1.7.1 39 | 從 1.6.3 升級到 1.7.0 40 | 從 1.6.2 升級到 1.6.3 41 | 從 1.6.1 升級到 1.6.2 42 | 從 1.6.0 升級到 1.6.1 43 | 從 1.5.4 升級到 1.6.0 44 | 從 1.5.3 升級到 1.5.4 45 | 從 1.5.2 升級到 1.5.3 46 | 從 1.5.0 或 1.5.1 升級到 1.5.2 47 | 從 1.4.1 升級到 1.5.0 48 | 從 1.4.0 升級到 1.4.1 49 | 從 1.3.3 升級到 1.4.0 50 | 從 1.3.2 升級到 1.3.3 51 | 從 1.3.1 升級到 1.3.2 52 | 從 1.3 升級到 1.3.1 53 | 從 1.2 升級到 1.3 54 | 從 1.1 升級到 1.2 55 | 從 Beta 1.0 升級到 Beta 1.1 56 | -------------------------------------------------------------------------------- /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 | 效能測試類別可用於 24 | :doc:`controllers `, 25 | :doc:`views `, 或是你的 :doc:`models `. 26 | 使用的順序為: 27 | 28 | #. 標記一個起始點 29 | #. 標記一個結束點 30 | #. 執行 "elapsed time" 函數取得執行時間 31 | 32 | 範例: 33 | 34 | $this->benchmark->mark('code_start'); 35 | 36 | // 程式碼於這裡執行 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 | // 程式碼於這裡執行 49 | 50 | $this->benchmark->mark('cat'); 51 | 52 | // 更多程式碼於這裡執行 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:`Profiler ` 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:`Profiler page ` 獲得更多資訊 81 | 82 | 顯示總執行時間 83 | =============================== 84 | 85 | 如果你希望顯示Codeigniter從開始執行到顯示頁面的時間,只要在樣板中放入以下程式碼:: 86 | 87 | benchmark->elapsed_time();?> 88 | 89 | 你會注意到這是和上一個範例中相同的函數,除了 **沒有** 使用任何參數。 90 | 當參數為空時,不管你在哪裡執行這個函數,直到顯示頁面前Codeigniter不會停止效能測試 91 | 92 | 如果你不喜歡使用純PHP,另一個顯示執行時間的方法為使用虛擬變數:: 93 | 94 | {elapsed_time} 95 | 96 | .. note:: 如果你想要測試controller中的效能,你就必須設置自己的起始/結束標記點 97 | 98 | 顯示記憶體用量 99 | ============================= 100 | 101 | 如果你的PHP在安裝時有開啟--enable-memory-limit,你就可以使用下面的程式碼顯示記憶體用量:: 102 | 103 | benchmark->memory_usage();?> 104 | 105 | .. note:: 這個函數只能在view files中使用。記憶體用量會反應整個應用程式的使用量。 106 | 107 | 如果你不喜歡使用純PHP,另一個顯示記憶體用量的方法為使用虛擬變數:: 108 | 109 | {memory_usage} 110 | 111 | 112 | *************** 113 | 類別參考 114 | *************** 115 | 116 | .. php:class:: CI_Benchmark 117 | 118 | .. php:method:: mark($name) 119 | 120 | :param string $name: 標記名稱 121 | :rtype: void 122 | 123 | 設置標記 124 | 125 | .. php:method:: elapsed_time([$point1 = ''[, $point2 = ''[, $decimals = 4]]]) 126 | 127 | :param string $point1: 起始標記名稱 128 | :param string $point2: 結束標記名稱 129 | :param int $decimals: 小數點位數 130 | :returns: 經過的時間 131 | :rtype: string 132 | 133 | 計算並回傳兩個標記點間的執行時間。 134 | 135 | 如果第一個參數為空,這個函數會回傳 ``{elapsed_time}`` 虛擬函數。這讓完整的系統執行時間能在樣板中顯示。 136 | The output class will swap the real value for this variable. 137 | 138 | 139 | .. php:method:: memory_usage() 140 | 141 | :returns: 記憶體用量資訊 142 | :rtype: string 143 | 144 | 回傳 ``{memory_usage}`` 145 | 146 | This permits it to be put it anywhere in a template without the memory 147 | being calculated until the end. The :doc:`Output Class ` will 148 | swap the real value for this variable. 149 | -------------------------------------------------------------------------------- /source/libraries/index.rst: -------------------------------------------------------------------------------- 1 | ######### 2 | Libraries 3 | ######### 4 | 5 | .. toctree:: 6 | :glob: 7 | :titlesonly: 8 | 9 | * 10 | -------------------------------------------------------------------------------- /source/libraries/typography.rst: -------------------------------------------------------------------------------- 1 | ################ 2 | Typography 類別 3 | ################ 4 | 5 | Typography 類別可以幫忙你處理文字的格式。 6 | 7 | .. contents:: 8 | :local: 9 | 10 | .. raw:: html 11 | 12 |
13 | 14 | ************************** 15 | 使用 Typography 類別 16 | ************************** 17 | 18 | 初始化類別 19 | ====================== 20 | 21 | 就像 CodeIgniter 其它多數類別一樣, 22 | Typography 類別可以在你的 controller 內透過 ``$this->load->library()`` 函式來初始化:: 23 | 24 | $this->load->library('typography'); 25 | 26 | 載入之後,就可以這樣取得 Typography 物件:: 27 | 28 | $this->typography 29 | 30 | *************** 31 | 類別參考 32 | *************** 33 | 34 | .. php:class:: CI_Typography 35 | 36 | .. attribute:: $protect_braced_quotes = FALSE 37 | 38 | 當 Typography 與 :doc:`Template Parser library ` 搭配使用時, 39 | 通常會需要保護大括號內的單引號與雙引號不被改變。 40 | 要啟用這個功能,將 ``protect_braced_quotes`` 屬性設定為 TRUE。 41 | 42 | 使用範例:: 43 | 44 | $this->load->library('typography'); 45 | $this->typography->protect_braced_quotes = TRUE; 46 | 47 | .. php:method:: auto_typography($str[, $reduce_linebreaks = FALSE]) 48 | 49 | :param string $str: 輸入字串 50 | :param bool $reduce_linebreaks: 是否縮減連續的換行 51 | :returns: 可安全用在 HTML 排版的字串 52 | :rtype: string 53 | 54 | 將文字格式化成語意與排版正確的 HTML。 55 | 輸入一個字串,並套用下列的規則處理後回傳: 56 | 57 | - 在段落前後加上

(使用兩個換行來標示段落)。 58 | - 換行被轉換為
,除了出現在
 標籤內的以外。
 59 | 		 -  區塊元素,像是 
標籤,不會被放進段落中,但是若其內容文字含有段落,則內容文字會被放進段落裡。 60 | - 引號會被轉換成對應的印刷體(curly)引號,除了出現在 HTML 標籤中的以外。 61 | - 撇號被轉換為印刷體撇號。 62 | - 兩個連字號(不管是 這 -- 樣 或 這--樣)會被轉換為破折號。 63 | - 單字前面或後面的三個連續句號被轉換為省略號。 64 | - 跟在句子後的兩個空白字元會被轉換為不斷行空白(non-breaking spaces)來模擬兩個空白。 65 | 66 | 使用範例:: 67 | 68 | $string = $this->typography->auto_typography($string); 69 | 70 | 這邊有一個選擇性的參數,可以決定是否要將兩個以上的連續換行縮減為兩個。 71 | 傳入布林值 TRUE 來啟用這個功能:: 72 | 73 | $string = $this->typography->auto_typography($string, TRUE); 74 | 75 | .. note:: 文字排版可以用掉很多處理器資源,尤其是要處理的內容很多的時候。 76 | 如果你決定要這麼做,你可能也會考慮 :doc:`快取 <../general/caching>` 你的頁面。 77 | 78 | .. php:method:: format_characters($str) 79 | 80 | :param string $str: 輸入字串 81 | :returns: 格式化的字串 82 | :rtype: string 83 | 84 | 這個方法類似上面的 ``auto_typography()`` ,差別是只做字元轉換: 85 | 86 | - 引號會被轉換成對應的印刷體(curly)引號,除了出現在 HTML 標籤中的以外。 87 | - 撇號被轉換為印刷體撇號。 88 | - 兩個連字號(不管是 這 -- 樣 或 這--樣)會被轉換為破折號。 89 | - 單字前面或後面的三個連續句號被轉換為省略號。 90 | - 跟在句子後的兩個空白字元會被轉換為不斷行空白(non-breaking spaces)來模擬兩個空白。 91 | 92 | 使用範例:: 93 | 94 | $string = $this->typography->format_characters($string); 95 | 96 | .. php:method:: nl2br_except_pre($str) 97 | 98 | :param string $str: 輸入字串 99 | :returns: 格式化的字串 100 | :rtype: string 101 | 102 | 將換行轉換為
標籤,除非其位於
 標籤內。
103 | 		這個方法與 PHP 原生的 :php:func:`nl2br()` 函式相等,但是 nl2br() 會忽略 
 標籤。
104 | 
105 | 		使用範例::
106 | 
107 | 			$string = $this->typography->nl2br_except_pre($string);
108 | 


--------------------------------------------------------------------------------
/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 | 


--------------------------------------------------------------------------------
/source/overview/appflow.rst:
--------------------------------------------------------------------------------
 1 | ######################
 2 | 應用程式溝通流程
 3 | ######################
 4 | 
 5 | 根據圖片指示,來了解資料在系統中是如何跑的:
 6 | 
 7 | |CodeIgniter application flow|
 8 | 
 9 | #. index.php 檔案是最一開始的 controller,初始化 Codeigniter 基礎資源。
10 | #. Router 解釋 HTTP 請求 去找到這個請求該往哪裡走。
11 | #. 如果 cache 檔案存在,將會直接通過一般系統執行回傳給瀏覽器資料。
12 | #. Security。在傳給 application controller 讀取之前,HTTP 請求以及所有使用者送出的資料會通過它來過濾。
13 | #. Controller 載入 model、core libraries、helpers、以及程式需要的所有特殊資源。
14 | #. 最後 View 是最終的呈現結果,來送回給瀏覽器。如果快取是啟動的,view 會在第一次快取一份,之後使用者在發 HTTP 請求的時候,就會直接回傳這份快取,不需要再通過 Router 了。
15 | 
16 | .. |CodeIgniter application flow| image:: ../images/appflowchart.gif
17 | 


--------------------------------------------------------------------------------
/source/overview/at_a_glance.rst:
--------------------------------------------------------------------------------
 1 | #######################
 2 | CodeIgniter 一目了然
 3 | #######################
 4 | 
 5 | CodeIgniter 是網站應用程式框架
 6 | =======================================
 7 | 
 8 | CodeIgniter 網站應用程式框架 - 給運用PHP開發網站工程師的一個工具。它的目使你在開發專案時需要使用一般功能時,它提供一群豐富的函式庫以及函式庫介面和存取函式庫的邏輯結構,使你在開發一般功能時比從頭造輪子還快許多。 CodeIgniter 讓你專注於專案之上,使你寫出最小化的程式碼達到需要的功能。
 9 | 
10 | CodeIgniter 是免費的
11 | ===================
12 | 
13 | CodeIgniter 是授權在 Apache/BSD-style 開放原始碼 license 你可以盡情地使用它。想要知道更多資訊請閱讀 :doc:`license agreement <../license>` 。
14 | 
15 | CodeIgniter 是輕量的
16 | ===========================
17 | 
18 | 真的很輕量。核心系統只需有幾個非常小的 Library。與現今需要大量資源的 Framework 相比。除此之外函式庫是根據需求才會讀取進來的,所以基礎系統是非常小且快速。
19 | 
20 | CodeIgniter 是快速的
21 | ===================
22 | 
23 | 真的超快。我們跟你挑戰,你絕對找不到比 Codeigniter 還快的 Framework。
24 | 
25 | CodeIgniter 使用 M-V-C 架構
26 | ======================
27 | 
28 | CodeIgniter 使用 Model-View-Controller 架構,這讓你把邏輯、呈現很好的分開。設計師在設計你的模板檔案,可以達到最小化的程式碼,這是非常好的架構。
29 | 
30 | CodeIgniter 創造出簡潔的 URL
31 | ================================
32 | 
33 | 創造出簡潔、對搜尋引擎友善的 URLs。而不是運用標準的 “query string” 達到同義詞動態系統的 URLs,CodeIgniter 運用分段來完成。::
34 | 
35 | 	example.com/news/article/345
36 | 
37 | .. note:: 預設 *index.php* 字串是包含在 URL 裡面的 (example.com/index.php/news/article/345),但是這個字串可以被省略掉,通過 *.htaccess* 檔案設定。
38 | 
39 | CodeIgniter 全力一擊
40 | =========================
41 | 
42 | CodeIgniter 是全能的函式庫,它可以使你完成大部分的網頁開發任務,像是存取資料庫,傳送信件,表單驗證,維持session,操作圖片,操作 XML-RPC 資料甚至更多功能。
43 | 
44 | CodeIgniter 是可擴展的
45 | =========================
46 | 
47 | 系統可以被簡單的擴展,只要通過我們的 libraries、 helpers 或者通過 Class Extensions 或 System Hooks。
48 | 
49 | CodeIgniter 不需要模板引擎
50 | ==============================================
51 | 
52 | 雖然 CodeIgniter *可以* 使用簡單的模板解析器,不過這些是可選的,我們不強迫你使用它。模板引擎根本無法比擬原生的PHP性能,而且模板語言往往都難過學習PHP語言的基礎。來看看這段 PHP code::
53 | 
54 | 	
    55 | 56 |
  • 57 | 58 |
59 | 60 | 來比較使用虛擬碼的模板語言:: 61 | 62 |
    63 | {foreach from=$addressbook item="name"} 64 |
  • {$name}
  • 65 | {/foreach} 66 |
67 | 68 | 沒錯,樣板語言解析稍微簡潔一點,但是它需要花額外的效能去解析虛擬碼回 PHP 來執行。所以我們其一的目標就是 *最佳化* 性能,我們選擇不需要使用模板語言。 69 | 70 | CodeIgniter 是完全文件化的 71 | ==================================== 72 | 73 | 工程師喜歡寫程式碼,討厭寫文件。我們不一樣,為什麼這麼說呢,因為文件是 **非常重要** 的對程式碼來說,我們致力於把它做好。因此我們的原始碼是非常簡潔的且有良好的註解。 74 | 75 | CodeIgniter 有很友善的社群使用者 76 | ============================================= 77 | 78 | 我們正在成長的社群有積極參與的夥伴們 79 | `Community Forums `_. 80 | -------------------------------------------------------------------------------- /source/overview/features.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | CodeIgniter 特色 3 | #################### 4 | 5 | 僅僅觀看特色功能是無法得知使用者體驗好壞,應用在設計上直覺跟聰明的地方。同時你也不會知道程式碼的品質、效能、細膩度以及安全性。判斷一個程式好壞的不二法門就是親身去體驗跟了解當中的乾坤。因此我們鼓勵你去 6 | `Installing <../installation/>`_ 它。同時,以下為 CodeIgniter 一些主要特色。 7 | 8 | - Model-View-Controller Based System 9 | - Extremely Light Weight 10 | - Full Featured database classes with support for several platforms. 11 | - Query Builder Database Support 12 | - Form and Data Validation 13 | - Security and XSS Filtering 14 | - Session Management 15 | - Email Sending Class. Supports Attachments, HTML/Text email, multiple 16 | protocols (sendmail, SMTP, and Mail) and more. 17 | - Image Manipulation Library (cropping, resizing, rotating, etc.). 18 | Supports GD, ImageMagick, and NetPBM 19 | - File Uploading Class 20 | - FTP Class 21 | - Localization 22 | - Pagination 23 | - Data Encryption 24 | - Benchmarking 25 | - Full Page Caching 26 | - Error Logging 27 | - Application Profiling 28 | - Calendaring Class 29 | - User Agent Class 30 | - Zip Encoding Class 31 | - Template Engine Class 32 | - Trackback Class 33 | - XML-RPC Library 34 | - Unit Testing Class 35 | - Search-engine Friendly URLs 36 | - Flexible URI Routing 37 | - Support for Hooks and Class Extensions 38 | - Large library of "helper" functions 39 | 40 | -------------------------------------------------------------------------------- /source/overview/getting_started.rst: -------------------------------------------------------------------------------- 1 | ################################ 2 | 開始 CodeIgniter 3 | ################################ 4 | 5 | 所有的軟體應用程式開發都需要努力的學習。我們已經在學習的路徑在,最小化的降低了學習門檻。 6 | 7 | 第一步是 :doc:`安裝 <../installation/index>` CodeIgniter,然後從 **Introduction** 章節開始,閱讀所有的主題。 8 | 9 | 下一步,有順序的閱讀所有的 **General Topics** 每一個主題都是由前一個主題而來,以及包含程式碼的解釋,這些都是鼓勵你去嘗試的唷。 10 | 11 | 一旦你了解基礎的主題,就可以進到下一步來探索 **類別參考文件** 以及 **輔助函式參考文件** 頁面去學習利用原生函式庫以及輔助函式的檔案。 12 | 13 | 隨時利用我們的論壇 `Community 14 | Forums `_ 如果你有任何問題,以及我們的 `Wiki `_ 去看其他工程是發布出來的程式碼解釋。 15 | -------------------------------------------------------------------------------- /source/overview/goals.rst: -------------------------------------------------------------------------------- 1 | ############################## 2 | 設計以及架構目標 3 | ############################## 4 | 5 | CodeIgniter 的目標是最高性能、能力最強、最可擴展的、以及最簡潔、盡可能最輕量的封裝。 6 | 7 | 為了達到這個目標,我們承諾去評測、重新分解,並簡化在開發過程中的每一步,拒絕任何無法進一步了解的目標。 8 | 9 | 從技術以及架構的角度來看,CodeIgniter 被創造出來是根據下列幾個目標: 10 | 11 | - **動態實例化.** 在 CodeIgniter 中,元件只有當被請求的時候才會載入以及執行,而不是全部被載入。事實上,根據系統是由需要超過最小的資源核心所組成,所以我們預設這個系統是非常輕量化的。事件通過 HTTP 請求來觸發,然後設計將會依照你所決定的呼叫不同的 controllers 以及 views 。 12 | - **鬆散耦合.** 耦合是指系統元件相互依賴的程度。相互依賴的元件很少,大部分都可以重用且非常靈活。我們的目標是非常鬆散的耦合系統。 13 | - **元件單一性.** 單一性是元件有狹隘的用途的程度。在 CodeIgniter 中,每個類別以及它的功能是高度自主的,以便達到最大的效用。 14 | 15 | CodeIgniter 動態實例化,鬆散耦合系統以及高元件單一性。它力求簡便性,靈活性,和高性能輕量封裝。 16 | -------------------------------------------------------------------------------- /source/overview/index.rst: -------------------------------------------------------------------------------- 1 | #################### 2 | CodeIgniter 概觀 3 | #################### 4 | 5 | 我們會根據以下頁面廣泛的描述 CodeIgniter: 6 | 7 | .. toctree:: 8 | :titlesonly: 9 | 10 | 開始 CodeIgniter 11 | CodeIgniter 一目了然 12 | CodeIgniter 特色 13 | 應用程式溝通流程 14 | Model-View-Controller 15 | 設計以及架構目標 16 | -------------------------------------------------------------------------------- /source/overview/mvc.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | Model-View-Controller 3 | ##################### 4 | 5 | CodeIgniter 是基於 Model-View-Controller 開發的設計模式。 MVC 是軟體開發的方向,它把應用程式的邏輯從 Presentation 中分離出來。實際上,它允許你在網頁上包含最小化的程式碼,因為 Presentation 是從PHP腳本中分離出來的。 6 | 7 | - **Model** 代表你的資料結構。簡單來說你的 model 類別將會包含很多方法,可以幫助你 retrieve、insert、update 資料到你的資料庫。 8 | - **View** 是網站資訊,它是主要呈現給使用者看的結果。一個 View 一般可以只是 Web Page,但是在 CodeIgniter,View 也可以當成 Page Fragment 像是 header 或是 footer。它也可以做成 RSS Page,或者所有其他形式的 “page”。 9 | - **Controller** 視為 *中介* 在 Model 和 View 之間,所有 HTTP 請求的資源需求以及處理,或是產出一個網頁都是通過它。 10 | 11 | CodeIgniter 有一個相當寬鬆的途徑在 MVC 在架構上,因為 Models 不是必要的。如果你不需要增加分離,或者在維護模式底下你不需要更多複雜的操作,你可以忽略 Model 然後最小化地建置出你的 Application 只用到 Controllers 以及 Views。 CodeIgniter 使你能夠去改善你現存的程式,甚至開發系統核心函式庫,使你在工作上對你自己更有 sense。 12 | -------------------------------------------------------------------------------- /source/tutorial/conclusion.rst: -------------------------------------------------------------------------------- 1 | ########## 2 | 結論 3 | ########## 4 | 5 | 這篇教學無法涵蓋一個完整的內容管理系統所需要的東西,但是它介紹了更重要的主題:路由、控制器與模型。我們希望這篇教學可以使你洞察一些 CodeIgniter 的基本設計模式,並讓你可以在這基礎上進行擴展。 6 | 7 | 現在你已經完成了這個教學,我們建議你看一看手冊的其它部份。CodeIgniter 常常因為擁有完整的文件而被稱讚。你可以好好的利用這個優勢,完整的閱讀“簡介”與“一般主題”。 當有需要時,你也應該閱讀類別參考與補助函式參考。 8 | 9 | 任何一個中階的 PHP 開發者應該都能夠在幾天內掌握使用 CodeIgniter 的訣竅。 10 | 11 | 如果你對於 CodeIgniter 框架或是對於你的 CodeIgniter 程式有問題,你可以在這邊尋求協助: 12 | 13 | - Check out our `forums `_ 14 | - Visit our `IRC chatroom `_ 15 | - Explore the `Wiki `_ 16 | 17 | -------------------------------------------------------------------------------- /source/tutorial/create_news_items.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | 動態新增新聞 3 | ################# 4 | 5 | 你現在知道如何使用 CodeIgniter 從資料庫中讀取資料,但資料庫中尚未寫入任何資訊。 6 | 在這一章節你將會擴充你先前做的 news 控制器及模型來增加這個功能。 7 | 8 | 建立一個表單 9 | ------------- 10 | 11 | 為了要輸入資料到資料庫當中,你需要建立一個表單讓你可以輸入要儲存的資訊。 12 | 這代表你需要一個有兩個欄位的表單,一個用來輸入標題,另一個輸入內文。 13 | 你將會在模型中將標題製成 slug,現在到 *application/views/news/create.php* 建立新的檢視。 14 | 15 | :: 16 | 17 |

18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 裡面只有兩個東西你可能不熟悉:``form_open()`` 函式以及 ``validation_errors()`` 函式。 34 | 35 | 第一個函式是由 `Form 36 | 輔助函式 <../helpers/form_helper.html>`_ 所提供的,它將會顯示表單元素並增加一些額外功能。 37 | 例如增加一個隱藏的 `CSRF 預防欄位 <../libraries/security.html>`_ 。第二個函式則是當表單驗證錯誤時,用來顯示錯誤訊息。 38 | 39 | 回到你的 news 控制器。在這邊你將要做兩件事情,檢查是否有表單被送出,以及送出的資料是否通過驗證規則。 40 | 我們將使用 `Form 驗證 <../libraries/form_validation.html>`_ 程式庫來做這件事。 41 | 42 | :: 43 | 44 | public function create() 45 | { 46 | $this->load->helper('form'); 47 | $this->load->library('form_validation'); 48 | 49 | $data['title'] = 'Create a news item'; 50 | 51 | $this->form_validation->set_rules('title', 'Title', 'required'); 52 | $this->form_validation->set_rules('text', 'text', 'required'); 53 | 54 | if ($this->form_validation->run() === FALSE) 55 | { 56 | $this->load->view('templates/header', $data); 57 | $this->load->view('news/create'); 58 | $this->load->view('templates/footer'); 59 | 60 | } 61 | else 62 | { 63 | $this->news_model->set_news(); 64 | $this->load->view('news/success'); 65 | } 66 | } 67 | 68 | 上面這段程式增加了許多功能。 69 | 開頭前幾行用來載入 Form 輔助函式以及 Form Validation 程式庫。 70 | 接著是設定表單驗證的規則。 71 | ``set_rules()`` 方法需要三個參數,輸入欄位的名稱,用來顯示在錯誤訊息中的名稱,以及規則。 72 | 在這個例子中使用的規則,用來表示標題及內文都是必要的欄位。 73 | 74 | 如上面的範例, CodeIgniter 有一個強力的表單驗證程式庫。 75 | 你可以在這邊閱讀 `更多關於表單驗證的資訊 <../libraries/form_validation.html>`_ 。 76 | 77 | 繼續往下看,你可以看到一個條件式用來檢查表單驗證是否成功。 78 | 若是沒有,就會顯示表單,若是表單已被送出 並且 通過了驗證,模型就會被呼叫。 接著一個檢視會被載入並顯示成功訊息。 79 | 請在 *application/view/news/success.php* 建立一個檢視並寫入成功訊息。 80 | 81 | 模型(Model) 82 | ----------- 83 | 84 | 最後一件事就是寫一個方法來將資料存進資料庫。 85 | 你將會使用 Active Record 類別來新增這資訊,並使用 Input 程式庫來取得表單送出的資料。 86 | 打開之前建立的模型,並加入下列程式碼: 87 | 88 | :: 89 | 90 | public function set_news() 91 | { 92 | $this->load->helper('url'); 93 | 94 | $slug = url_title($this->input->post('title'), 'dash', TRUE); 95 | 96 | $data = array( 97 | 'title' => $this->input->post('title'), 98 | 'slug' => $slug, 99 | 'text' => $this->input->post('text') 100 | ); 101 | 102 | return $this->db->insert('news', $data); 103 | } 104 | 105 | 這個新方法用來新增資料到資料庫中。 106 | 在第三行有個新的 url_title() 函式。 107 | 這個函式 - 由 `URL 輔助函式 <../helpers/url_helper.html>`_ 提供 - 會讀取你傳入的字串,使用破折號 (-) 來替換掉空白,並將所有字串轉為小寫。 108 | 最後會產生一個很好的 slug ,非常適合用來建立 URI 。 109 | 110 | 我們繼續處理待會要存入的資料,將其放進 ``$data`` 陣列中。 111 | 陣列中的每個元素都對應到我們建立的資料庫中的欄位。 112 | 你可能注意到這邊有個新的函式叫做 ``post()`` ,它來自 `Input 函式庫 <../libraries/input.html>`_ 。 113 | 這個方法用來確保資料已經被消毒,可以避免你受到令人討厭的攻擊。而這個程式庫預設就會被自動載入。 114 | 最後,我們將 ``$data`` 存入資料庫當中。 115 | 116 | 路由(Routing) 117 | --------------- 118 | 119 | 在你開始新增項目進去你的 CodeIgniter 應用程式之前,你需要在 *config/routes.php* 中增加額外的規則。 120 | 確認你的檔案中含有下列項目。這讓 CodeIgniter 看到 'create' 時,當作是一個方法,而不是一個新聞的 slug 。 121 | 122 | :: 123 | 124 | $route['news/create'] = 'news/create'; 125 | $route['news/(:any)'] = 'news/view/$1'; 126 | $route['news'] = 'news'; 127 | $route['(:any)'] = 'pages/view/$1'; 128 | $route['default_controller'] = 'pages/view'; 129 | 130 | 現在打開你的瀏覽器並輸入你的 CodeIgniter 根目錄網址,並在後面加上 index.php/news/create 。 恭喜你,你剛剛建立了你的第一個 CodeIgniter 應用程式!增加一些新聞並逛一逛你所建立的其它頁面。 131 | -------------------------------------------------------------------------------- /source/tutorial/index.rst: -------------------------------------------------------------------------------- 1 | ######## 2 | 教學 3 | ######## 4 | 5 | 這篇教學旨在向你介紹 CodeIgniter 框架以及 MVC 架構的基本原則。它將一步步的告訴你一個基本的 CodeIgniter 程式是如何建構的。 6 | 7 | 在這篇教學裡,你將會製作一個 **簡單的新聞程式** 。你將從使用程式來讀取靜態頁面開始。接著,你會製作一個新聞模組,可以從資料庫讀取新聞項目。最後你會增加一個表單,用來在資料庫中增加新聞項目。 8 | 9 | 這篇教學主要會專注在: 10 | 11 | - Model-View-Controller 基礎知識 12 | - 路由(Routing)基礎知識 13 | - 表單驗證 14 | - 使用”Query Builder“來做簡單的資料庫查詢 15 | 16 | 整篇教學被分為數個部份進行,每一部份解釋 CodeIgniter 框架的一小部份功能。詳列如下: 17 | 18 | - 簡介,也就是目前這一頁,給你一些概念讓你知道接下來會做些什麼。 19 | - `靜態頁面 `_ ,將會教你關於控制器(Controller),視圖(View)與路由的基礎知識。 20 | - `新聞模組 `_ ,這邊你將開始使用模型(Model),並且進行一些簡單的資料庫操作。 21 | - `新增新聞項目 `_ ,將會進行更進階的資料庫操作以及表單驗證。 22 | - `結論 `_ ,將會指引你一些未來的學習方向以及其它資源。 23 | 24 | 祝你在 CodeIgniter 框架的探索中旅途愉快。 25 | 26 | .. toctree:: 27 | :glob: 28 | :hidden: 29 | :titlesonly: 30 | 31 | static_pages 32 | news_section 33 | create_news_items 34 | conclusion 35 | -------------------------------------------------------------------------------- /source/tutorial/static_pages.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | 靜態頁面 3 | ############ 4 | 5 | **Note:** 這篇教學假設你已經下載了 CodeIgniter 並且已經 `安裝 <../installation/index.html>`_ 在你的開發環境中。 6 | 7 | 你要做的第一件事情是設置一個 **控制器(Controller)** 來處理靜態頁面。控制器是一個簡單的類別來幫助委派工作。它是你的網頁應用程式中的膠水。 8 | 9 | 例如,當瀏覽器發出一個請求給: 10 | 11 | http://example.com/news/latest/10 12 | 13 | 我們可以想像那邊有個控制器名為 "news" 。而 news 控制器將會被呼叫的方法(method)為 "latest" 。 這個 latest 方法的工作可能是抓取十個新聞項目,並顯示在頁面上。這在 MVC 中很常見,你看到的 URL 格式將會是這樣: 14 | 15 | http://example.com/[controller-class]/[controller-method]/[arguments] 16 | 17 | 當 URL 變得更複雜時這可能會改變。但目前來說這就是我們所需要知道的全部了。 18 | 19 | 在 application/controllers/Pages.php 創建一個檔案,填入下面的程式。 20 | 21 | :: 22 | 23 | 40 | 41 | CodeIgniter Tutorial 42 | 43 | 44 | 45 |

46 | 47 | 這個 header 放的是你想要在主畫面之前顯示的基本 HTML 代碼,裡面包含了 HTML head。 它也顯示了 $title 變數,我們待會會在控制器中定義它。 現在在 application/views/templates/footer.php 建立 footer 檔案,裡面包含下列代碼: 48 | 49 | :: 50 | 51 | © 2015 52 | 53 | 54 | 55 | 在控制器(Controller)中增加邏輯 56 | ------------------------------ 57 | 58 | 剛才你設置了控制器以及一個 view() 方法。這個方法接受一個參數,這個參數就是將要被讀取的頁面名稱。靜態頁面的模板將會放在 application/views/pages/ 資料夾。 59 | 60 | 在那個資料夾裡,建立兩個檔案並命名為 home.php 以及 about.php 。在這兩個檔案裡打一些字−隨便你想打什麼−然後存檔。如果你喜歡老套的,就放"Hello World!"。 61 | 62 | 在讀取這些頁面之前,你必須去確認所要求的頁面是存在的: 63 | 64 | :: 65 | 66 | public function view($page = 'home') 67 | { 68 | if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')) 69 | { 70 | // Whoops, we don't have a page for that! 71 | show_404(); 72 | } 73 | 74 | $data['title'] = ucfirst($page); // Capitalize the first letter 75 | 76 | $this->load->view('templates/header', $data); 77 | $this->load->view('pages/'.$page, $data); 78 | $this->load->view('templates/footer', $data); 79 | } 80 | 81 | 現在,當頁面存在時,它將會被讀取然後顯示給使用者,包含了 header 與 footer 。如果頁面不存在,將會顯示錯誤訊息"404 Page not found"。 82 | 83 | 在這個方法中的第一行檢查了頁面檔案是否存在。PHP的原生函式 file\_exists() 用來檢查檔案是否在預期的地方。 show\_404() 是 CodeIgniter 內建的函式,用來顯示預設的錯誤訊息頁面。 84 | 85 | 在 header 模板裡, $title 變數用來客製頁面的標題。在view方法中我們給標題設定了值,但我們不是將值設定給變數,而是設定給 $data 陣列裡面的 title 元素。 86 | 87 | 最後要做的事情是按照順序來讀取檢視。在 view() 方法中的第二個參數是用來傳值給檢視用的。$data 陣列中的每個值會依照其陣列索引鍵值來存放到同名的變數中。 所以在控制器中 $data['title'] 的值等同於檢視中的 $title 。 88 | 89 | 路由(Routing) 90 | ------------- 91 | 92 | 控制器現在可以運作了!打開你的瀏覽器並前往 [你的網址]index.php/pages/view 來瞧瞧你的網頁。 當你訪問 index.php/pages/view/about 時你將會看到 about 頁面,並且包含了 header 與 footer。 93 | 94 | 使用自訂的路由規則,你就擁有將任何 URI 對應到任何控制器與方法的力量,並且掙脫了這個慣例: 95 | ``http://example.com/[controller-class]/[controller-method]/[arguments]`` 96 | 97 | 就讓我們試試看。打開位於 application/config/routes.php 的路由檔案,增加下列兩行。並將其它設置 $route 陣列的程式碼都移除。 98 | 99 | :: 100 | 101 | $route['default_controller'] = 'pages/view'; 102 | $route['(:any)'] = 'pages/view/$1'; 103 | 104 | CodeIgniter 由上而下讀取這個路由規則,並且將請求導向第一個符合的規則。 每一個規則都是正則表達式(位於左側),對應到由反斜線分隔的控制器與方法(位於右側)。當一個請求進來,CodeIgniter 找出第一個符合的規則,然後呼叫其控制器與方法,可能還包含了參數。 105 | 106 | 關於路由的更多資訊可以在 107 | `documentation <../general/routing.html>`_ 中找到。 108 | 109 | 在這邊, $routes 陣列中的第二條規則使用了萬用字串 (:any),它將會符合任何的請求。並將參數傳送給 pages 類別中的 view() 方法。 110 | 111 | 現在,訪問 index.php/about 。是不是被正確的導到 pages 控制器中的 view() 方法呢?太神奇了! 112 | --------------------------------------------------------------------------------