Permalink
Browse files

[ci skip] Polish docs in user_guide_src/source/general/

  • Loading branch information...
narfbg committed Nov 9, 2012
1 parent 1bc3026 commit 16a704ce8a1449cbee22fb13bd32508c975fac9f
Showing with 587 additions and 473 deletions.
  1. +1 −1 user_guide_src/source/contributing/index.rst
  2. +10 −11 user_guide_src/source/general/alternative_php.rst
  3. +50 −11 user_guide_src/source/general/ancillary_classes.rst
  4. +9 −9 user_guide_src/source/general/autoloader.rst
  5. +16 −14 user_guide_src/source/general/caching.rst
  6. +7 −7 user_guide_src/source/general/cli.rst
  7. +41 −43 user_guide_src/source/general/controllers.rst
  8. +20 −20 user_guide_src/source/general/core_classes.rst
  9. +3 −2 user_guide_src/source/general/creating_drivers.rst
  10. +60 −33 user_guide_src/source/general/creating_libraries.rst
  11. +1 −1 user_guide_src/source/general/credits.rst
  12. +8 −8 user_guide_src/source/general/drivers.rst
  13. +3 −3 user_guide_src/source/general/environments.rst
  14. +44 −22 user_guide_src/source/general/errors.rst
  15. +30 −28 user_guide_src/source/general/helpers.rst
  16. +37 −36 user_guide_src/source/general/hooks.rst
  17. +1 −1 user_guide_src/source/general/index.rst
  18. +12 −11 user_guide_src/source/general/libraries.rst
  19. +21 −23 user_guide_src/source/general/managing_apps.rst
  20. +48 −49 user_guide_src/source/general/models.rst
  21. +14 −14 user_guide_src/source/general/profiling.rst
  22. +10 −4 user_guide_src/source/general/requirements.rst
  23. +22 −19 user_guide_src/source/general/reserved_names.rst
  24. +25 −25 user_guide_src/source/general/routing.rst
  25. +35 −16 user_guide_src/source/general/security.rst
  26. +20 −22 user_guide_src/source/general/styleguide.rst
  27. +13 −11 user_guide_src/source/general/urls.rst
  28. +25 −28 user_guide_src/source/general/views.rst
  29. +1 −1 user_guide_src/source/general/welcome.rst
@@ -102,4 +102,4 @@ it.
By signing your work in this manner, you certify to a "Developer's Certificate
or Origin". The current version of this certificate is in the :doc:`/DCO` file
-in the root of this documentation.
+in the root of this documentation.
@@ -17,12 +17,12 @@ Automatic Short Tag Support
work on your server it might be that "short tags" are disabled in your
PHP ini file. CodeIgniter will optionally rewrite short tags on-the-fly,
allowing you to use that syntax even if your server doesn't support it.
- This feature can be enabled in your config/config.php file.
+ This feature can be enabled in your *config/config.php* file.
Please note that if you do use this feature, if PHP errors are
encountered in your **view files**, the error message and line number
will not be accurately shown. Instead, all errors will be shown as
-eval() errors.
+``eval()`` errors.
Alternative Echos
=================
@@ -39,13 +39,13 @@ Alternative Control Structures
==============================
Controls structures, like if, for, foreach, and while can be written in
-a simplified format as well. Here is an example using foreach::
+a simplified format as well. Here is an example using ``foreach``::
<ul>
<?php foreach ($todo as $item): ?>
- <li><?=$item?></li>
+ <li><?=$item?></li>
<?php endforeach; ?>
@@ -60,17 +60,16 @@ Also notice that instead of using a semicolon after each structure
Here is another example, using ``if``/``elseif``/``else``. Notice the colons::
- <?php if ($username == 'sally'): ?>
+ <?php if ($username === 'sally'): ?>
- <h3>Hi Sally</h3>
+ <h3>Hi Sally</h3>
- <?php elseif ($username == 'joe'): ?>
+ <?php elseif ($username === 'joe'): ?>
- <h3>Hi Joe</h3>
+ <h3>Hi Joe</h3>
<?php else: ?>
- <h3>Hi unknown user</h3>
-
- <?php endif; ?>
+ <h3>Hi unknown user</h3>
+ <?php endif; ?>
@@ -7,31 +7,35 @@ controllers but have the ability to utilize all of CodeIgniter's
resources. This is easily possible as you'll see.
get_instance()
-===============
+==============
-**Any class that you instantiate within your controller functions can
+.. php:function:: get_instance()
+
+ :returns: object of class CI_Controller
+
+**Any class that you instantiate within your controller methods can
access CodeIgniter's native resources** simply by using the
-get_instance() function. This function returns the main CodeIgniter
-object.
+``get_instance()`` function. This function returns the main
+CodeIgniter object.
-Normally, to call any of the available CodeIgniter functions requires
-you to use the $this construct::
+Normally, to call any of the available CodeIgniter methods requires
+you to use the ``$this`` construct::
$this->load->helper('url');
$this->load->library('session');
$this->config->item('base_url');
// etc.
-$this, however, only works within your controllers, your models, or your
-views. If you would like to use CodeIgniter's classes from within your
-own custom classes you can do so as follows:
+``$this``, however, only works within your controllers, your models,
+or your views. If you would like to use CodeIgniter's classes from
+within your own custom classes you can do so as follows:
First, assign the CodeIgniter object to a variable::
$CI =& get_instance();
Once you've assigned the object to a variable, you'll use that variable
-*instead* of $this::
+*instead* of ``$this``::
$CI =& get_instance();
@@ -40,10 +44,45 @@ Once you've assigned the object to a variable, you'll use that variable
$CI->config->item('base_url');
// etc.
-.. note:: You'll notice that the above get_instance() function is being
+.. note:: You'll notice that the above get_instance() ``function`` is being
passed by reference::
$CI =& get_instance();
This is very important. Assigning by reference allows you to use the
original CodeIgniter object rather than creating a copy of it.
+
+Furthermore, if you'll be using ``get_intance()`` inside anoter class,
+then it would be better if you assign it to a property. This way, you
+won't need to call ``get_instance()`` in every single method.
+
+Example::
+
+class Example {
+
+ protected $CI;
+
+ // We'll use a constructor, as you can't directly call a function
+ // from a property definition.
+ public function __construct()
+ {
+ // Assign the CodeIgniter super-object
+ $this->CI =& get_instance();
+ }
+
+ public function foo()
+ {
+ $this->CI->load->helper('url');
+ redirect();
+ }
+
+ public function bar()
+ {
+ $this->CI->config_item('base_url');
+ }
+
+}
+
+In the above example, both methods ``foo()`` and ``bar()`` will work
+after you instantiate the Example class, without the need to call
+``get_instance()`` in each of them.
@@ -9,15 +9,15 @@ application you should consider auto-loading them for convenience.
The following items can be loaded automatically:
-- Classes found in the "libraries" folder
-- Helper files found in the "helpers" folder
-- Custom config files found in the "config" folder
-- Language files found in the "system/language" folder
-- Models found in the "models" folder
+- Classes found in the *libraries/* directory
+- Helper files found in the *helpers/* directory
+- Custom config files found in the *config/* directory
+- Language files found in the *system/language/* directory
+- Models found in the *models/* folder
-To autoload resources, open the application/config/autoload.php file and
-add the item you want loaded to the autoload array. You'll find
-instructions in that file corresponding to each type of item.
+To autoload resources, open the *application/config/autoload.php*
+file and add the item you want loaded to the autoload array. You'll
+find instructions in that file corresponding to each type of item.
.. note:: Do not include the file extension (.php) when adding items to
- the autoload array.
+ the autoload array.
@@ -23,36 +23,38 @@ will be retrieved and sent to the requesting user's browser. If it has
expired, it will be deleted and refreshed before being sent to the
browser.
-Note: The Benchmark tag is not cached so you can still view your page
-load speed when caching is enabled.
+.. note: The Benchmark tag is not cached so you can still view your page
+ load speed when caching is enabled.
Enabling Caching
================
To enable caching, put the following tag in any of your controller
-functions::
+methods::
- $this->output->cache(n);
+ $this->output->cache($n);
-Where n is the number of **minutes** you wish the page to remain cached
-between refreshes.
+Where ``$n`` is the number of **minutes** you wish the page to remain
+cached between refreshes.
-The above tag can go anywhere within a function. It is not affected by
+The above tag can go anywhere within a method. It is not affected by
the order that it appears, so place it wherever it seems most logical to
you. Once the tag is in place, your pages will begin being cached.
.. important:: Because of the way CodeIgniter stores content for output,
- caching will only work if you are generating display for your controller
- with a :doc:`view <./views>`.
+ caching will only work if you are generating display for your
+ controller with a :doc:`view <./views>`.
.. note:: Before the cache files can be written you must set the file
- permissions on your application/cache folder such that it is writable.
+ permissions on your *application/cache/* directory such that
+ it is writable.
Deleting Caches
===============
If you no longer wish to cache a file you can remove the caching tag and
-it will no longer be refreshed when it expires. Note: Removing the tag
-will not delete the cache immediately. It will have to expire normally.
-If you need to remove it earlier you will need to manually delete it
-from your cache folder.
+it will no longer be refreshed when it expires.
+
+.. note:: Removing the tag will not delete the cache immediately. It will
+ have to expire normally. If you need to remove it earlier you
+ will need to manually delete it from your cache directory.
@@ -21,7 +21,7 @@ Why run via the command-line?
There are many reasons for running CodeIgniter from the command-line,
but they are not always obvious.
-- Run your cron-jobs without needing to use wget or curl
+- Run your cron-jobs without needing to use *wget* or *curl*
- Make your cron-jobs inaccessible from being loaded in the URL by
checking for ``$this->input->is_cli_request()``
- Make interactive "tasks" that can do things like set permissions,
@@ -44,9 +44,8 @@ in it::
echo "Hello {$to}!".PHP_EOL;
}
}
- ?>
-Then save the file to your application/controllers/ folder.
+Then save the file to your *application/controllers/* folder.
Now normally you would visit the your site using a URL similar to this::
@@ -60,19 +59,20 @@ in Windows and navigate to our CodeIgniter project.
$ cd /path/to/project;
$ php index.php tools message
-If you did it right, you should see Hello World!.
+If you did it right, you should see *Hello World!* printed.
.. code-block:: bash
$ php index.php tools message "John Smith"
Here we are passing it a argument in the same way that URL parameters
-work. "John Smith" is passed as a argument and output is: Hello John
-Smith!.
+work. "John Smith" is passed as a argument and output is::
+
+ Hello John Smith!
That's it!
==========
That, in a nutshell, is all there is to know about controllers on the
command line. Remember that this is just a normal controller, so routing
-and _remap works fine.
+and ``_remap()`` works fine.
Oops, something went wrong.

0 comments on commit 16a704c

Please sign in to comment.