Skip to content

Commit

Permalink
[ci skip] Polish docs in user_guide_src/source/general/
Browse files Browse the repository at this point in the history
  • Loading branch information
narfbg committed Nov 9, 2012
1 parent 1bc3026 commit 16a704c
Show file tree
Hide file tree
Showing 29 changed files with 587 additions and 473 deletions.
2 changes: 1 addition & 1 deletion user_guide_src/source/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
21 changes: 10 additions & 11 deletions user_guide_src/source/general/alternative_php.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=================
Expand All @@ -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; ?>

Expand All @@ -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; ?>
61 changes: 50 additions & 11 deletions user_guide_src/source/general/ancillary_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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.
18 changes: 9 additions & 9 deletions user_guide_src/source/general/autoloader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
30 changes: 16 additions & 14 deletions user_guide_src/source/general/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
14 changes: 7 additions & 7 deletions user_guide_src/source/general/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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::

Expand All @@ -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.
Loading

0 comments on commit 16a704c

Please sign in to comment.