From b0dd10f8171945e0c1f3527dd1e9d18b043e01a7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Aug 2006 17:25:49 +0000 Subject: Initial Import --- user_guide/general/alternative_php.html | 142 +++++ user_guide/general/ancillary_classes.html | 122 ++++ user_guide/general/autoloader.html | 106 ++++ user_guide/general/base_classes.html | 127 +++++ user_guide/general/caching.html | 119 ++++ user_guide/general/changelog.html | 248 +++++++++ user_guide/general/controllers.html | 317 +++++++++++ user_guide/general/creating_libraries.html | 222 ++++++++ user_guide/general/credits.html | 96 ++++ user_guide/general/errors.html | 142 +++++ user_guide/general/helpers.html | 140 +++++ user_guide/general/hooks.html | 184 +++++++ user_guide/general/index.html | 95 ++++ user_guide/general/libraries.html | 111 ++++ user_guide/general/models.html | 256 +++++++++ user_guide/general/multiple_apps.html | 116 ++++ user_guide/general/plugins.html | 125 +++++ user_guide/general/quick_reference.html | 83 +++ user_guide/general/requirements.html | 88 +++ user_guide/general/routing.html | 163 ++++++ user_guide/general/scaffolding.html | 153 +++++ user_guide/general/scripts.html | 115 ++++ user_guide/general/security.html | 159 ++++++ user_guide/general/urls.html | 159 ++++++ user_guide/general/views.html | 249 +++++++++ user_guide/helpers/array_helper.html | 111 ++++ user_guide/helpers/cookie_helper.html | 133 +++++ user_guide/helpers/date_helper.html | 340 ++++++++++++ user_guide/helpers/directory_helper.html | 145 +++++ user_guide/helpers/file_helper.html | 144 +++++ user_guide/helpers/form_helper.html | 343 ++++++++++++ user_guide/helpers/html_helper.html | 117 ++++ user_guide/helpers/index.html | 131 +++++ user_guide/helpers/security_helper.html | 131 +++++ user_guide/helpers/string_helper.html | 144 +++++ user_guide/helpers/text_helper.html | 197 +++++++ user_guide/helpers/typography_helper.html | 129 +++++ user_guide/helpers/url_helper.html | 269 +++++++++ user_guide/helpers/xml_helper.html | 110 ++++ user_guide/images/appflowchart.gif | Bin 0 -> 25276 bytes user_guide/images/arrow.gif | Bin 0 -> 123 bytes user_guide/images/ci_logo.jpg | Bin 0 -> 5602 bytes user_guide/images/ci_logo_mini.jpg | Bin 0 -> 2198 bytes user_guide/images/ci_quick_ref.png | Bin 0 -> 94476 bytes user_guide/images/file.gif | Bin 0 -> 370 bytes user_guide/images/folder.gif | Bin 0 -> 570 bytes user_guide/images/nav_bg.jpg | Bin 0 -> 441 bytes user_guide/images/nav_separator.jpg | Bin 0 -> 305 bytes user_guide/images/nav_toggle.jpg | Bin 0 -> 3076 bytes user_guide/images/transparent.gif | Bin 0 -> 43 bytes user_guide/index.html | 106 ++++ user_guide/installation/downloads.html | 97 ++++ user_guide/installation/index.html | 116 ++++ user_guide/installation/upgrade_120.html | 98 ++++ user_guide/installation/upgrade_130.html | 209 +++++++ user_guide/installation/upgrade_131.html | 108 ++++ user_guide/installation/upgrade_132.html | 106 ++++ user_guide/installation/upgrade_133.html | 118 ++++ user_guide/installation/upgrade_140.html | 111 ++++ user_guide/installation/upgrade_b11.html | 150 +++++ user_guide/installation/upgrading.html | 95 ++++ user_guide/libraries/benchmark.html | 160 ++++++ user_guide/libraries/calendar.html | 258 +++++++++ user_guide/libraries/config.html | 158 ++++++ user_guide/libraries/database/active_record.html | 610 ++++++++++++++++++++ user_guide/libraries/database/call_function.html | 123 +++++ user_guide/libraries/database/configuration.html | 144 +++++ user_guide/libraries/database/connecting.html | 172 ++++++ user_guide/libraries/database/examples.html | 183 ++++++ user_guide/libraries/database/fields.html | 144 +++++ user_guide/libraries/database/index.html | 99 ++++ user_guide/libraries/database/queries.html | 180 ++++++ user_guide/libraries/database/results.html | 235 ++++++++ user_guide/libraries/database/table_data.html | 116 ++++ user_guide/libraries/email.html | 294 ++++++++++ user_guide/libraries/encryption.html | 187 +++++++ user_guide/libraries/file_uploading.html | 429 +++++++++++++++ user_guide/libraries/image_lib.html | 669 ++++++++++++++++++++++ user_guide/libraries/input.html | 207 +++++++ user_guide/libraries/language.html | 130 +++++ user_guide/libraries/loader.html | 171 ++++++ user_guide/libraries/output.html | 112 ++++ user_guide/libraries/pagination.html | 218 ++++++++ user_guide/libraries/parser.html | 214 +++++++ user_guide/libraries/sessions.html | 283 ++++++++++ user_guide/libraries/trackback.html | 251 +++++++++ user_guide/libraries/unit_testing.html | 210 +++++++ user_guide/libraries/uri.html | 220 ++++++++ user_guide/libraries/validation.html | 674 +++++++++++++++++++++++ user_guide/libraries/xmlrpc.html | 485 ++++++++++++++++ user_guide/license.html | 113 ++++ user_guide/overview/appflow.html | 101 ++++ user_guide/overview/at_a_glance.html | 168 ++++++ user_guide/overview/features.html | 122 ++++ user_guide/overview/goals.html | 103 ++++ user_guide/overview/index.html | 89 +++ user_guide/overview/mvc.html | 105 ++++ user_guide/scripts/hacks.txt | 9 + user_guide/scripts/moo.fx.js | 119 ++++ user_guide/scripts/moo.fx.pack.js | 241 ++++++++ user_guide/scripts/nav.js | 116 ++++ user_guide/scripts/prototype.lite.js | 127 +++++ user_guide/toc.html | 182 ++++++ user_guide/userguide.css | 406 ++++++++++++++ 104 files changed, 16932 insertions(+) create mode 100644 user_guide/general/alternative_php.html create mode 100644 user_guide/general/ancillary_classes.html create mode 100644 user_guide/general/autoloader.html create mode 100644 user_guide/general/base_classes.html create mode 100644 user_guide/general/caching.html create mode 100644 user_guide/general/changelog.html create mode 100644 user_guide/general/controllers.html create mode 100644 user_guide/general/creating_libraries.html create mode 100644 user_guide/general/credits.html create mode 100644 user_guide/general/errors.html create mode 100644 user_guide/general/helpers.html create mode 100644 user_guide/general/hooks.html create mode 100644 user_guide/general/index.html create mode 100644 user_guide/general/libraries.html create mode 100644 user_guide/general/models.html create mode 100644 user_guide/general/multiple_apps.html create mode 100644 user_guide/general/plugins.html create mode 100644 user_guide/general/quick_reference.html create mode 100644 user_guide/general/requirements.html create mode 100644 user_guide/general/routing.html create mode 100644 user_guide/general/scaffolding.html create mode 100644 user_guide/general/scripts.html create mode 100644 user_guide/general/security.html create mode 100644 user_guide/general/urls.html create mode 100644 user_guide/general/views.html create mode 100644 user_guide/helpers/array_helper.html create mode 100644 user_guide/helpers/cookie_helper.html create mode 100644 user_guide/helpers/date_helper.html create mode 100644 user_guide/helpers/directory_helper.html create mode 100644 user_guide/helpers/file_helper.html create mode 100644 user_guide/helpers/form_helper.html create mode 100644 user_guide/helpers/html_helper.html create mode 100644 user_guide/helpers/index.html create mode 100644 user_guide/helpers/security_helper.html create mode 100644 user_guide/helpers/string_helper.html create mode 100644 user_guide/helpers/text_helper.html create mode 100644 user_guide/helpers/typography_helper.html create mode 100644 user_guide/helpers/url_helper.html create mode 100644 user_guide/helpers/xml_helper.html create mode 100644 user_guide/images/appflowchart.gif create mode 100644 user_guide/images/arrow.gif create mode 100644 user_guide/images/ci_logo.jpg create mode 100644 user_guide/images/ci_logo_mini.jpg create mode 100644 user_guide/images/ci_quick_ref.png create mode 100644 user_guide/images/file.gif create mode 100644 user_guide/images/folder.gif create mode 100644 user_guide/images/nav_bg.jpg create mode 100644 user_guide/images/nav_separator.jpg create mode 100644 user_guide/images/nav_toggle.jpg create mode 100644 user_guide/images/transparent.gif create mode 100644 user_guide/index.html create mode 100644 user_guide/installation/downloads.html create mode 100644 user_guide/installation/index.html create mode 100644 user_guide/installation/upgrade_120.html create mode 100644 user_guide/installation/upgrade_130.html create mode 100644 user_guide/installation/upgrade_131.html create mode 100644 user_guide/installation/upgrade_132.html create mode 100644 user_guide/installation/upgrade_133.html create mode 100644 user_guide/installation/upgrade_140.html create mode 100644 user_guide/installation/upgrade_b11.html create mode 100644 user_guide/installation/upgrading.html create mode 100644 user_guide/libraries/benchmark.html create mode 100644 user_guide/libraries/calendar.html create mode 100644 user_guide/libraries/config.html create mode 100644 user_guide/libraries/database/active_record.html create mode 100644 user_guide/libraries/database/call_function.html create mode 100644 user_guide/libraries/database/configuration.html create mode 100644 user_guide/libraries/database/connecting.html create mode 100644 user_guide/libraries/database/examples.html create mode 100644 user_guide/libraries/database/fields.html create mode 100644 user_guide/libraries/database/index.html create mode 100644 user_guide/libraries/database/queries.html create mode 100644 user_guide/libraries/database/results.html create mode 100644 user_guide/libraries/database/table_data.html create mode 100644 user_guide/libraries/email.html create mode 100644 user_guide/libraries/encryption.html create mode 100644 user_guide/libraries/file_uploading.html create mode 100644 user_guide/libraries/image_lib.html create mode 100644 user_guide/libraries/input.html create mode 100644 user_guide/libraries/language.html create mode 100644 user_guide/libraries/loader.html create mode 100644 user_guide/libraries/output.html create mode 100644 user_guide/libraries/pagination.html create mode 100644 user_guide/libraries/parser.html create mode 100644 user_guide/libraries/sessions.html create mode 100644 user_guide/libraries/trackback.html create mode 100644 user_guide/libraries/unit_testing.html create mode 100644 user_guide/libraries/uri.html create mode 100644 user_guide/libraries/validation.html create mode 100644 user_guide/libraries/xmlrpc.html create mode 100644 user_guide/license.html create mode 100644 user_guide/overview/appflow.html create mode 100644 user_guide/overview/at_a_glance.html create mode 100644 user_guide/overview/features.html create mode 100644 user_guide/overview/goals.html create mode 100644 user_guide/overview/index.html create mode 100644 user_guide/overview/mvc.html create mode 100644 user_guide/scripts/hacks.txt create mode 100755 user_guide/scripts/moo.fx.js create mode 100755 user_guide/scripts/moo.fx.pack.js create mode 100644 user_guide/scripts/nav.js create mode 100755 user_guide/scripts/prototype.lite.js create mode 100644 user_guide/toc.html create mode 100644 user_guide/userguide.css (limited to 'user_guide') diff --git a/user_guide/general/alternative_php.html b/user_guide/general/alternative_php.html new file mode 100644 index 000000000..8838ac8a0 --- /dev/null +++ b/user_guide/general/alternative_php.html @@ -0,0 +1,142 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Alternate PHP Syntax for View Files

+ +

If you do not utilize Code Igniter's template engine, you'll be using pure PHP +in your View files. To minimize the PHP code in these files, and to make it easier to identify the code blocks it is recommended that you use PHPs alternative +syntax for control structures and echo statements. If you are not familiar with this syntax, it allows you to eliminate the braces from your code, +and eliminate "echo" statements.

+ +

Alternative Echos

+ +

Normally to echo, or print out a variable you would do this:

+ +<?php echo $variable; ?> + +

With the alternative syntax you can instead do it this way:

+ +<?=$variable?> + +

Note: If you find that the syntax described in this page does not work on your server it might +be that "short tags" are disabled in your PHP ini file.

+ + +

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:

+ + +<ul>
+
+<?php foreach($todo as $item): ?>
+
+<li><?=$item?></li>
+
+<?php endforeach ?>
+
+</ul>
+ +

Notice that there are no braces. Instead, the end brace is replaced with endforeach. +Each of the control structures listed above has a similar closing syntax: +endif, endfor, endforeach, and endwhile

+ +

Also notice that instead of using a semicolon after each structure (except the last one), there is a colon. This is +important!

+ +

Here is another example, using if/elseif/else. Notice the colons:

+ + +<?php if ($username == 'sally'): ?>
+
+   <h3>Hi Sally</h3>
+
+<?php elseif ($username == 'joe'): ?>
+
+   <h3>Hi Joe</h3>
+
+<?php else: ?>
+
+   <h3>Hi unknown user</h3>
+
+<?php endif; ?>
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/ancillary_classes.html b/user_guide/general/ancillary_classes.html new file mode 100644 index 000000000..fc67bec70 --- /dev/null +++ b/user_guide/general/ancillary_classes.html @@ -0,0 +1,122 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Creating Ancillary Classes

+ +

In some cases you may want to develop classes that exist apart from your controllers but have the ability to +utilize all of Code Igniter's resources. This is easily possible as you'll see.

+ +

get_instance()

+ + +

Any class that you instantiate within your controller functions can access Code Igniter's native resources simply by using the get_instance() function. +This function returns the main Code Igniter object.

+ +

Normally, to call any of the available Code Igniter functions 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 Code Igniter's classes from within your own custom classes you can do so as follows:

+ + +

First, assign the Code Igniter object to a variable:

+ +$obj =& get_instance(); + +

Once you've assigned the object to a variable, you'll use that variable instead of $this:

+ + +$obj =& get_instance();

+$obj->load->helper('url');
+$obj->load->library('session');
+$obj->config->item('base_url');
+etc. +
+ +

Note: You'll notice that the above get_instance() function is being passed by reference: +

+$obj =& get_instance(); +

+This is very important. Assigning by reference allows you to use the original Code Igniter object rather than creating a copy of it.

+
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/autoloader.html b/user_guide/general/autoloader.html new file mode 100644 index 000000000..5f90fddad --- /dev/null +++ b/user_guide/general/autoloader.html @@ -0,0 +1,106 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Auto-loading Resources

+ +

Code Igniter comes with an "Auto-load" feature that permits libraries, helpers, and plugins to be initialized +automatically every time the system runs. If you need certain resources globally throughout your application you should +consider auto-loading them for convenience.

+ +

The following items can be loaded automatically:

+ + + +

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.

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/base_classes.html b/user_guide/general/base_classes.html new file mode 100644 index 000000000..215bd25b5 --- /dev/null +++ b/user_guide/general/base_classes.html @@ -0,0 +1,127 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Replacing System Classes

+ +

Every time Code Igniter runs there are several base classes that are initialized automatically as part of the core framework. +It is possible, however, to swap any of the core system files with your own versions.  Most users will never have any need to do this, +but the option to replace them does exist for those that would like to significantly alter the Code Igniter core. +

+ +

Note:  Replacing a core system class with your own version has a lot of implications, so make sure you +know what you are doing before attempting it.

+ + +

System Class List

+ +

The following is a list of the core system files that are invoked every time Code Igniter runs:

+ + + +

Replacing Core Classes

+ +

To use one of your own system classes instead of a default one simply place your version inside your local libraries directory:

+ +application/libraries/some-class.php + +

Any file named identically to one from the list above will be used instead of the one normally used.

+ +

Please note that your class must use CI as a prefix. For example, if your file is named Input.php the class will be named:

+ + +class CI_Input {

+ +} +
+ + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/caching.html b/user_guide/general/caching.html new file mode 100644 index 000000000..a5edbe73f --- /dev/null +++ b/user_guide/general/caching.html @@ -0,0 +1,119 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Web Page Caching

+ +

Code Igniter lets you cache your pages in order to achieve maximum performance. + +Although Code Igniter is quite fast, the amount of dynamic information you display in your pages will correlate directly to the +server resources, memory, and processing cycles utilized, which affect your page load speeds. +By caching your pages, since they are saved in their fully rendered state, you can achieve performance that nears that of static web pages. + + +

How Does Caching Work?

+ +

Caching can be enabled on a per-page basis, and you can set the length of time that a page should remain cached before being refreshed. +When a page is loaded for the first time, the cache file will be written to your system/cache folder. On subsequent page loads the cache file 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.

+ +

Enabling Caching

+ +

To enable caching, put the following tag in any of your controller functions:

+ +$this->output->cache(n); + +

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

+ +

Note: Before the cache files can be written you must set the file permissions on your +system/cache folder such that it is writable (666 is usually appropriate).

+ +

Deleting Caches

+ +

If you no longer wish to cache a file you can remove the caching tag and it will not 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.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/changelog.html b/user_guide/general/changelog.html new file mode 100644 index 000000000..0bcb165da --- /dev/null +++ b/user_guide/general/changelog.html @@ -0,0 +1,248 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Change Log

+ + + +

Version 1.4.0

+

Release Date: August 25, 2006

+ + + + + +

Version 1.3.3

+

Release Date: June 1, 2006

+ + + + + + +

Version 1.3.2

+

Release Date: April 17, 2006

+ + + + + +

Version 1.3.1

+

Release Date: April 11, 2006

+ + + + +

Version 1.3

+

Release Date: April 3, 2006

+ + + + + + + + + + +

Version 1.2

+

Release Date: March 21, 2006

+ + + + + + + +

Version Beta 1.1

+

Release Date: March 10, 2006

+ + + +

Version Beta 1.0

+

Release Date: February 28, 2006

+

First publicly released version.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/controllers.html b/user_guide/general/controllers.html new file mode 100644 index 000000000..648298eb0 --- /dev/null +++ b/user_guide/general/controllers.html @@ -0,0 +1,317 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Controllers

+ +

Controllers are the heart of your application, as they determine how HTTP requests should be handled.

+ + + + + + +

What is a Controller?

+ +

A Controller is simply a class file that is named in a way that can be associated with a URI.

+ +

Consider this URI:

+ +www.your-site.com/index.php/blog/ + +

In the above example, Code Igniter would attempt to find a controller named blog.php and load it.

+ +

When a controller's name matches the first segment of a URI, it will be loaded.

+ + +

Let's try it:  Hello World!

+ +

Let's create a simple controller so you can see it in action. Using your text editor, create a file called blog.php, and put the following code in it:

+ + + + + + +

Then save the file to your application/controllers/ folder.

+ +

Now visit the your site using a URL similar to this:

+ +www.your-site.com/index.php/blog/ + +

If you did it right, you should see Hello World!.

+ +

Note: Class names must start with an uppercase letter. In other words, this is valid: + +<?php
+class Blog extends Controller {
+
+}
+?>
+ +

This is not valid:

+ +<?php
+class blog extends Controller {
+
+}
+?>
+ +

Also, always make sure your controller extends the parent controller class so that it can inherit all its functions.

+ + + + +

Functions

+ +

In the above example the function name is index(). The "index" function is always loaded by default if the +second segment of the URI is empty. Another way to show your "Hello World" message would be this:

+ +www.your-site.com/index.php/blog/index/ + +

The second segment of the URI determines which function in the controller gets called.

+ +

Let's try it. Add a new function to your controller:

+ + + + +

Now load the following URL to see the comment function:

+ +www.your-site.com/index.php/blog/comments/ + +

You should see your new message.

+ + +

Private Functions

+ +

In some cases you may not want certain functions accessible publicly. To make a function private, simply add an +underscore as the name prefix and it will not be served via a URL request. For example, if you were to have a function like this:

+ + +function _utility()
+{
+  // some code
+}
+ +

Trying to access it via the URL, like this, will not work:

+ +www.your-site.com/index.php/blog/_utility/ + + + + +

Defining a Default Controller

+ +

Code Igniter can be told to load a default controller when a URI is not present, +as will be the case when only your site root URL is requested. To specify a default controller, open +your application/config/routes.php file and set this variable:

+ +$route['default_controller'] = 'Blog'; + +

Where Blog is the name of the controller class you want used. If you now load your main index.php file without +specifying any URI segments you'll see your Hello World message by default.

+ + + +

Class Constructors

+ + +

If you intend to use a constructor in any of your Controllers, you MUST place the following line of code in it:

+ +parent::Controller(); + +

The reason this line is necessary is because your local constructor will be overriding the one in the parent controller class so we need to manually call it.

+ + +

If you are not familliar with constructors, in PHP 4, a constructor is simply a function that has the exact same name as the class:

+ + +<?php
+class Blog extends Controller {
+
+       function Blog()
+       {
+            parent::Controller();
+       }
+}
+?>
+ +

In PHP 5, constructors use the following syntax:

+ + +<?php
+class Blog extends Controller {
+
+       function __construct()
+       {
+            parent::Controller();
+       }
+}
+?>
+ +

Constructors are useful if you need to set some default values, or run a default process when your class is instantiated. +Constructors can't return a value, but they can do some default work.

+ + +

Reserved Function Names

+ +

Since your controller classes will extend the main application controller you +must be careful not to name your functions identically to the ones used by that class, otherwise your local functions +will override them. The following +is a list of reserved names. Do not name your controller functions any of these:

+ + + +


If you are running PHP 4 there are some additional reserved names. These ONLY apply if you are running PHP 4.

+ + + + + + + + +

That's it!

+ +

That, in a nutshell, is all there is to know about controllers.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/creating_libraries.html b/user_guide/general/creating_libraries.html new file mode 100644 index 000000000..fa3416767 --- /dev/null +++ b/user_guide/general/creating_libraries.html @@ -0,0 +1,222 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Creating Libraries

+ +

When we use the term "Libraries" we are normally referring to the classes that are located in the libraries +directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create your own libraries within +your application directory in order to maintain separation between your local resources and the global framework resources.

+ +

Storage

+ +

In order for your libraries to be stored in your application folder you will need to create two directories in which to store them:

+ + + + +

Anatomy of a Library

+ +

A class library consists of two components:

+ +
    +
  1. An init file.
  2. +
  3. A class file.
  4. +
+ +

The Init File

+ +

An init file a small initialization file corresponding to each of your classes. The purpose of this file is to +instantiate a particular class. Each init file must be named identically to your class file name, adding the "init_" prefix. For example, if your +class is named myclass.php your init file will be named:

+ +init_myclass.php + +

Within your init file you will place your initialization code. Here's an example of such code, using an imaginary class named Myclass:

+ + +<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+
+if ( ! class_exists('Myclass'))
+{
+     require_once(APPPATH.'libraries/Myclass'.EXT);
+}
+
+$obj =& get_instance();
+$obj->myclass = new Myclass();
+$obj->ci_is_loaded[] = 'myclass';
+
+?>
+ +

The Class File

+ +

Your class file itself will be placed inside your libraries directory:

+ +application/libraries/myclass.php + +

The class will have this basic prototype:

+ +<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+
+class Myclass {
+
+}
+?>
+ + +

Naming Conventions

+ + + + +

Using Your Class

+ +

From within any of your Controller classes you can initialize your class using the standard:

+ +$this->load->library('myclass'); + +

Once loaded you can access your class using:

+ +$this->myclass->function(); + +

Note: In your init file you can define the object variable name.

+ + +

Passing Parameters Your Class

+ +

In the library loading function you can pass data via the second parameter and it will be available to your initialization file:

+ + +$params = array('type' => 'large', 'color' => 'red');
+
+$this->load->library('myclass', $params);
+ +

Parameters will be accessible using a variable called $params. By default this variable is set to FALSE.

+ + +

Utilizing Code Igniter Resources within Your Library

+ + +

To access Code Igniter's native resources within your library use the get_instance() function. +This function returns the Code Igniter super object.

+ +

Normally, to call any of the available Code Igniter functions 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 directly within your controllers, your models, or your views. +If you would like to use Code Igniter's classes from within your own custom classes you can do so as follows:

+ + +

First, assign the Code Igniter object to a variable:

+ +$obj =& get_instance(); + +

Once you've assigned the object to a variable, you'll use that variable instead of $this:

+ + +$obj =& get_instance();

+$obj->load->helper('url');
+$obj->load->library('session');
+$obj->config->item('base_url');
+etc. +
+ +

Note: You'll notice that the above get_instance() function is being passed by reference: +

+$obj =& get_instance(); +

+This is very important. Assigning by reference allows you to use the original Code Igniter object rather than creating a copy of it.

+ + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/credits.html b/user_guide/general/credits.html new file mode 100644 index 000000000..dd318b7d4 --- /dev/null +++ b/user_guide/general/credits.html @@ -0,0 +1,96 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Credits

+ +

Code Igniter was developed by Rick Ellis, who in his other life is CEO of +pMachine, Inc. The core framework was written +specifically for this application, while many of the class libraries, helpers, and sub-systems borrow from the code-base of +ExpressionEngine, a Content Management System written by Rick Ellis and +Paul Burdick.

+ +

A hat tip goes to Ruby on Rails for inspiring us to create a PHP framework, and for +bringing frameworks into the general consciousness of the web community.

+ +

The Code Igniter logo and icons were created by Rick Ellis.

+ +

The pull-down table of contents was created with the use of the moo.fx library.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/errors.html b/user_guide/general/errors.html new file mode 100644 index 000000000..60acbfe1f --- /dev/null +++ b/user_guide/general/errors.html @@ -0,0 +1,142 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Error Handling

+ +

Code Igniter lets you build error reporting into your applications using the functions described below. +In addition, it has an error logging class that permits error and debugging messages to be saved as text files.

+ +

Note: By default, Code Igniter displays all PHP errors. You might +wish to change this behavior once your development is complete. You'll find the error_reporting() +function located at the top of your main index.php file. Disabling error reporting will NOT prevent log files +from being written if there are errors.

+ +

Unlike most systems in Code Igniter, the error functions are simple procedural interfaces that are available +globally throughout the application. This approach permits error messages to get triggered without having to worry +about class/function scoping.

+ +

The following functions let you generate errors:

+ +

show_error('message')

+

This function will display the error message supplied to it using the following error template:

+

application/errors/error_general.php

+ +

show_404('page')

+

This function will display the 404 error message supplied to it using the following error template:

+

application/errors/error_404.php

+ +

The function expects the string passed to it to be the file path to the page that isn't found. +Note that Code Igniter automatically shows 404 messages if controllers are not found.

+ + +

log_message('level', 'message')

+ +

This function lets you write messages to your log files. You must supply one of three "levels" +in the first parameter, indicating what type of message it is (debug, error, info), with the message +itself in the second parameter. Example:

+ + +if ($some_var == "")
+{
+    log_message('error', 'Some variable did not contain a value.');
+}
+else
+{
+    log_message('debug', 'Some variable was correctly set');
+}
+
+log_message('info', 'The purpose of some variable is to provide some value.');
+
+ +

There are three message types:

+ +
    +
  1. Error Messages. These are actual errors, such as PHP errors or user errors.
  2. +
  3. Debug Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info.
  4. +
  5. Informational Messages. These are the lowest priority messages, simply giving information regarding some process. Code Igniter doesn't natively generate any info messsages but you may want to in your application.
  6. +
+ + +

Note: In order for the log file to actually be written, the "log_errors" +option must be enabled in your application/config/config.php file, and the "logs" folder must be writable. +In addition, you'll can set the "threshold" for logging. +You might, for example, only want error messages to be logged, and not the other two types.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/helpers.html b/user_guide/general/helpers.html new file mode 100644 index 000000000..1bed4a8b0 --- /dev/null +++ b/user_guide/general/helpers.html @@ -0,0 +1,140 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Helper Functions

+ +

Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular +category. There are URL Helpers, that assist in creating links, there are Form Helpers +that help you create form elements, Text Helpers perform various text formatting routines, +Cookie Helpers set and read cookies, File Helpers help you deal with files, etc. +

+ +

Unlike most other systems in Code Igniter, Helpers are not written in an Object Oriented format. They are simple, procedural functions. +Each helper function performs one specific task, with no dependence on other functions.

+ +

Code Igniter does not load Helper Files by default, so the first step in using +a Helper is to load it. Once loaded, it becomes globally available in your controller and views.

+ +

Loading a Helper

+ +

Loading a helper file is quite simple using the following function:

+ +$this->load->helper('name'); + +

Where name is the file name of the helper, without the .php file extension or the "helper" part.

+ +

For example, to load the URL Helper file, which is named url_helper.php, you would do this:

+ +$this->load->helper('url'); + +

A helper can be loaded anywhere within your controller functions (or even within your View files, although that's not a good practice), +as long as you load it before you use it. You can load your helpers in your controller constructor so that they become available +automatically in any function, or you can load a helper in a specific function that needs it.

+ +

Note: The Helper loading function above does not return a value, so don't try to assign it to a variable. Just use it as shown.

+ + +

Loading Multiple Helpers

+ +

If you need to load more than one helper you can specify them in an array, like this:

+ +$this->load->helper( array('helper1', 'helper2', 'helper3') ); + +

Auto-loading Helpers

+ +

If you find that you need a particular helper globally throughout your application, you can tell Code Igniter to auto-load it during system initialization. +This is done by opening the application/config/autoload.php file and adding the helper to the autoload array.

+ + +

Using a Helper

+ +

Once you've loaded the Helper File containing the function you intend to use, you'll call it the way you would a standard PHP function.

+ +

For example, to create a link using the anchor() function in one of your view files you would do this:

+ +<?=anchor('blog/comments', 'Click Here');?> + +

Where "Click Here" is the name of the link, and "blog/comments" is the URI to the controller/function you wish to link to.

+ + +

Now What?

+ +

In the Table of Contents you'll find a list of all the available Helper Files. Browse each one to see what they do.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/hooks.html b/user_guide/general/hooks.html new file mode 100644 index 000000000..301654653 --- /dev/null +++ b/user_guide/general/hooks.html @@ -0,0 +1,184 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Hooks - Extending the Framework Core

+ +

Code Igniter's Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files. +When Code Igniter runs it follows a specific execution process, diagramed in the Application Flow page. +There may be instances, however, where you'd like to cause some action to take place at a particular stage in the execution process. +For example, you might want to run a script right before your controllers get loaded, or right after, or you might want to trigger one of +your own scripts in some other location. +

+ + +

Defining a Hook

+ +

Hooks are defined in application/config/hooks.php file. Each hook is specified as an array with this prototype:

+ + +$hook['pre_controller'] = array(
+                                'class'    => 'MyClass',
+                                'function' => 'Myfunction',
+                                'filename' => 'Myclass.php',
+                                'filepath' => 'hooks',
+                                'params'   => array('beer', 'wine', 'snacks')
+                                );
+ +

Notes:
The array index correlates to the name of the particular hook point you want to +use. In the above example the hook point is pre_controller. A list of hook points is found below. +The following items should be defined in your associative hook array:

+ + + + +

Multiple Calls to the Same Hook

+ +

If want to use the same hook point with more then one script, simply make your array declaration multi-dimensional, like this: + + +$hook['pre_controller'][] = array(
+                                'class'    => 'MyClass',
+                                'function' => 'Myfunction',
+                                'filename' => 'Myclass.php',
+                                'filepath' => 'hooks',
+                                'params'   => array('beer', 'wine', 'snacks')
+                                );
+
+$hook['pre_controller'][] = array(
+                                'class'    => 'MyOtherClass',
+                                'function' => 'MyOtherfunction',
+                                'filename' => 'Myotherclass.php',
+                                'filepath' => 'hooks',
+                                'params'   => array('red', 'yellow', 'blue')
+                                );
+ +

Notice the brackets after each array index:

+ +$hook['pre_controller'][] + +

This permits you to the same hook point with multiple scripts. The order you define your array will be the execution order.

+ + +

Hook Points

+ +The following is a list of available hook points.

+ + + + + + + + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/index.html b/user_guide/general/index.html new file mode 100644 index 000000000..31e99d53e --- /dev/null +++ b/user_guide/general/index.html @@ -0,0 +1,95 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Getting Started With Code Igniter

+ +

Any software application requires some effort to learn. We've done our best to minimize the learning +curve, while making the process as enjoyable as possible. +

+ +

The first step is to install Code Igniter, then read +all the topics in the Introduction section of the User Guide.

+ +

Next, read each of the General Topics pages in order. +Each topic builds on the previous one, and includes code examples that you are encouraged to try.

+ +

Once you understand the basics you'll be ready to explore the Class Reference and +Helper Reference pages to learn to utilize the native libraries and helper files.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/libraries.html b/user_guide/general/libraries.html new file mode 100644 index 000000000..642399ba9 --- /dev/null +++ b/user_guide/general/libraries.html @@ -0,0 +1,111 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Loading Libraries

+ +

The core libraries are the class files located in the "libraries" folder. +In most cases, to use one of these classes involves initializing it within your controllers using the following function:

+ +$this->load->library('class name'); + +

Where class name is the name of the class you want to invoke. For example, to load the validation class you would do this:

+ +$this->load->library('validation'); + +

Once initialized you can use it as indicated in the user guide page corresponding to each class.

+ +

Semantic Relevance

+ +

The pattern you will use when calling functions is this:

+ +

$this->class->function()

+ +

We've placed a high value on semantic relevance in the naming of our classes and functions. +Here are some examples of function calls you might use in Code Igniter:

+ +

$this->email->send()

+

$this->input->user_agent()

+

$this->benchmark->elapsed_time()

+

$this->db->query()

+

$this->load->helper()

+

$this->uri->segment()

+

$this->lang->line()

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/models.html b/user_guide/general/models.html new file mode 100644 index 000000000..dfb45d622 --- /dev/null +++ b/user_guide/general/models.html @@ -0,0 +1,256 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Models

+ +

Models are optionally available for those who want to use a more +traditional MVC approach.

+ + + + + + + +

What is a Model?

+ +

Models are PHP classes that are designed to work with information in your database. For example, let's say +you use Code Igniter to manage a blog. You might have a model class that contains functions to insert, update, and +retrieve your blog data. Here is an example of what such a model class might look like:

+ + +class Blogmodel extends Model {
+
+    var $title   = '';
+    var $content = '';
+    var $date    = '';
+
+    function Blogmodel()
+    {
+        // Call the Model constructor
+        parent::Model();
+    }
+    
+    function get_last_ten_entries()
+    {
+        $query = $this->db->get('entries', 10);
+        return $query->result();
+    }
+
+    function insert_entry()
+    {
+        $this->title   = $_POST['title'];
+        $this->content = $_POST['content'];
+        $this->date    = time();
+
+        $this->db->insert('entries', $this);
+    }
+
+    function update_entry()
+    {
+        $this->title   = $_POST['title'];
+        $this->content = $_POST['content'];
+        $this->date    = time();
+
+        $this->db->update('entries', $this, array('id', $_POST['id']));
+    }
+
+}
+ +

Note: The functions in the above example use the Active Record database functions.

+ + + +

Anatomy of a Model

+ +

Model classes are stored in your application/models/ folder. The basic prototype for a model is this:

+ + + +class Model_name extends Model {
+
+    function Model_name()
+    {
+        parent::Model();
+    }
+}
+ +

Where Model_name is the name of your class. Class names must be capitalized. +Make sure your class extends the base Model class.

+ +

The file name will be a lower case version of your class name. For example, if your class is this:

+ + +class User_model extends Model {
+
+    function User_model()
+    {
+        parent::Model();
+    }
+}
+ +

Your file will be this:

+ +application/models/user_model.php + + + +

Loading a Model

+ +

Your models will typically be loaded and called from within your controller functions. +To load a model you will use the following function:

+ +$this->load->model('Model_name'); + +

Once loaded, you will access your model functions using an object with the same name as your class:

+ + +$this->load->model('Model_name');
+
+$this->Model_name->function(); +
+ +

If you would like your model assigned to a different object name you can specify it via the second parameter of the loading +function:

+ + + +$this->load->model('Model_name', 'fubar');
+
+$this->fubar->function(); +
+ +

Here is an example of a controller, that loads a model, then serves a view:

+ + +class Blog_controller extends Controller {
+
+    function blog()
+    {
+        $this->load->model('Blog');
+
+        $data['query'] = $this->Blog->get_last_ten_entries();

+        $this->load->view('blog', $data);
+    }
+}
+ + + + +

Connecting to your Database

+ +

When a model is loaded it does NOT connect automatically to your database. The following options for connecting are available to you:

+ + + + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/multiple_apps.html b/user_guide/general/multiple_apps.html new file mode 100644 index 000000000..229349493 --- /dev/null +++ b/user_guide/general/multiple_apps.html @@ -0,0 +1,116 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Running Multiple Applications with one Code Igniter Installation

+ +

By default it is assumed that you only intend to use Code Igniter to manage one application, which you will build in your +system/application/ directory. It is possible, however, to have multiple sets of applications that share a single +Code Igniter installation. To do this you will put all of the directories located inside your application folder into their +own sub-folder.

+ +

For example, let's say you want to create two applications, "foo" and "bar". You will structure your +application folder like this: + +system/application/foo/
+system/application/foo/config/
+system/application/foo/controllers/
+system/application/foo/errors/
+system/application/foo/models/
+system/application/foo/scripts/
+system/application/foo/views/
+system/application/bar/
+system/application/bar/config/
+system/application/bar/controllers/
+system/application/bar/errors/
+system/application/bar/models/
+system/application/bar/scripts/
+system/application/bar/views/
+ + +

To select a particular application for use requires that you open your main index.php file and set the $application_folder +variable. For example, to select the "foo" application for use you would do this:

+ +$application_folder = "foo"; + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/plugins.html b/user_guide/general/plugins.html new file mode 100644 index 000000000..c28dd321f --- /dev/null +++ b/user_guide/general/plugins.html @@ -0,0 +1,125 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Plugins

+ +

Plugins work almost identically to Helpers. The main difference is that a plugin usually +provides a single function, whereas a Helper is usually a collection of functions. Helpers are also considerd a part of +the core system; plugins are intended to be created and shared by our community.

+ + +

Loading a Plugin

+ +

Loading a plugin file is quite simple using the following function:

+ +$this->load->plugin('name'); + +

Where name is the file name of the plugin, without the .php file extension or the "plugin" part.

+ +

For example, to load the Captcha plugin, which is named captcha_pi.php, you will do this:

+ +$this->load->plugin('captcha'); + +

A plugin can be loaded anywhere within your controller functions (or even within your View files, although that's not a good practice), +as long as you load it before you use it. You can load your plugins in your controller constructor so that they become available +automatically in any function, or you can load a plugin in a specific function that needs it.

+ +

Note: The Plugin loading function above does not return a value, so don't try to assign it to a variable. Just use it as shown.

+ + +

Loading Multiple Plugins

+ +

If you need to load more than one plugin you can specify them in an array, like this:

+ +$this->load->plugin( array('plugin1', 'plugin2', 'plugin3') ); + +

Auto-loading Plugins

+ +

If you find that you need a particular plugin globally throughout your application, you can tell Code Igniter to auto-load it +during system initialization. This is done by opening the application/config/autoload.php file and adding the plugin to the autoload array.

+ + +

Using a Plugin

+ +

Once you've loaded the Plugin, you'll call it the way you would a standard PHP function.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/quick_reference.html b/user_guide/general/quick_reference.html new file mode 100644 index 000000000..3e95fac6c --- /dev/null +++ b/user_guide/general/quick_reference.html @@ -0,0 +1,83 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Quick Reference Chart

+ +

For a PDF version of this chart, click here. + +

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/requirements.html b/user_guide/general/requirements.html new file mode 100644 index 000000000..8e18ab09a --- /dev/null +++ b/user_guide/general/requirements.html @@ -0,0 +1,88 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Server Requirements

+ + + + + +
+ + + + + + + + \ No newline at end of file diff --git a/user_guide/general/routing.html b/user_guide/general/routing.html new file mode 100644 index 000000000..c6e8bd9cf --- /dev/null +++ b/user_guide/general/routing.html @@ -0,0 +1,163 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

URI Routing

+ +

Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. +The segments in a URI normally follow this pattern:

+ +www.your-site.com/class/function/id/ + +

In some instances, however, you may want to remap this relationship so that a different class/function can be called +instead of the one corresponding to the URL.

+ +

For example, lets say you want your URLs to have this prototype:

+ +

+www.your-site.com/product/1/
+www.your-site.com/product/2/
+www.your-site.com/product/3/
+www.your-site.com/product/4/ +

+ +

Normally the second segment of the URL is reserved for the function name, but in the example above, it instead has a product ID. +To overcome this, Code Igniter allows you to remap the URI handler.

+ + +

Setting your own routing rules

+ +

Routing rules are defined in your application/config/routes.php file. In it you'll see an array called $route, that +you can use to specify your own routing criteria. A typical route might look something like this:

+ +$route['product/:num'] = "catalog/product_lookup"; + +

In a route, the array key contains the URI to be matched, while the array value contains the destination it should be re-routed to. +In the above example, if the literal word "product" is found in the first segment of the URL, and a number is found in the second segment, +the "catalog" class and the "product_lookup" method are instead used.

+ +

You can match literal values or you can use two wildcard types:

+ +

+:num
+:any +

+ +

:num will match a segment containing only numbers.
+:any will match a segment containing any character. +

+ +

Note: Routes will run in the order they are defined. +Higher routes will always take precedence over lower ones.

+ + +

Examples

+ +

Here are a few routing examples:

+ +$route['journals'] = "blogs"; +

Any URL containing the word "journals" in the first segment will be remapped to the "blogs" class.

+ +$route['blog/joe'] = "blogs/users/34"; +

Any URL containing the segments blog/joe will be remapped to the "blogs" class and the "users" method. The ID will be set to "34".

+ + +$route['product/:any'] = "catalog/product_lookup"; +

Any URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" class and the "product_lookup" method.

+ +

Important: Do not use leading/trailing slashes.

+ + +

Reserved Route

+ +

There are two reserved routes:

+ +$route['default_controller'] = 'welcome'; + +

This route indicates which controller class should be loaded if the URI contains no data, which will be the case +when people load your root URL. In the above example, the "welcome" class would be loaded. You +are encouraged to always have a default route otherwise a 404 page will appear by default.

+ +$route['scaffolding_trigger'] = 'scaffolding'; + +

This route lets you set a secret word, which when present in the URL, triggers the scaffolding feature. +Please read the Scaffolding page for details.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/scaffolding.html b/user_guide/general/scaffolding.html new file mode 100644 index 000000000..3b32c3692 --- /dev/null +++ b/user_guide/general/scaffolding.html @@ -0,0 +1,153 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Scaffolding

+ +

Code Igniter's Scaffolding feature provides a fast and very convenient way to add, edit, or delete information in your database +during development.

+ +

Very Important: Scaffolding is intended for development use only. It provides very little +security other than a "secret" word, so anyone who has access to your Code Igniter site can potentially edit or delete your information. +If you use scaffolding make sure you disable it immediately after you are through using it. DO NOT leave it enabled on a live site. +And please, set a secret word before you use it.

+ + +

Why would someone use scaffolding?

+ +

Here's a typical scenario: You create a new database table during development and you'd like a quick way to insert some data +into it to work with. Without scaffolding your choices are either to write some inserts using the command line or to use a +database management tool like phpMyAdmin. With Code Igniter's scaffolding feature you can quickly add some data using its browser +interface. And when you are through using the data you can easily delete it.

+ +

Setting a Secret Word

+ +

Before enabling scaffolding please take a moment to set a secret word. This word, when encountered in your URL, +will launch the scaffolding interface, so please pick something obscure that no one is likely to guess.

+ +

To set a secret word, open your application/config/routes.php file and look for this item:

+ +$route['scaffolding_trigger'] = ''; + +

Once you've found it add your own unique word.

+ +

Note: The scaffolding word can not start with an underscore.

+ + +

Enabling Scaffolding

+ +

Note: The information on this page assumes you already know how controllers work, and that you have +a working one available. It also assumes you have configured Code Igniter to auto-connect to your database. +If not, the information here won't be very relevant, so you are encouraged to go through those sections first. +Lastly, it assumes you understand what a class constructor is. If not, read the last section of the controllers +page.

+ +

To enable scaffolding you will initialize it in your constructor like this:

+ + +<?php
+class Blog extends Controller {
+
+       function Blog()
+       {
+            parent::Controller();

+            $this->load->scaffolding('table_name');
+       }
+}
+?>
+ +

Where table_name is the name of the table (table, not database) you wish to work with.

+ +

Once you've initialized scaffolding, you will access it with this URL prototype: + +www.your-site.com/index.php/class/secret_word/ + +

For example, using a controller named Blog, and abracadabra as the secret word, +you would access scaffolding like this:

+ +www.your-site.com/index.php/blog/abracadabra/ + +

The scaffolding interface should be self-explanatory. You can add, edit or delete records.

+ + +

A Final Note:

+ +

The scaffolding feature will only work with tables that contain a primary key, as this is information is needed to perform the various +database functions.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/scripts.html b/user_guide/general/scripts.html new file mode 100644 index 000000000..d0b5d26f6 --- /dev/null +++ b/user_guide/general/scripts.html @@ -0,0 +1,115 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

The Scripts Folder

+ +

Inside the application directory you'll find a folder called scripts. Its purpose is +to give you a place to store your own script includes or classes.

+ +

Loading a Script

+ +

Your scripts can be loaded in your controllers or views using the following function:

+ +$this->load->script('name'); + +

Where name is the file name of the script, without the .php file extension.

+ +

For example, to load a file called utilities.php you would do this:

+ +$this->load->script('utilities'); + +

If you load a script in your controller constructor it will be available +automatically in any function, or you can load it in a specific function that needs it.

+ +

Note: The Script loading function above does not return a value, so don't try to assign it to a variable. Just use it as shown.

+ +

Loading Multiple Scripts

+ +

If you need to load more than one script you can specify them in an array, like this:

+ +$this->load->script( array('script1', 'script2', 'script3') ); + +

Auto-loading Scripts

+ +

If you find that you need a particular script globally throughout your application, you can tell Code Igniter to auto-load it +during system initialization. This is done by opening the application/config/autoload.php file and adding +the script to the autoload array.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/security.html b/user_guide/general/security.html new file mode 100644 index 000000000..06287a23b --- /dev/null +++ b/user_guide/general/security.html @@ -0,0 +1,159 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Security

+ +

This page describes some "best practices" regarding web security, and details +Code Igniter's internal security features.

+ + +

URI Security

+ +

Code Igniter is fairly restrictive regarding which characters it allows in your URI strings in order to help +minimize the possibility that malicious data can be passed to your application. URIs may only contain the following: +

+ + + +

GET, POST, and COOKIE Data

+ +

GET data is simply disallowed by Code Igniter since the system utilizes URI segments rather than traditional URL query strings (unless +you have the query string option enabled in your config file). The global GET +array is unset by the Input class during system initialization.

+ +

Register_globals

+ +

During system initialization all global variables are unset, except those found in the $_POST and $_COOKIE arrays. The unsetting +routine is effectively the same as register_globals = off.

+ + +

magic_quotes_runtime

+ +

The magic_quotes_runtime directive is turned off during system initialization so that you don't have to remove slashes when +retrieving data from your database.

+ +


Best Practices

+ +

Before accepting any data into your application, whether it be POST data from a form submission, COOKIE data, URI data, +XML-RPC data, or even data from the SERVER array, you are encouraged to practice this three step approach:

+ +
    + +
  1. Filter the data as if it were tainted.
  2. +
  3. Validate the data to ensure it conforms to the correct type, length, size, etc. (sometimes this step can replace step one)
  4. +
  5. Escape the data before submitting it into your database.
  6. +
+ +Code Igniter provides the following functions to assist in this process:

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/urls.html b/user_guide/general/urls.html new file mode 100644 index 000000000..8daef51a6 --- /dev/null +++ b/user_guide/general/urls.html @@ -0,0 +1,159 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Code Igniter URLs

+ +

By default, URLs in Code Igniter are designed to be search-engine and human friendly. Rather than using the standard "query string" +approach to URLs that is synonymous with dynamic systems, Code Igniter uses a segment-based approach:

+ +www.your-site.com/news/article/my_article + +

Note: Query string URLs can be optionally enabled, as described below.

+ +

URI Segments

+ +

The segments in the URL, in following with the Model-View-Controller approach, usually represent:

+ +www.your-site.com/class/function/ID + +
    +
  1. The first segment represents the controller class that should be invoked.
  2. +
  3. The second segment represents the class function, or method, that should be called.
  4. +
  5. The third, and any additional segments, represent the ID and any variables that will be passed to the controller.

    +
+ +

The URI Class and the URL Helper +contain functions that make it easy to work with your URI data. In addition, your URLs can be remapped using the +URI Routing feature for more flexibility.

+ + + +

Removing the index.php file

+ +

By default, the index.php file will be included in your URLs: + +www.your-site.com/index.php/news/article/my_article + +

You can easily remove this file by using a .htaccess file with some simple rules. Here is an example + of such a file, using the "negative" method in which everything is redirected except the specified items:

+ +RewriteEngine on
+RewriteCond $1 !^(index\.php|images|robots\.txt)
+RewriteRule ^(.*)$ /index.php/$1 [L]
+ +

In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as +a request for your index.php file.

+ + +

Adding a URL Suffix

+ +

In your config/config.php file you can specify a suffix that will be added to all URLs generated +by Code Igniter. For example, if a URL is this: + +www.your-site.com/index.php/products/view/shoes + +

You can optionaally add a suffix, like .html, making the page appear to be of a certain type:

+ +www.your-site.com/index.php/products/view/shoes.html + + +

Enabling Query Strings

+ +

In some cases you might prefer to use query strings URLs:

+ +index.php?c=products&m=view&id=345 + +

Code Igniter optionally supports this capability, which can be enabled in your application/config.php file. If you +open your config file you'll see these items:

+ +$config['enable_query_strings'] = FALSE;
+$config['controller_trigger'] = 'c';
+$config['function_trigger'] = 'm';
+ +

If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then +be accessible using the "trigger" words you've set to invoke your controllers and methods:

+ +index.php?c=controller&m=method + +

Please note: If you are using query strings you will have to build your own URLs, rather than utilizing +the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with +segment based URLs.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/general/views.html b/user_guide/general/views.html new file mode 100644 index 000000000..14b03e58f --- /dev/null +++ b/user_guide/general/views.html @@ -0,0 +1,249 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Views

+ +

A view is simply a web page, or a page fragment, like a header, footer, sidebar, etc. +In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type +of hierarchy.

+ +

Views are never called directly, they must be loaded by a controller. Remember that in an MVC framework, the Controller acts as the +traffic cop, so it is responsible for fetching a particular view. If you have not read the Controllers page +you should do so before continuing.

+ +

Using the example controller you created in the controller page, let's add a view to it.

+ +

Creating a View

+ +

Using your text editor, create a file called blogview.php, and put this in it:

+ + + +

Then save the file in your application/views/ folder.

+ +

Loading a View

+ +

To load a particular view file you will use the following function:

+ +$this->load->view('name'); + +

Where name is the name of your view file, without the .php file extension.

+ +

Now, open the controller file you made earlier called blog.php, and replace the echo statement with the view loading function:

+ + + + + +

If you visit the your site using the URL you did earlier you should see your new view. The URL was similar to this:

+ +www.your-site.com/index.php/blog/ + + +

Adding Dynamic Data to the View

+ +

Data is passed from the controller to the view by way of an array or an object in the second +parameter of the view loading function. Here is an example using an array:

+ +$data = array(
+               'title' => 'My Title',
+               'heading' => 'My Heading'
+               'message' => 'My Message'
+          );
+
+$this->load->view('blogview', $data);
+ +

And here's an example using an object:

+ +$data = new Someclass();
+$this->load->view('blogview', $data);
+ +

Note: If you use an object, the class variables will be turned into array elements.

+ + +

Let's try it with your controller file. Open it add this code:

+ + + + +

Now open your view file and change the text to variables that correspond to the array keys in your data:

+ + + + +

Then load the page at the URL you've been using and you should see the variables replaced.

+ +

Note: Youl'll notice that in the example above we are using PHP's alternative syntax. If you +are not familiar with it you can read about it here.

+ +

Creating Loops

+ +

The data array you pass to your view files is not limited to simple variables. You can +pass multi dimensional arrays, which can be looped to generate multiple rows. For example, if you +pull data from your database it will typically be in the form of a multi-dimensional array.

+ +

Here's a simple example. Add this to your controller:

+ + + + +

Now open your view file and create a loop:

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/array_helper.html b/user_guide/helpers/array_helper.html new file mode 100644 index 000000000..d719be9c7 --- /dev/null +++ b/user_guide/helpers/array_helper.html @@ -0,0 +1,111 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Array Helper

+ +

The Array Helper file contains functions that assist in working with arrays.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('array'); + +

The following functions are available:

+ + +

random_element()

+ +

Takes an array as input and returns a random element from it. Usage example:

+ +$quotes = array(
+            "I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
+            "Don't stay in bed, unless you can make money in bed. - George Burns",
+            "We didn't lose the game; we just ran out of time. - Vince Lombardi",
+            "If everything seems under control, you're not going fast enough. - Mario Andretti",
+            "Reality is merely an illusion, albeit a very persistent one. - Albert Einstein",
+            "Chance favors the prepared mind - Louis Pasteur"
+            );
+
+echo random_element($quotes);
+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/cookie_helper.html b/user_guide/helpers/cookie_helper.html new file mode 100644 index 000000000..3152fc309 --- /dev/null +++ b/user_guide/helpers/cookie_helper.html @@ -0,0 +1,133 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Cookie Helper

+ +

The Cookie Helper file contains functions that assist in working with cookies.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('cookie'); + +

The following functions are available:

+ +

set_cookie()

+ +

Sets a cookie containing the values you specify. There are two ways to pass information this function so that a cookie can be set: +Arrray Method, and Discreet Parameters:

+ +

Array Method

+ +

Using this method, an associative array is passed to the first parameter:

+ +$cookie = array(
+                   'name'   => 'The Cookie Name',
+                   'value'  => 'The Value',
+                   'expire' => '86500',
+                   'domain' => '.some-domain.com',
+                   'path'   => '/',
+                   'prefix' => 'myprefix_',
+               );
+
+set_cookie($cookie); +
+ +

Notes:

+ +

Only the name and value are required.

+ +

The expiration is set in seconds, which will be added to the current time. Do not include the time, but rather only the +number of seconds from now that you wish the cookie to be valid. If the expiration is set to +zero the cookie will only last as long as the browser is open.

+

To delete a cookie set it with the expiration blank.

+

For site-wide cookies regardless of how your site is requested, add your URL to the domain starting with a period, like this: .your-domain.com

+

The path is usually not needed since the function sets a root path.

+

The prefix is only needed if you need to avoid name collisions with other identically named cookies for your server.

+ +

Discreet Parameters

+ +

If you prefer, you can set the cookie by passing data using individual parameters:

+ +set_cookie($name, $value, $expire, $domain, $path, $prefix); + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/date_helper.html b/user_guide/helpers/date_helper.html new file mode 100644 index 000000000..b25f249df --- /dev/null +++ b/user_guide/helpers/date_helper.html @@ -0,0 +1,340 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Date Helper

+ +

The Date Helper file contains functions that help you work with dates.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('date'); + + +

The following functions are available:

+ +

now()

+ +

Returns the current time as a Unix timestamp, referenced either to your server's local time or GMT, based on the "time reference" +setting in your config file. If you do not intend to set your master time reference to GMT (which you'll typically do if you +run a site that lets each user set their own timezone settings) there is no benefit to using this function over PHP's time() function. +

+ + + + +

mdate()

+ +

This function is identical to PHPs date() function, except that it lets you +use MySQL style date codes, where each code letter is preceded with a percent sign: %Y %m %d etc.

+ +

The benefit of doing dates this way is that you don't have to worry about escaping any characters that +are not date codes, as you would normally have to do with the date() function. Example:

+ +$datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";
+$time = time();
+
+echo mdate($datestring, $time);
+ +

If a timestamp is not included in the second parameter the current time will be used.

+ + +

local_to_gmt()

+ +

Takes a Unix timestamp as input and returns it as GMT. Example:

+ +$now = time();
+
+$gmt = local_to_gmt($now);
+ + +

gmt_to_local()

+ +

Takes a Unix timestamp (referenced to GMT) as input, and converts it to a localized timestamp based on the +timezone and Daylight Saving time submitted. Example:

+ + +$timestamp = '1140153693';
+$timezone = 'UM8';
+$daylight_saving = TRUE;
+
+echo gmt_to_local($timestamp, $timezone, daylight_saving);
+ +

Note: For a list of timezones see the reference at the bottom of this page.

+ +

mysql_to_unix()

+ +

Takes a MySQL Timestamp as input and returns it as Unix. Example:

+ +$mysql = '20061124092345';
+
+$unix = mysql_to_unix($mysql);
+ + +

unix_to_human()

+ +

Takes a Unix timestamp as input and returns it in a human readable format with this prototype:

+ +YYYY-MM-DD HH:MM:SS AM/PM + +

This can be useful if you need to display a date in a form field for submission.

+ +

The time can be formatted with or without seconds, and it can be set to European or US format. If only +the timestamp is submitted it will return the time without seconds formatted for the U.S. Examples: + +$now = time();
+
+echo unix_to_human($now); // U.S. time, no seconds
+
+echo unix_to_human($now, TRUE, 'us'); // U.S. time with seconds
+
+echo unix_to_human($now, TRUE, 'eu'); // Euro time with seconds
+ + +

human_to_unix()

+ +

The opposite of the above function. Takes a "human" time as input and returns it as Unix. This function is +useful if you accept "human" formatted dates submitted via a form. Returns FALSE (boolean) if +the date string passed to it is not formatted as indicated above. Example:

+ +$now = time();
+
+$human = unix_to_human($now);
+
+$unix = human_to_unix($human);
+ + + + + +

timespan()

+ +

Formats a unix timestamp so that is appears similar to this:

+ +1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes + +

The first parameter must contain a Unix timestamp. The second parameter must contain a +timestamp that is greater that the first timesamp. If the second parameter empty, the current time will be used. The most common purpose +for this function is to show how much time has elapsed from some point in time in the past to now. Example:

+ +$post_date = '1079621429';
+$now = time();
+
+echo timespan($post_date, $now);
+ +

Note: The text generated by this function is found in the following language file: language/<your_lang>/date_lang.php

+ + +

days_in_month()

+ +

Returns the number of days in a given month/year. Takes leap years into account. Example:

+echo days_in_month(06, 2005); + +

If the second parameter is empty, the current year will be used.

+ + + +

timezone_menu()

+ +

Generates a pull-down menu of timezones, like this one:

+ +
+ +
+ +

This menu is useful if you run a membership site in which your users are allowed to set their local timezone value.

+ +

The first paramater lets you set the "selected" state of the menu. For example, to set Pacific time as the default you will do this:

+ +echo timezone_menu('UM8'); + +

Please see the timezone reference below to see the values of this menu.

+ +

The second parameter lets you set a CSS class name for the menu.

+ +

Note: The text contained in the menu is found in the following language file: language/<your_lang>/date_lang.php

+ + + +

Timezone Reference

+ +

The following table indicates each timezone and its location.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Time ZoneLocation
UM12(UTC - 12:00) Enitwetok, Kwajalien
UM11(UTC - 11:00) Nome, Midway Island, Samoa
UM10(UTC - 10:00) Hawaii
UM9(UTC - 9:00) Alaska
UM8(UTC - 8:00) Pacific Time
UM7(UTC - 7:00) Mountain Time
UM6(UTC - 6:00) Central Time, Mexico City
UM5(UTC - 5:00) Eastern Time, Bogota, Lima, Quito
UM4(UTC - 4:00) Atlantic Time, Caracas, La Paz
UM25(UTC - 3:30) Newfoundland
UM3(UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is.
UM2(UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena
UM1(UTC - 1:00) Azores, Cape Verde Islands
(UTC(UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia
UP1(UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome
UP2(UTC + 2:00) Kaliningrad, South Africa, Warsaw
UP3(UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi
UP25(UTC + 3:30) Tehran
UP4(UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi
UP35(UTC + 4:30) Kabul
UP5(UTC + 5:00) Islamabad, Karachi, Tashkent
UP45(UTC + 5:30) Bombay, Calcutta, Madras, New Delhi
UP6(UTC + 6:00) Almaty, Colomba, Dhakra
UP7(UTC + 7:00) Bangkok, Hanoi, Jakarta
UP8(UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei
UP9(UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk
UP85(UTC + 9:30) Adelaide, Darwin
UP10(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok
UP11(UTC + 11:00) Magadan, New Caledonia, Solomon Islands
UP12(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island
+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/directory_helper.html b/user_guide/helpers/directory_helper.html new file mode 100644 index 000000000..803bb4ce0 --- /dev/null +++ b/user_guide/helpers/directory_helper.html @@ -0,0 +1,145 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + + +
+ + +
+ + + +
+ + +

Directory Helper

+ +

The Directory Helper file contains functions that assist in working with directories.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('directory'); + +

The following functions are available:

+ +

directory_map('source directory')

+ +

This function reads the directory path specified in the first parameter +and builds an array representation of it and all its contained files. Example:

+ +$map = directory_map('./mydirectory/'); + +

Note: Paths are almost always relative to your main index.php file.

+ + + +

Sub-folders contained within the directory will be mapped as well. If you wish to map +only the top level directory set the second parameter to true (boolean):

+ +$map = directory_map('./mydirectory/', TRUE); + +

Each folder name will be an array index, while its contained files will be numerically indexed. +Here is an example of a typical array:

+ +Array
+(
+   [libraries] => Array
+   (
+       [0] => benchmark.html
+       [1] => config.html
+       [database] => Array
+       (
+             [0] => active_record.html
+             [1] => binds.html
+             [2] => configuration.html
+             [3] => connecting.html
+             [4] => examples.html
+             [5] => fields.html
+             [6] => index.html
+             [7] => queries.html
+        )
+       [2] => email.html
+       [3] => file_uploading.html
+       [4] => image_lib.html
+       [5] => input.html
+       [6] => language.html
+       [7] => loader.html
+       [8] => pagination.html
+       [9] => uri.html
+)
+ + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/file_helper.html b/user_guide/helpers/file_helper.html new file mode 100644 index 000000000..c6b049b27 --- /dev/null +++ b/user_guide/helpers/file_helper.html @@ -0,0 +1,144 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

File Helper

+ +

The File Helper file contains functions that assist in working with files.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('file'); + +

The following functions are available:

+ +

read_file('path')

+ +

Returns the data contained in the file specified in the path. Example:

+ +$string = read_file('./path/to/file.php'); + +

The path can be a relative or full server path. Returns FALSE (boolean) on failure.

+ +

Note: The path is relative to your main site index.php file, NOT your controller or view files. +Code Igniter uses a front controller so paths are always relative to the main site index.

+ +

If you server is running an open_basedir restriction this function +might not work if you are trying to access a file above the calling script.

+ +

write_file('path', $data)

+ +

Writes data to the file specified in the path. If the file does not exist the function will create it. Example:

+ + +$data = 'Some file data';
+
+if ( ! write_file('./path/to/file.php', $data))
+{
+     echo 'Unable to write the file';
+}
+else
+{
+     echo 'File written!';
+}
+ +

Note: In order for this function to write data to a file its file permissions must be set such that it is writable (666, 777, etc.). +If the file does not already exist, the directory containing it must be writable.

+ +

Note: The path is relative to your main site index.php file, NOT your controller or view files. +Code Igniter uses a front controller so paths are always relative to the main site index.

+ + + +

delete_files('path')

+ +

Deletes ALL files contained in the supplied path. Example:

+delete_files('/path/to/directory/'); + +

If the second parameter is set to true, any directories contained within the supplied root path will be deleted as well. Example:

+ +delete_files('/path/to/directory/', TRUE); + +

Note: The files must be writable or owned by the system in order to be deleted.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/form_helper.html b/user_guide/helpers/form_helper.html new file mode 100644 index 000000000..8593f81d9 --- /dev/null +++ b/user_guide/helpers/form_helper.html @@ -0,0 +1,343 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Form Helper

+ +

The Form Helper file contains functions that assist in working with forms.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('form'); + +

The following functions are available:

+ + + +

form_open()

+ +

Creates an opening form tag with a base URL built from your config preferences. It will optionally let you +add form attributes and hidden input fields.

+ +

The main benefit of using this tag rather than hard coding your own HTML is that it permits your site to be more portable +in the event your URLs ever change.

+ +

Here's a simple example:

+ +echo form_open('email/send'); + +

The above example would create a form that points to your base URL plus the "email/send" URI segments, like this:

+ +<form method="post" action="http:/www.your-site.com/index.php/email/send" /> + +

Adding Attributes

+ +

Attributes can be added by passing an associative array to the second parameter, like this:

+ + +$attributes = array('class' => 'email', 'id' => 'myform');
+
+echo form_open('email/send', $attributes);
+ +

The above example would create a form similar to this:

+ +<form method="post" action="http:/www.your-site.com/index.php/email/send"  class="email"  id="myform" /> + +

Adding Hidden Input Fields

+ +

Hidden fields can be added by passing an associative array to the third parameter, like this:

+ + +$hidden = array('username' => 'Joe', 'member_id' => '234');
+
+echo form_open('email/send', '', $hidden);
+ +

The above example would create a form similar to this:

+ +<form method="post" action="http:/www.your-site.com/index.php/email/send"  class="email"  id="myform" />
+<input type="hidden" name="username" value="Joe" />
+<input type="hidden" name="member_id" value="234" />
+ + +

form_open_multipart()

+ +

This function is absolutely identical to the form_open() tag above except that it adds a multipart attribute, +which is necessary if you would like to use the form to upload files with.

+ +

form_hidden()

+ +

Lets you generate hidden input fields. You can either submit a name/value string to create one field:

+ +form_hidden('username', 'johndoe');
+
+// Would produce:

+<input type="hidden" name="username" value="johnodoe" />
+ +

Or you can submit an associative array to create multiple fields:

+ +$data = array(
+              'name'  => 'John Doe',
+              'email' => 'john@some-site.com',
+              'url'   => 'http://www.some-site.com'
+            );
+
+echo form_hidden($data);
+
+// Would produce:

+<input type="hidden" name="name" value="John Doe" />
+<input type="hidden" name="email" value="john@some-site.com" />
+<input type="hidden" name="url" value="http://www.some-site.com" />
+ + + + +

form_input()

+ +

Lets you generate a standard text input field. You can minimally pass the field name and value in the first +and second parameter: + +echo form_input('username', 'johndoe'); + +

Or you can pass an associative array containing any data you wish your form to contain:

+ +$data = array(
+              'name'        => 'username',
+              'id'          => 'username',
+              'value'       => 'johndoe',
+              'maxlength'   => '100',
+              'size'        => '50',
+              'style'       => 'width:50%',
+            );
+
+echo form_input($data);
+
+// Would produce:

+<input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" />
+ +

If you would like your form to contain some additional data, like JavaScript, you can pass it as a string in the +third parameter: + +$js = 'onClick="some_function()"';
+
+echo form_input('username', 'johndoe', $js);
+ +

form_password()

+ +

This function is identical in all respects to the form_input() function above +except that is sets it as a "password" type.

+ +

form_upload()

+ +

This function is identical in all respects to the form_input() function above +except that is sets it as a "file" type, allowing it to be used to upload files.

+ +

form_textarea()

+ +

This function is identical in all respects to the form_input() function above +except that it generates a "textarea" type. Note: Instead of the "maxlength" and "size" attributes in the above +example, you will instead specify "rows" and "cols".

+ + +

form_dropdown()

+ +

Lets you create a standard drop-down field. The first parameter will contain the name of the field, +the second parameter will contain an associative array of options, and the third parameter will contain the +value you wish to be selected. Example: + +$options = array(
+                  'small'  => 'Small Shirt',
+                  'med'    => 'Medium Shirt',
+                  large'   => 'Large Shirt',
+                  'xlarge' => 'Extra Large Shirt',
+                );
+
+echo form_dropdown('shirts', $options, 'large');
+
+// Would produce:

+ +<select name="shirts">
+<option value="small">Small Shirt
+<option value="med">Medium Shirt
+<option value="large" selected>Large Shirt
+<option value="xlarge">Extra Large Shirt
+</select>
+ + +

If you would like the opening <select> to contain additional data, like JavaScript, you can pass it as a string in the +fourth parameter: + +$js = 'onChange="some_function()"';
+
+echo form_dropdown('shirts', $options, 'large', $js);
+ + +

form_checkbox()

+ +

Lets you generate a checkbox field. Simple example: + + +echo form_checkbox('newsletter', 'accept', TRUE);
+
+// Would produce:
+
+<input type="checkbox" name="newsletter" value="accept" checked="checked" />
+ +

The third parameter contains a boolean TRUE/FALSE to determine whether the box should be checked or not.

+ +

Similar to the other form functions in this helper, you can also pass an array of attributes to the function:

+ +$data = array(
+              'name'        => 'newsletter',
+              'id'          => 'newsletter',
+              'value'       => 'accept',
+              'checked'     => TRUE,
+              'style'       => 'margin:10px',
+            );
+
+echo form_checkbox($data);
+
+// Would produce:

+<input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" />
+ +

As with other functions, if you would like the tag to contain additional data, like JavaScript, you can pass it as a string in the +fourth parameter: + +$js = 'onClick="some_function()"';
+
+echo echo form_checkbox('newsletter', 'accept', TRUE, $js)
+ + +

form_radio()

+

This function is identical in all respects to the form_checkbox() function above except that is sets it as a "radio" type.

+ + +

form_submit()

+ +

Lets you generate a standard submit button. Simple example:

+ +echo form_submit('mysubmit', 'Submit Post!');
+
+// Would produce:
+
+<input type="submit" name="mysubmit" value="Submit Post!" />
+ +

Similar to other functions, you can submit an associative array in the first parameter if you prefer to set your own attributes. +The third parameter lets you add extra data to your form, like JavaScript.

+ + +

form_close()

+ +

Produces a closing </form> tag. The only advantage to using this function is it permits you to pass data to it +which will be added below the tag. For example:

+ +$string = "</div></div>";
+
+echo form_close($string);
+
+// Would produce:
+
+</form>
+</div></div>
+ + + + + +

form_prep()

+ +

Allows you to safely use HTML and characters such as quotes within form elements without breaking out of the form. Consider this example:

+ +$string = 'Here is a string containing "quoted" text.';
+
+<input type="text" name="myform" value="$string" />
+ +

Since the above string contains a set of quotes it will cause the form to break. +The form_prep function converts HTML so that it can be used safely:

+ +<input type="text" name="myform" value="<?php echo form_prep($string); ?>" /> + +

Note: If you use any of the form helper functions listed in this page the form +values will be prepped automatically, so there is no need to call this function. Use it only if you are +creating your own form elements.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/html_helper.html b/user_guide/helpers/html_helper.html new file mode 100644 index 000000000..603b83aa8 --- /dev/null +++ b/user_guide/helpers/html_helper.html @@ -0,0 +1,117 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

HTML Helper

+ +

The HTML Helper file contains functions that assist in working with HTML.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('html'); + +

The following functions are available:

+ + +

heading()

+ +

Lets you create HTML <h1> tags. The first parameter will contain the data, the +second the size of the heading. Example:

+ +echo heading('Welcome!', 3); + +

The above would produce: <h3>Welcome!</h3>

+ + +

nbs()

+

Generates non-breaking spaces (&nbsp;) based on the number you submit. Example:

+echo nbs(3); +

The above would produce: &nbsp;&nbsp;&nbsp;

+ + +

br()

+

Generates line break tags (<br />) based on the number you submit. Example:

+echo br(3); +

The above would produce: <br /><br /><br />

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/index.html b/user_guide/helpers/index.html new file mode 100644 index 000000000..342549d33 --- /dev/null +++ b/user_guide/helpers/index.html @@ -0,0 +1,131 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Helper Functions

+ +

Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular +category. There are URL Helpers, that assist in creating links, there are Form Helpers +that help you create form elements, Text Helpers perform various text formatting routines, +Cookie Helpers set and read cookies, File Helpers help you deal with files, etc. +

+ +

Unlike most other systems in Code Igniter, Helpers are not written in an Object Oriented format. They are simple, procedural functions. +Each helper function performs one specific task, with no dependence on other functions.

+ +

Helpers are intentionally kept very simple so that they can be used within your View Files with a minimal amount of code. +This is important if you intend to have designers or non-programmer will be working with your view files, since it keeps the code to a minimum. +

+ +

Code Igniter does not load Helper Files by default, so the first step in using +a Helper is to load it. Once loaded, it becomes globally available in your controller and views.

+ +

Loading a Helper

+ +

Loading a helper file is quite simple using the following function:

+ +$this->load->helper('name'); + +

Where name is the file name of the helper, without the .php file extension or the "helper" part.

+ +

For example, to load the URL Helper file, which is named url_helper.php, you would do this:

+ +$this->load->helper('url'); + +

A helper can be loaded anywhere within your controller functions (or even within your View files, although that's not a good practice), +as long as you load it before you use it. You can load your helpers in your controller constructor so that they become available +automatically in any function, or you can load a helper in a specific function that needs it.

+ +

Note: The Helper loading function above does not return a value, so don't try to assign it to a variable. Just use it as shown.

+ +

Auto-loading Helpers

+ +

If you find that you need a particular helper globally throughout your application, you can tell Code Igniter to auto-load it during system initialization. +This is done by opening the application/config/autoload.php file and adding the helper to the autoload array.

+ + +

Using a Helper

+ +

Once you've loaded the Helper File containing the function you intend to use, you'll call it the way you would a standard PHP function.

+ +

For example, to create a link using the anchor() function in one of your view files you would do this:

+ +<?=anchor('blog/comments', 'Click Here');?> + +

Where "Click Here" is the name of the link, and "blog/comments" is the URI to the controller/function you wish to link to.

+ + +

Now What?

+ +

In the Table of Contents you'll find a list of all the available Helper Files. Browse each one to see what they do.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/security_helper.html b/user_guide/helpers/security_helper.html new file mode 100644 index 000000000..7649fe779 --- /dev/null +++ b/user_guide/helpers/security_helper.html @@ -0,0 +1,131 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Security Helper

+ +

The Security Helper file contains security related functions.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('security'); + +

The following functions are available:

+ + +

xss_clean()

+ +

Provides Cross Site Script Hack filtering. This function is an alias to the the one in the +Input class. More info can be found there.

+ + +

hash()

+ +

Permits you to create SHA1 or MD5 one way hashes suitable for encrypting passwords. Will create SHA1 by default. Examples:

+ + +$str = hash($str); // SHA1
+
+$str = hash($str, 'md5'); // MD5 +
+ + + + +

strip_image_tags()

+ +

This is a security function that will strip image tags from a string. It leaves the image URL as plain text.

+ +$string = strip_image_tags($string); + + +

encode_php_tags()

+ +

This is a security function that converts PHP tags to entities. Note: If you use the XSS filtering function it does this automatically.

+ +$string = encode_php_tags($string); + + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/string_helper.html b/user_guide/helpers/string_helper.html new file mode 100644 index 000000000..dfe8ae7d6 --- /dev/null +++ b/user_guide/helpers/string_helper.html @@ -0,0 +1,144 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

String Helper

+ +

The String Helper file contains functions that assist in working with strings.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('string'); + +

The following functions are available:

+ +

random_string()

+ +

Generates a random string based on the type and length you specify. Useful for creating passwords or generating random hashes.

+ +

The first parameter specifies the type of string, the second parameter specifies the length. The following choices are available:

+ + + + +

Usage example:

+ +echo random_string('alnum', 16); + + +

alternator()

+ +

Allows two or more items to be alternated between, when cycling through a loop. Example: + +for ($i = 0; $i < 10; $i++)
+{
+    echo alternator('string one', 'string two');
+}
+
+ +

You can add as many parameters as you want, and with each each iteration of your loop the next item will be returned.

+ +for ($i = 0; $i < 10; $i++)
+{
+    echo alternator('one', 'two', 'three', 'four', 'five');
+}
+
+ +

Note: To use multiple separate calls to this function simply call the function with no arguments to re-initialize.

+ + + +

repeater()

+

Generates repeating copies of the data you submit. Example:

+$string = "\n";
+echo repeater($string, 30);
+ +

The above would generate 30 newlines.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/text_helper.html b/user_guide/helpers/text_helper.html new file mode 100644 index 000000000..61de8ea43 --- /dev/null +++ b/user_guide/helpers/text_helper.html @@ -0,0 +1,197 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Text Helper

+ +

The Text Helper file contains functions that assist in working with text.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('text'); + +

The following functions are available:

+ + +

word_limiter()

+ +

Truncates a string to the number of words specified. Example:

+ + +$str = "Here is a nice text string consisting of eleven words.";
+
+$string = word_limiter($string, 4);

+ +// Returns: Here is a nice… +
+ +

The third parameter is an optional suffix added to the string. By default it add an ellipsis.

+ + +

character_limiter()

+ +

Truncates a string to the number of characters specified. It maintains the integrity +of words so the character count may be slightly more or less then what you specify. Example:

+ + +$str = "Here is a nice text string consisting of eleven words.";
+
+$string = char_limiter($string, 20);

+ +// Returns: Here is a nice text string… +
+ +

The third parameter is an optional suffix added to the string. By default it add an ellipsis.

+ + + +

ascii_to_entities()

+ +

Converts ASCII values to character entities, including high ASCII and MS Word characters that can cause problems when used in a web page, +so that they can be shown consistently regardless of browser settings or stored reliably in a database. +There is some dependance on your server's supported character sets, so it may not be 100% reliable in all cases, but for the most +part it should correctly identify characters outside the normal range (like accented characters). Example:

+ +$string = ascii_to_entities($string); + + +

entities_to_ascii()

+ +

This function does the opposite of the previous one; it turns character entities back into ASCII.

+ + +

word_censor()

+ +

Enables you to censor words within a text string. The first parameter will contain the original string. The +second will contain an array of words which you disallow. The third (optional) parameter can contain a replacement value +for the words. If not specified they are replaced with pound signs: ####. Example:

+ + +$disallowed = array('darn', 'shucks', 'golly', 'phooey');
+
+$string = word_censor($string, $disallowed, 'Beep!');
+ + +

highlight_code()

+ +

Colorizes a string of code (PHP, HTML, etc.). Example:

+ +$string = highlight_code($string); + +

The function uses PHP's highlight_string() function, so the colors used are the ones specified in your php.ini file.

+ + +

highlight_phrase()

+ +

Will highlight a phrase within a text string. The first parameter will contain the original string, the second will +contain the phrase you wish to highlight. The third and fourth parameters will contain the opening/closing HTML tags +you would like the phrase wrapped in. Example:

+ + +$str = "Here is a nice text string about nothing in particular.";
+
+$string = highlight_phrase($string, "nice text", '<span style="color:#990000">', '</span>'); +
+ +

The above text returns:

+ +

Here is a nice text string about nothing in particular.

+ + + +

word_wrap()

+ +

Wraps text at the specified character count while maintaining complete words. Example:

+ +$string = "Here is a simple string of text that will help us demonstrate this function.";
+
+echo word_wrap($string, 25);
+
+// Would produce:
+
+Here is a simple string
+of text that will help
+us demonstrate this
+function
+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/typography_helper.html b/user_guide/helpers/typography_helper.html new file mode 100644 index 000000000..5e8da4bab --- /dev/null +++ b/user_guide/helpers/typography_helper.html @@ -0,0 +1,129 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Typography Helper

+ +

The Typography Helper file contains functions that help your format text in semantically relevant ways.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('typography'); + +

The following functions are available:

+ + +

auto_typography()

+ +

Formats text so that it is semantically and typographically correct HTML. Takes a string as input and returns it with +the following formatting:

+ + + +

Usage example:

+ +$string = auto_typography($string); + +

Note: Typographic formatting can be processor intensive, particularly if you have a lot of content being formatted. +If you choose to use this function you may want to consider +caching your pages.

+ + +

nl2br_except_pre()

+ +

Converts newlines to <br /> tags unless they appear within <pre> tags. +This function is identical to the native PHP nl2br() function, except that it ignores <pre> tags.

+ +

Usage example:

+ +$string = nl2br_except_pre($string); + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/url_helper.html b/user_guide/helpers/url_helper.html new file mode 100644 index 000000000..a8f5c14d6 --- /dev/null +++ b/user_guide/helpers/url_helper.html @@ -0,0 +1,269 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

URL Helper

+ +

The URL Helper file contains functions that assist in working with URLs.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('url'); + +

The following functions are available:

+ +

site_url()

+ +

Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your +site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function.

+ +

You are encouraged to use this function any time you need to generate a local URL so that your pages become more portable +in the event your URL changes.

+ +

Segments can be optionally passed to the function as a string or an array. Here is a string example:

+ +echo site_url("news/local/123"); + +

The above example would return something like: http://www.your-site.com/index.php/news/local/123

+ +

Here is an example of segments passed as an array:

+ + +$segments = array('news', 'local', '123');
+
+echo site_url($segments);
+ + +

base_url()

+

Returns your site base URL, as specified in your config file. Example:

+echo base_url(); + + +

index_page()

+

Returns your site "index" page, as specified in your config file. Example:

+echo index_page(); + + + +

anchor()

+ +

Creates a standard HTML anchor link based on your local site URL:

+ +<a href="http://www.your-site.com">Click Here</a> + +

The tag has three optional parameters:

+ +anchor(uri segments, text, attributes) + +

The first parameter can contain any segments you wish appended to the URL. As with the site_url() function above, +segments can be a string or an array. Note: Do not include the base URL. It will be built as specified in your config file. Include +only the URI segments you wish appended to the URL.

+ +

The second segment is the text you would like the link to say. If you leave it blank, the URL will be used.

+ +

The third parameter can contain a list of attributes you would like added to the link. The attributes can be a simple string or an associative array.

+ +

Here are some examples:

+ +echo anchor(news/local/123, My News); + +

Would produce: <a href="http://www.your-site.com/index.php/news/local/123" title="My News">My News</a>

+ +echo anchor(news/local/123, My News, array('title' => 'The best news!')); + +

Would produce: <a href="http://www.your-site.com/index.php/news/local/123" title="The best news!">My News</a>

+ + +

anchor_popup()

+ +

Nearly identical to the anchor() function except that it opens the URL in a new window. + +You can specify JavaScript window attributes in the third parameter to control how the window is opened. If +the third parameter is not set it will simply open a new window with your own browser settings. Here is an example +with attributes:

+ + + +$atts = array(
+              'width'      => '800',
+              'height'     => '600',
+              'scrollbars' => 'yes',
+              'status'     => 'yes',
+              'resizable'  => 'yes',
+              'screenx'    => '0',
+              'screeny'    => '0'
+            );
+
+echo anchor_popup(news/local/123, 'Click Me!', $atts);
+ +

Note: The above attributes are the function defaults so you only need to set the ones that are different from what you need. +If you want the function to use all of its defaults simply pass an empty array in the third parameter:

+ +echo anchor_popup(news/local/123, 'Click Me!', array()); + + +

mailto()

+ +

Creates a standard HTML email link. Usage example:

+ +echo mailto('me@my-site.com', 'Click Here to Contact Me'); + +

As with the anchor() tab above, you can set attributes using the third parameter.

+ + +

safe_mailto()

+ +

Identical to the above function except it writes an obfuscated version of the mailto tag using ordinal numbers +written with JavaScript to help prevent the email address from being harvested by spam bots.

+ + +

auto_link()

+ +

Automatically turns URLs and email addresses contained in a string into links. Example:

+ +$string = auto_link($string); + +

The second parameter determines whether URLs and emails are converted or just one or the other. Default behavior is both +if the parameter is not specified

+ +

Converts only URLs:

+$string = auto_link($string, 'url'); + +

Converts only Email addresses:

+$string = auto_link($string, 'email'); + +

The third parameter determines whether links are shown in a new window. The value can be TRUE or FALSE (boolean):

+$string = auto_link($string, 'both', TRUE); + + +

url_title()

+

Takes a string as input and creates a human-friendly URL string. This is useful if, for example, you have a blog +in which you'd like to use the title of your entries in the URL. Example:

+ +$title = "What's wrong with CSS?";
+
+$url_title = url_title($title);
+
+// Produces: whats-wrong-with-css +
+ + +

The second parameter determines the word delimiter. By default dashes are used. Options are: dash, or underscore:

+ +$title = "What's wrong with CSS?";
+
+$url_title = url_title($title, 'underscore');
+
+// Produces: whats_wrong_with_css +
+ + +

prep_url()

+

This function will add http:// in the event it is missing from a URL. Pass the URL string to the function like this:

+ +$url = "www.some-site.com";

+$url = prep_url($url);
+ + + + +

redirect()

+ +

Does a "header redirect" to the local URI specified. Just like other functions in this helper, this one is designed +to redirect to a local URL within your site. You will not specify the full site URL, but rather simply the URI segments +to the controller you want to direct to. The function will build the URL based on your config file values.

+ +

The second parameter allows you to choose between the "location" +method or the "refresh" method. Location is faster, but on Windows servers it can sometimes be a problem. Example:

+ +if ($logged_in == FALSE)
+{
+     redirect('/login/form/', 'refresh');
+}
+ +

Note: In order for this function to work it must be used before anything is outputted +to the browser since it utilizes server headers.

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/helpers/xml_helper.html b/user_guide/helpers/xml_helper.html new file mode 100644 index 000000000..63e2b73cd --- /dev/null +++ b/user_guide/helpers/xml_helper.html @@ -0,0 +1,110 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

XML Helper

+ +

The XML Helper file contains functions that assist in working with XML data.

+ + +

Loading this Helper

+ +

This helper is loaded using the following code:

+$this->load->helper('xml'); + +

The following functions are available:

+ +

xml_convert('string')

+ +

Takes a string as input and converts the following reserved XML characters to entities:

+ +

+Ampersands: &
+Less then and greater than characters: < >
+Single and double quotes: '  "
+Dashes: -

+ +

This function ignores ampersands if they are part of existing character entities. Example:

+ +$string = xml_convert($string); + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/images/appflowchart.gif b/user_guide/images/appflowchart.gif new file mode 100644 index 000000000..422332c9e Binary files /dev/null and b/user_guide/images/appflowchart.gif differ diff --git a/user_guide/images/arrow.gif b/user_guide/images/arrow.gif new file mode 100644 index 000000000..9e9c79a79 Binary files /dev/null and b/user_guide/images/arrow.gif differ diff --git a/user_guide/images/ci_logo.jpg b/user_guide/images/ci_logo.jpg new file mode 100644 index 000000000..3ae0eee07 Binary files /dev/null and b/user_guide/images/ci_logo.jpg differ diff --git a/user_guide/images/ci_logo_mini.jpg b/user_guide/images/ci_logo_mini.jpg new file mode 100644 index 000000000..e9f79b5c8 Binary files /dev/null and b/user_guide/images/ci_logo_mini.jpg differ diff --git a/user_guide/images/ci_quick_ref.png b/user_guide/images/ci_quick_ref.png new file mode 100644 index 000000000..c07d6b469 Binary files /dev/null and b/user_guide/images/ci_quick_ref.png differ diff --git a/user_guide/images/file.gif b/user_guide/images/file.gif new file mode 100644 index 000000000..8141e0357 Binary files /dev/null and b/user_guide/images/file.gif differ diff --git a/user_guide/images/folder.gif b/user_guide/images/folder.gif new file mode 100644 index 000000000..fef31a60b Binary files /dev/null and b/user_guide/images/folder.gif differ diff --git a/user_guide/images/nav_bg.jpg b/user_guide/images/nav_bg.jpg new file mode 100644 index 000000000..440e04ddb Binary files /dev/null and b/user_guide/images/nav_bg.jpg differ diff --git a/user_guide/images/nav_separator.jpg b/user_guide/images/nav_separator.jpg new file mode 100644 index 000000000..3f8b15121 Binary files /dev/null and b/user_guide/images/nav_separator.jpg differ diff --git a/user_guide/images/nav_toggle.jpg b/user_guide/images/nav_toggle.jpg new file mode 100644 index 000000000..531bc2635 Binary files /dev/null and b/user_guide/images/nav_toggle.jpg differ diff --git a/user_guide/images/transparent.gif b/user_guide/images/transparent.gif new file mode 100644 index 000000000..b7406476a Binary files /dev/null and b/user_guide/images/transparent.gif differ diff --git a/user_guide/index.html b/user_guide/index.html new file mode 100644 index 000000000..b0f4bfa3a --- /dev/null +++ b/user_guide/index.html @@ -0,0 +1,106 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + +
+ + + +
+ +
+ + + +
+ + + +

Welcome to Code Igniter

+ +

Code Igniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. +Its goal is to enable you to develop projects must faster than you could if you were writing code +from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and +logical structure to access these libraries. Code Igniter lets you creatively focus on your project by +minimizing the amount of code needed for a given task.

+ +

Please read the Introduction section of the User Guide to learn the broad concepts behind Code Igniter, +then read the Getting Started page.

+ + +

Who is Code Igniter For?

+ +

Code Igniter is right for you if:

+ + + + +
+ + + + + + + + + \ No newline at end of file diff --git a/user_guide/installation/downloads.html b/user_guide/installation/downloads.html new file mode 100644 index 000000000..df8878458 --- /dev/null +++ b/user_guide/installation/downloads.html @@ -0,0 +1,97 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Downloading Code Igniter

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/index.html b/user_guide/installation/index.html new file mode 100644 index 000000000..15e7925bd --- /dev/null +++ b/user_guide/installation/index.html @@ -0,0 +1,116 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Installation Instructions

+ +

Code Igniter is installed in four steps:

+ +
    +
  1. Unzip the package.
  2. +
  3. Upload the Code Igniter folders and files to your server. Normally the index.php file will be at your root.
  4. +
  5. Open the application/config/config.php file with a text editor and set your base URL.
  6. +
  7. If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.
  8. +
+ +

If you wish to increase security by hiding the location of your Code Igniter files you can rename the system folder +to something more private. If you do rename it, you must open your main index.php file and set the $system_folder +variable at the top of the page with the new name you've chosen.

+ +

That's it!

+ +

If you're new to Code Igniter, please read the Getting Started section of the User Guide to begin learning how +to build dynamic PHP applications. Enjoy!

+ +

Troubleshooting

+ +

If you find that no matter what you put in your URL only your default page is loading, it might be that your server +does not support the PATH_INFO variable needed to serve search-engine friendly URLs. + +As a first step, open your application/config/config.php file and look for the URI Protocol +information. It will recommend that you try a couple alternate settings. If it still doesn't work after you've tried this you'll need +to force Code Igniter to add a question mark to your URLs. To do this open your application/config/config.php file and change this:

+ +$config['index_page'] = "index.php"; + +

To this:

+ +$config['index_page'] = "index.php?"; + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrade_120.html b/user_guide/installation/upgrade_120.html new file mode 100644 index 000000000..28ee83cba --- /dev/null +++ b/user_guide/installation/upgrade_120.html @@ -0,0 +1,98 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading From Beta 1.0 to Final 1.2

+ +

To upgrade to Version 1.2 please replace the following directories with the new versions:

+ +

Note: If you have any custom developed files in these folders please make copies of them first.

+ + + +

Please also replace your local copy of the user guide with the new version.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrade_130.html b/user_guide/installation/upgrade_130.html new file mode 100644 index 000000000..41de13e75 --- /dev/null +++ b/user_guide/installation/upgrade_130.html @@ -0,0 +1,209 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading from 1.2 to 1.3

+ +

Note: The instructions on this page assume you are running version 1.2. If you +have not upgraded to that version please do so first.

+ + +

Before performing an update you should take your site offline by replacing the index.php file +with a static one.

+ + +

Step 1: Update your Code Igniter files

+ +

Replace the following directories in your "system" folder with the new versions:

+ +

Note: If you have any custom developed files in these folders please make copies of them first.

+ + + + +

Step 2: Update your error files

+ +

Version 1.3 contains two new error templates located in application/errors, and for naming consistency the other error templates have +been renamed.

+ +

If you have not customized any of the error templates simply +replace this folder:

+ + + +

If you have customized your error templates, rename them as follows:

+ + + + + +

Step 3: Update your index.php file

+ +

Please open your main index.php file (located at your root). At the very bottom of the file, change this:

+ +require_once BASEPATH.'libraries/Front_controller'.EXT; + +

To this:

+ +require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; + + +

Step 4: Update your config.php file

+ +

Open your application/config/config.php file and add these new items:

+ +
+/*
+|------------------------------------------------
+| URL suffix
+|------------------------------------------------
+|
+| This option allows you to add a suffix to all URLs.
+| For example, if a URL is this:
+|
+| www.your-site.com/index.php/products/view/shoes
+| 
+| You can optionally add a suffix, like ".html",
+| making the page appear to be of a certain type:
+|
+| www.your-site.com/index.php/products/view/shoes.html
+|
+*/
+$config['url_suffix'] = "";
+
+
+/*
+|------------------------------------------------
+| Enable Query Strings
+|------------------------------------------------
+|
+| By default Code Igniter uses search-engine and 
+| human-friendly segment based URLs:
+|
+| www.your-site.com/who/what/where/
+|
+| You can optionally enable standard query string
+| based URLs:
+|
+| www.your-site.com?who=me&what=something&where=here
+|
+| Options are: TRUE or FALSE (boolean)
+|
+| The two other items let you set the query string "words"
+| that will invoke your controllers and functions:
+| www.your-site.com/index.php?c=controller&m=function
+|
+*/
+$config['enable_query_strings'] = FALSE;
+$config['controller_trigger'] = 'c';
+$config['function_trigger'] = 'm';
+
+ + +

Step 5: Update your database.php file

+ +

Open your application/config/database.php file and add these new items:

+ +
+$db['default']['dbprefix'] = "";
+$db['default']['active_r'] = TRUE;
+
+ + +

Step 6: Update your user guide

+ +

Please also replace your local copy of the user guide with the new version.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrade_131.html b/user_guide/installation/upgrade_131.html new file mode 100644 index 000000000..8f7a7408b --- /dev/null +++ b/user_guide/installation/upgrade_131.html @@ -0,0 +1,108 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading from 1.3 to 1.3.1

+ +

Note: The instructions on this page assume you are running version 1.3. If you +have not upgraded to that version please do so first.

+ +

Before performing an update you should take your site offline by replacing the index.php file with a static one.

+ + + +

Step 1: Update your Code Igniter files

+ +

Replace the following directories in your "system" folder with the new versions:

+ +

Note: If you have any custom developed files in these folders please make copies of them first.

+ + + + +

Step 2: Update your user guide

+ +

Please also replace your local copy of the user guide with the new version.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrade_132.html b/user_guide/installation/upgrade_132.html new file mode 100644 index 000000000..69f22212d --- /dev/null +++ b/user_guide/installation/upgrade_132.html @@ -0,0 +1,106 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading from 1.3.1 to 1.3.2

+ +

Note: The instructions on this page assume you are running version 1.3.1. If you +have not upgraded to that version please do so first.

+ +

Before performing an update you should take your site offline by replacing the index.php file with a static one.

+ + + +

Step 1: Update your Code Igniter files

+ +

Replace the following directories in your "system" folder with the new versions:

+ +

Note: If you have any custom developed files in these folders please make copies of them first.

+ + + + +

Step 2: Update your user guide

+ +

Please also replace your local copy of the user guide with the new version.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrade_133.html b/user_guide/installation/upgrade_133.html new file mode 100644 index 000000000..563cbf7b4 --- /dev/null +++ b/user_guide/installation/upgrade_133.html @@ -0,0 +1,118 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading from 1.3.2 to 1.3.3

+ +

Note: The instructions on this page assume you are running version 1.3.2. If you +have not upgraded to that version please do so first.

+ +

Before performing an update you should take your site offline by replacing the index.php file with a static one.

+ + + +

Step 1: Update your Code Igniter files

+ +

Replace the following directories in your "system" folder with the new versions:

+ +

Note: If you have any custom developed files in these folders please make copies of them first.

+ + + + +

Step 2: Update your Models

+ +

If you are NOT using Code Igniter's Models feature disregard this step.

+ +

As of version 1.3.3, Code Igniter does not connect automatically to your database when a model is loaded. This +allows you greater flexibility in determining which databases you would like used with your models. If your application is not connecting +to your database prior to a model being loaded you will have to update your code. There are several options for connecting, +as described here. + + +

Step 3: Update your user guide

+ +

Please also replace your local copy of the user guide with the new version.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrade_140.html b/user_guide/installation/upgrade_140.html new file mode 100644 index 000000000..7f25c44e9 --- /dev/null +++ b/user_guide/installation/upgrade_140.html @@ -0,0 +1,111 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading from 1.3.3 to 1.4.0

+ +

Note: The instructions on this page assume you are running version 1.3.2. If you +have not upgraded to that version please do so first.

+ +

Before performing an update you should take your site offline by replacing the index.php file with a static one.

+ + + +

Step 1: Update your Code Igniter files

+ +

Replace the following directories in your "system" folder with the new versions:

+ +

Note: If you have any custom developed files in these folders please make copies of them first.

+ + + + +

Step 4: Update your user guide

+ +

Please also replace your local copy of the user guide with the new version.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrade_b11.html b/user_guide/installation/upgrade_b11.html new file mode 100644 index 000000000..562507a5a --- /dev/null +++ b/user_guide/installation/upgrade_b11.html @@ -0,0 +1,150 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading From Beta 1.0 to Beta 1.1

+ +

To upgrade to Beta 1.1 please perform the following steps:

+ +

Step 1: Replace your index file

+ +

Replace your main index.php file with the new index.php file. Note: If you have renamed your "system" folder you will need to edit this info in the new file.

+ +

Step 2: Relocate your config folder

+ +

This version of Code Igniter now permits multiple sets of "applications" to all share a common set of backend files. In order to enable +each application to have its own configuration values, the config directory must now reside +inside of your application folder, so please move it there.

+ + +

Step 3: Replace directories

+ +

Replace the following directories with the new versions:

+ + + + +

Step 4: Add the calendar language file

+ +

There is a new language file corresponding to the new calendaring class which must be added to your language folder. Add +the following item to your version: language/english/calendar_lang.php

+ + +

Step 5: Edit your config file

+ +

The original application/config/config.php file has a typo in it Open the file and look for the items related to cookies:

+ +$conf['cookie_prefix'] = "";
+$conf['cookie_domain'] = "";
+$conf['cookie_path'] = "/";
+ +

Change the array name from $conf to $config, like this:

+ +$config['cookie_prefix'] = "";
+$config['cookie_domain'] = "";
+$config['cookie_path'] = "/";
+ +

Lastly, add the following new item to the config file (and edit the option if needed):

+ +
+/*
+|------------------------------------------------
+| URI PROTOCOL
+|------------------------------------------------
+|
+| This item determines which server global
+| should be used to retrieve the URI string. The
+| default setting of "auto" works for most servers.
+| If your links do not seem to work, try one of
+| the other delicious flavors:
+|
+| 'auto' Default - auto detects
+| 'path_info' Uses the PATH_INFO
+| 'query_string' Uses the QUERY_STRING
+*/
+
+$config['uri_protocol'] = "auto";
+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/installation/upgrading.html b/user_guide/installation/upgrading.html new file mode 100644 index 000000000..3ab9fd844 --- /dev/null +++ b/user_guide/installation/upgrading.html @@ -0,0 +1,95 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Upgrading From a Previous Version

+ +

Please read the upgrade notes corresponding to the version you are upgrading from.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/benchmark.html b/user_guide/libraries/benchmark.html new file mode 100644 index 000000000..1f72f3531 --- /dev/null +++ b/user_guide/libraries/benchmark.html @@ -0,0 +1,160 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Benchmarking Class

+ +

Code Igniter has a Benchmarking class that is always active, enabling the time difference between any +two marked points to be calculated.

+ +

Note: This class is initialized automatically by the system so there is no need to do it manually.

+ + +

In addition, the benchmark is always started the moment the framework is +invoked, and ended by the output class right before sending the final view to the browser, enabling a very accurate +timing of the entire system execution to be shown.

+ +

Using the Benchmark

+ +

The Benchmark class can be used within your controllers, views, or your Models. The process for usage is this: + +

    +
  1. Mark a start point
  2. +
  3. Mark an end point
  4. +
  5. Run the "elapsed time" function to view the results
  6. +
+ +

Here's an example using real code:

+ +$this->benchmark->mark('start');
+
+// Some code happens here
+
+$this->benchmark->mark('end');
+
+echo $this->benchmark->elapsed_time('start', 'end');
+ +

Note: The words "start" and "end" are arbitrary. They are simply words used to set two markers. You can +use any words you want, and you can set multiple sets of markers. Consider this example:

+ +$this->benchmark->mark('dog');
+
+// Some code happens here
+
+$this->benchmark->mark('cat');
+
+// More code happens here
+
+$this->benchmark->mark('bird');
+
+echo $this->benchmark->elapsed_time('dog', 'cat');
+echo $this->benchmark->elapsed_time('cat', 'bird');
+echo $this->benchmark->elapsed_time('dog', 'bird');
+ + +

Displaying Total Execution Time

+ +

If you would like to display the total elapsed time from the moment Code Igniter starts to the moment the final output +is sent to the browser, simply place this in one of your view templates:

+ +<?=$this->benchmark->elapsed_time();?> + +

You'll notice that it's the same function used in the examples above to calculate the time between two point, except you are +not using any parameters. When the parameters are absent, Code Igniter does not stop the benchmark until right before the final +output is sent to the browser. It doesn't matter where you use the function call, the timer will continue to run until the very end.

+ +

An alternate way to show your elapsed time in your view files is to use this pseudo-variable, if you prefer not to use the pure PHP:

+{elapsed_time} + +

Note: If you want to benchmark anything within your controller +functions you must set your own start/end points.

+ +

Displaying Memory Consumption

+ +

If your PHP installation is configured with --enable-memory-limit, you can display the amount of memory consumed by the entire +system using the following code in one of your view file:

+ +<?=$this->benchmark->memory_usage();?> +

Note: This function can only be used in your view files. The consumpiton will reflect the total memory used by the entire app.

+ +

An alternate way to show your memory usage in your view files is to use this pseudo-variable, if you prefer not to use the pure PHP:

+{memory_usage} + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/calendar.html b/user_guide/libraries/calendar.html new file mode 100644 index 000000000..a3bd87b5d --- /dev/null +++ b/user_guide/libraries/calendar.html @@ -0,0 +1,258 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + + + +

Calendaring Class

+ +

The Calendar class enables you to dynamically create calendars. Your calendars can be formatted through the use of a calendar +template, allowing 100% control over every aspect of its design. In addition, you can pass data to your calendar cells.

+ +

Initializing the Class

+ +

Like most other classes in Code Igniter, the Calendar class is initialized in your controller using the $this->load->library function:

+ +$this->load->library('calendar'); +

Once loaded, the Calendar object will be available using: $this->calendar

+ + +

Displaying a Calendar

+ +

Here is a very simple example showing how you can display a calendar:

+ +$this->load->library('calendar');
+
+echo $this->calendar->generate();
+ +

The above code will generate a calendar for the current month/year based on your server time. +To show a calendar for a specific month and year you will pass this information to the calendar generating function:

+ +$this->load->library('calendar');
+
+echo $this->calendar->generate(2006, 6);
+ +

The above code will generate a calendar showing the month of June in 2006. The first parameter specifies the year, the second parameter specifies the month.

+ +

Passing Data to your Calendar Cells

+ +

To add data to your calendar cells involves creating an associative array in which the keys correspond to the days +you wish to populate and the array value contains the data. The array is passed to the third parameter of the calendar +generating function. Consider this example:

+ +$this->load->library('calendar');
+
+$data = array(
+               3  => 'http://your-site.com/news/article/2006/03/',
+               7  => 'http://your-site.com/news/article/2006/07/',
+               13 => 'http://your-site.com/news/article/2006/13/',
+               26 => 'http://your-site.com/news/article/2006/26/'
+             );
+
+echo $this->calendar->generate(2006, 6, $data);
+ +

Using the above example, day numbers 3, 7, 13, and 26 will become links pointing to the URLs you've provided.

+ +

Note: By default it is assumed that your array will contain links. +In the section that explains the calendar template below you'll see how you can customize +how data passed to your cells is handled so you can pass different types of information.

+ + +

Setting Display Preferences

+ +

There are seven preferences you can set to control various aspects of the calendar. Preferences are set using an initialization +function similar to other classes. Here is an example: + + +$this->load->library('calendar');
+
+$prefs = array (
+               'start_day'    => 'saturday',
+               'month_type'   => 'long',
+               'day_type'     => 'short'
+             );
+
+$this->calendar->initialize($prefs);
+
+echo $this->calendar->generate();
+ +

The above code would start the calendar on saturday, use the "long" month heading, and the "short" day names. More information +regarding preferences below.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescription
templateNoneNoneA string containing your calendar template. See the template section below.
local_timetime()NoneA Unix timestamp corresponding to the current time.
start_daysundayAny week day (sunday, monday, tuesday, etc.)Sets the day of the week the calendar should start on.
month_typelonglong, shortDetermines what version of the month name to use in the header. long = January, short = Jan.
day_typeabrlong, short, abrDetermines what version of the weekday names to use in the column headers. long = Sunday, short = Sun, abr = Su.
show_next_prevFALSETRUE/FALSE (boolean)Determines whether to display links allowing you to toggle to next/previous months. See information on this feature below.
next_prev_urlNoneA URLSets the basepath used in the next/previous calendar links.
+ + + + +

Creating a Calendar Template

+ +

By creating a calendar template you have 100% control over the design of your calendar. Each component of your +calendar will be placed within a pair of pseudo-variables as shown here:

+ + +$this->load->library('calendar');

+$prefs['template'] = '

+   {table_open}<table border="0" cellpadding="0" cellspacing="0">{/table_open}
+
+   {heading_row_start}<tr>{/heading_row_start}
+
+   {heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
+   {heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
+   {heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}
+
+   {heading_row_end}</tr>{/heading_row_end}
+
+   {week_row_start}<tr>{/week_row_start}
+   {week_day_cell}<td>{week_day}</td>{/week_day_cell}
+   {week_row_end}</tr>{/week_row_end}
+
+   {cal_row_start}<tr>{/cal_row_start}
+   {cal_cell_start}<td>{/cal_cell_start}
+
+   {cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
+   {cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}
+
+   {cal_cell_no_content}{day}{/cal_cell_no_content}
+   {cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}
+
+   {cal_cell_blank}&nbsp;{/cal_cell_blank}
+
+   {cal_cell_end}</td>{/cal_cell_end}
+   {cal_row_end}<tr>{/cal_row_end}
+
+   {table_close}</table>{/table_close}
+';
+
+$this->calendar->initialize($prefs);
+
+echo $this->calendar->generate();
+ + + +

Showing Next/Previous Month Links

+ +

To allow your calendar to dynamically increment/decrement via the next/previous links requires that you set up your calendar +code similar to this example:

+ + +$this->load->library('calendar');
+
+$prefs = array (
+               'show_next_prev'  => TRUE,
+               'next_prev_url'   => 'http://www.your-site.com/index.php/calendar/show/'
+             );
+
+$this->calendar->initialize($prefs);
+
+echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));
+ +

You'll notice a few things about the above example:

+ + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/config.html b/user_guide/libraries/config.html new file mode 100644 index 000000000..c173f5690 --- /dev/null +++ b/user_guide/libraries/config.html @@ -0,0 +1,158 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Config Class

+ +

The Config class provides a means to retrieve configuration preferences. These preferences can +come from the default config file (application/config/config.php) or from your own custom config files.

+ +

Note: This class is initialized automatically by the system so there is no need to do it manually.

+ + +

Anatomy of a Config File

+ +

By default, Code Igniter has a one primary config file, located at application/config/config.php. If you open the file using +your text editor you'll see that config items are stored in an array called $config.

+ +

You can add your own config items to +this file, or if you prefer to keep your configuration items separate (assuming you even need config items), +simply create your own file and save it in config folder.

+ +

Note: If you do create your own config files use the same format as the primary one, storing your items in +an array called $config. Code Igniter will intelligently manage these files so there will be no conflict even though +the array has the same name (assuming an array index is not named the same as another).

+ +

Loading a Config File

+ +

Note: Code Igniter automatically loads the primary config file (application/config/config.php), +so you will only need to load a config file if you have created your own.

+ +

There are two ways to load a config file:

+ +
  1. Manual Loading + +

    To load one of your custom config files you will use the following function within the controller that needs it:

    + +$this->config->load('filename'); + +

    Where filename is the name of your config file, without the .php file extension.

    + +
  2. +
  3. Auto-loading
  4. + +

    If you find that you need a particular config file globally, you can have it loaded automatically by the system. To do this, +open the autoload.php file, located at application/config/autoload.php, and add your config file as +indicated in the file.

    + +
+ + +

Fetching Config Items

+ +

To retrive an item from your config file, use the following function:

+ +$this->config->item('item name'); + +

Where item name is the $config array index you want to retrieve. For example, to fetch your language choice you'll do this:

+ +$lang = $this->config->item('language'); + +

The function returns FALSE (boolean) if the item you are trying to fetch does not exist.

+ +

Setting a Config Item

+ +

If you would like to dynamically set a config item or change an existing one, you can so so using:

+ +$this->config->set_item('item_name', 'item_value'); + +

Where item_name is the $config array index you want to change, and item_value is its value.

+ + +

Helper Functions

+ +

The config class has the following helper functions:

+ +

$this->config->site_url();

+

This function retrieves the URL to your site, along with the "index" value you've specified in the config file.

+ +

$this->config->system_url();

+

This function retrieves the URL to your system folder.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/active_record.html b/user_guide/libraries/database/active_record.html new file mode 100644 index 000000000..8fc3b8131 --- /dev/null +++ b/user_guide/libraries/database/active_record.html @@ -0,0 +1,610 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + +
+ + + +
+ + +

Active Record Class

+ + +

Code Igniter uses a modified version of the Active Record Database Pattern. +This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. +In some cases only one or two lines of code are necessary to perform a database action. +Code Igniter does not require that each database table be its own class file. It instead provides a more simplified interface.

+ +

Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax +is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.

+ +

Note: If you intend to write your own queries you can disable this class in your database config file, allowing the core database library and adapter to utilize fewer resources.

+ +
+ + + + + + +  +

Selecting Data

+ +

The following functions allow you to build SQL SELECT statements.

+ +

Note: If you are using PHP 5 you can use method chaining for more compact syntax. This is described at the end of the page.

+ + +

$this->db->get();

+ +

Runs the selection query and returns the result. Can be used by itself to retrieve all records from a table:

+ +$query = $this->db->get('mytable');
+
+// Produces: SELECT * FROM mytable
+ +

The second and third parameters enable you do set a limit and offset clause:

+ +$query = $this->db->get('mytable', 10, 20);
+
+// Produces: SELECT * FROM mytable LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
+ + + +

You'll notice that the above function is assigned to a variable named $query, which can be used to show the results:

+ +$query = $this->db->get('mytable');
+
+foreach ($query->result() as $row)
+{
+    echo $row->title;
+}
+ +

Please visit the result functions page for a full discussion regarding result generation.

+ + +

$this->db->getwhere();

+ +

Identical to the above function except that it permits you to add a "where" clause in the second parameter, +instead of using the db->where() function:

+ +$query = $this->db->getwhere('mytable', array(id => $id), $limit, $offset); + +

Please read the about the where function below for more information.

+ + +

$this->db->select();

+ +

Permits you to write the SELECT portion of your query:

+ + +$this->db->select('title, content, date');
+
+$query = $this->db->get('mytable');
+
+// Produces: SELECT title, content, date FROM mytable
+ +

Note: If you are selecting all (*) from a table you do not need to use this function. When omitted, Code Igniter assumes you wish to SELECT *

+ + +

$this->db->from();

+ +

Permits you to write the FROM portion of your query:

+ + +$this->db->select('title, content, date');
+$this->db->from('mytable');
+
+$query = $this->db->get();
+
+// Produces: SELECT title, content, date FROM mytable
+ +

Note: As shown earlier, the FROM portion of your query can be specified in the $this->db->get() function, so use whichever method +you prefer.

+ +

$this->db->join();

+ +

Permits you to write the JOIN portion of your query:

+ + +$this->db->select('*');
+$this->db->from('blogs');
+$this->db->join('comments', 'comments.id = blogs.id');
+
+$query = $this->db->get();
+
+// Produces:
+// SELECT * FROM blogs
+// JOIN comments ON comments.id = blogs.id
+
+ +

Multiple function calls can be made if you need several joins in one query.

+ +

If you need something other than a natural JOIN you can specify it via the third parameter of the function. +Options are: left, right, outer, inner, left outer, and right outer.

+ + +$this->db->join('comments', 'comments.id = blogs.id', 'left');
+
+// Produces: LEFT JOIN comments ON comments.id = blogs.id
+ + + + + +

$this->db->where();

+

This function enables you to set WHERE clauses using one of four methods:

+ +

Note: All values passed to this function are escaped automatically, producing safer queries.

+ +
    +
  1. Simple key/value method: + + $this->db->where('name', $name); +

    // Produces: WHERE name = 'Joe' +
    + +

    Notice that the equal sign is added for you.

    + +

    If you use multiple function calls they will be chained together with AND between them:

    + + $this->db->where('name', $name);
    + $this->db->where('title', $title);
    + $this->db->where('status', $status); +

    // WHERE = 'Joe' AND title = 'boss' AND status = 'active' +
    + + +
  2. + +
  3. Custom key/value method: + +

    You can include an operator in the first parameter in order to to control the comparison:

    + + $this->db->where('name !=', $name);
    + $this->db->where('id <', $id); +

    // Produces: WHERE name != 'Joe' AND id < 45 +
    + + + +
  4. +
  5. Associative array method: + + + + $array = array('name' => $name, 'title' => $title, 'status' => $status);

    + + $this->db->where($array); +

    // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active' +
    + +

    You can include your own operators using this method as well:

    + + + $array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);

    + + $this->db->where($array);
    + +
  6. +
  7. Custom string: + +

    You can write your own clauses manually:

    + + + $where = "name='Joe' AND status='boss' OR status='active'";

    + $this->db->where($where);
    + +
  8. +
+ + +

$this->db->orwhere();

+

This function is identical to the one above, except that multiple instances are joined by OR:

+ + +$this->db->where('name !=', $name);
+$this->db->orwhere('id >', $id); +

// Produces: WHERE name != 'Joe' OR id > 50 +
+ + + + +

$this->db->like();

+

This function enables you to generate LIKE clauses, useful for doing searches.

+ +

Note: All values passed to this function are escaped automatically.

+ + +
    +
  1. Simple key/value method: + + $this->db->like('title', $match); +

    // Produces: WHERE title LIKE '%match%' +
    + +

    If you use multiple function calls they will be chained together with AND between them:

    + + $this->db->like('title', $match);
    + $this->db->like('body', $match); +

    // WHERE title LIKE '%match%' AND body LIKE '%match%' +
    + +
  2. + +
  3. Associative array method: + + + $array = array('title' => $match, 'page1' => $match, 'page2' => $match);

    + + $this->db->like($array); +

    // WHERE title LIKE '%match%' AND page1 LIKE '%match%' AND page2 LIKE '%match%' +
    + +
  4. +
+ + +

$this->db->orlike();

+

This function is identical to the one above, except that multiple instances are joined by OR:

+ + +$this->db->like('title', $match);
+$this->db->orlike('body', $match); +

// WHERE title LIKE '%match%' OR body LIKE '%match%' +
+ + + + +

$this->db->groupby();

+ +

Permits you to write the GROUP BY portion of your query:

+ +$this->db->groupby("title"); +

// Produces: GROUP BY title +
+ +

You can also pass an array of multiple values as well:

+ +$this->db->groupby(array("title", "date"); +

// Produces: GROUP BY title, date +
+ + +

$this->db->having();

+ +

Permits you to write the HAVING portion of your query:

+ +$this->db->having('user_id = 45'); +

// Produces: HAVING 'user_id = 45' +
+ +

You can also pass an array of multiple values as well:

+ + +$this->db->having(array('title =' => 'My Title', 'id <' => $id)); +

// Produces: HAVING title = 'My Title', 'id < 45' +
+ + + +

$this->db->orderby();

+

Lets you set an ORDER BY clause. The first parameter contains the name of the column you would like to order by. +The second parameter lets you set the direction of the result. Options are asc or desc

+ +$this->db->orderby("title", "desc"); +

// Produces: ORDER BY title DESC +
+ +

You can also pass your own string in the first parameter:

+ +$this->db->orderby('title desc, name asc'); +

// Produces: ORDER BY title DESC, name ASC +
+ + + +

$this->db->limit();

+

Lets you limit the number of rows you would like returned by the query: + + +$this->db->limit(10);
+
+// Produces: LIMIT 10
+ + +

The second parameter lets you set a result offset.

+ + +$this->db->limit(10, 20);
+
+// Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
+ + +

$this->db->count_all();

+ +

Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:

+ +echo $this->db->count_all('my_table');
+
+// Produces an integer, like 25
+ + + + +  +

Inserting Data

+ +

$this->db->insert();

+

Generates an insert string based on the data you supply, and runs the query. You can either pass an +array or an object to the function. Here is an example using an array:

+ + +$data = array(
+               'title' => $title,
+               'name' => $name,
+               'date' => $date
+            );
+
+$this->db->insert('mytable', $data); +

+// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
+ +

The first parameter will contain the table name, the second is an associative array of values.

+ +

Here is an example using an object:

+ + +/*
+    class Myclass {
+        var = $title = 'My Title';
+        var = $content = 'My Content';
+        var = $date = 'My Date';
+    }
+*/
+
+$object = new Myclass;
+
+$this->db->insert('mytable', $object); +

+// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
+ +

The first parameter will contain the table name, the second is an associative array of values.

+ +

Note: All values are escaped automatically producing safer queries.

+ + + + +

$this->db->set();

+

This function enables you to set values for inserts or updates.

+ +

It can be used instead of passing a data array directly to the insert or update functions:

+ +$this->db->set('name', $name); +
+$this->db->insert('mytable'); +

+// Produces: INSERT INTO mytable (name) VALUES ('{$name}')
+ +

If you use multiple function called they will be assembled properly based on whether you are doing an insert or an update:

+ +$this->db->set('name', $name);
+$this->db->set('title', $title);
+$this->db->set('status', $status);
+$this->db->insert('mytable'); +
+ +

You can also pass an associative array to this function:

+ + +$array = array('name' => $name, 'title' => $title, 'status' => $status);

+ +$this->db->set($array);
+$this->db->insert('mytable'); +
+ +

Or an object:

+ + + +/*
+    class Myclass {
+        var = $title = 'My Title';
+        var = $content = 'My Content';
+        var = $date = 'My Date';
+    }
+*/
+
+$object = new Myclass;
+
+$this->db->set($object);
+$this->db->insert('mytable'); +
+ + + +  +

Updating Data

+ +

$this->db->update();

+

Generates an update string and runs the query based on the data you supply. You can pass an +array or an object to the function. Here is an example using +an array:

+ + +$data = array(
+               'title' => $title,
+               'name' => $name,
+               'date' => $date
+            );
+
+$this->db->where('id', $id);
+$this->db->update('mytable', $data); +

+// Produces:
+// UPDATE mytable
+// SET title = '{$title}', name = '{$name}', date = '{$date}'
+// WHERE id = $id
+ +

Or you can supply an object:

+ + +/*
+    class Myclass {
+        var = $title = 'My Title';
+        var = $content = 'My Content';
+        var = $date = 'My Date';
+    }
+*/
+
+$object = new Myclass;
+
+$this->db->where('id', $id);
+$this->db->update('mytable', $object, $where); +

+// Produces:
+// UPDATE mytable
+// SET title = '{$title}', name = '{$name}', date = '{$date}'
+// WHERE id = $id
+ + + +

Note: All values are escaped automatically producing safer queries.

+ +

You'll notice the use of the $this->db->where() function, enabling you to set the WHERE clause. +You can optionally pass this information directly into the update function as a string:

+ +$this->db->update('mytable', $data, "id = 4"); + +

Or as an array:

+ +$this->db->update('mytable', $data, array('id' => $id)); + +

You may also use the $this->db->set() function described above when performing updates.

+ + +  +

Deleting Data

+ + + +

$this->db->delete();

+

Generates a delete SQL string and runs the query.

+ + +$this->db->delete('mytable', array('id', $id)); +

+// Produces:
+// DELETE FROM mytable
+// WHERE id = $id
+ +

The first parameter is the table name, the second is the where clause. You can also use the where() or orwhere() functions instead of passing +the data to the second parameter of the function: + + +$this->db->where('id', $id);
+$this->db->delete('mytable'); +

+// Produces:
+// DELETE FROM mytable
+// WHERE id = $id
+ +

Note: All values are escaped automatically producing safer queries.

+ + +  +

Method Chaining

+ +

Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example:

+ + +$this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20);
+
+$query = $this->db->get();
+ +

Note: Method chaining only works with PHP 5.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/call_function.html b/user_guide/libraries/database/call_function.html new file mode 100644 index 000000000..9c860a426 --- /dev/null +++ b/user_guide/libraries/database/call_function.html @@ -0,0 +1,123 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + +
+ + + +
+ +

Custom Function Calls

+ +

$this->db->call_function();

+ +

This function enables you to call PHP database functions that are not natively included in Code Igniter, in a platform independent manner. +For example, lets say you want to call the mysql_get_client_info() function, which is not natively supported +by Code Igniter. You could do so like this: +

+ +$this->db->call_function('get_client_info'); + +

You must supply the name of the function, without the mysql_ prefix, in the first parameter. The prefix is added +automatically based on which database driver is currently being used. This permits you to run the same function on different database platforms. +Obviously not all function calls are identical between platforms, so there are limits to how useful this function can be in terms of portability.

+ +

Any parameters needed by the function you are calling will be added to the second parameter.

+ +$this->db->call_function('some_function', $param1, $param2, etc..); + + +

Often, you will either need to supply a database connection ID or a database result ID. The connection ID can be accessed using:

+ +$this->db->conn_id; + +

The result ID can be accessed from within your result object, like this:

+ +$query = $this->db->query("SOME QUERY");
+
+$query->result_id;
+ + + + + + + + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/configuration.html b/user_guide/libraries/database/configuration.html new file mode 100644 index 000000000..4b7d2a8a0 --- /dev/null +++ b/user_guide/libraries/database/configuration.html @@ -0,0 +1,144 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + +
+ + + +
+ + +

Database Configuration

+ +

Code Igniter has a config file that lets you store your database connection values (username, password, database name, etc.). +The config file is located at: + +

application/config/database.php

+ +

The config settings are stored in a multi-dimensional array with this prototype:

+ +$db['default']['hostname'] = "localhost";
+$db['default']['username'] = "root";
+$db['default']['password'] = "";
+$db['default']['database'] = "database_name";
+$db['default']['dbdriver'] = "mysql";
+$db['default']['dbprefix'] = "";
+$db['default']['pconnect'] = TRUE;
+$db['default']['db_debug'] = FALSE;
+$db['default']['active_r'] = TRUE;
+ +

The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store +multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.) +under a single installation, you can set up a connection group for each, then switch between groups as needed. +For example, to set up a "test" environment you would do this:

+ +$db['test']['hostname'] = "localhost";
+$db['test']['username'] = "root";
+$db['test']['password'] = "";
+$db['test']['database'] = "database_name";
+$db['test']['dbdriver'] = "mysql";
+$db['test']['dbprefix'] = "";
+$db['test']['pconnect'] = TRUE;
+$db['test']['db_debug'] = FALSE;
+$db['test']['active_r'] = TRUE;
+ + +

Then, to globally tell the system to use that group you would set this variable located in the config file:

+ +$active_group = "test"; + +

Note: The name "test" is arbitrary. It can be anything you want. By default we've used the word "default" +for the primary connection, but it too can be renamed to something more relevant to your project.

+ +

Explanation of Values:

+ + + +

Note: Depending on what database platform you are using (MySQL, Postgre, etc.) +not all values will be needed. For example, when using SQLite you will not need to supply a username or password, and +the database name will be the path to your database file. The information above assumes you are using MySQL.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/connecting.html b/user_guide/libraries/database/connecting.html new file mode 100644 index 000000000..7bf93c302 --- /dev/null +++ b/user_guide/libraries/database/connecting.html @@ -0,0 +1,172 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + +
+ + + +
+ + +

Connecting to your Database

+ +

There are two ways to connect to a database:

+ +

Automatically Connecting

+ +

The "auto connect" feature will load and instantiate the database class with every page load. +To enable "auto connecting", add the word database to the core array, as indicated in the following file:

+ +

application/config/autoload.php

+ +

Manually Connecting

+ +

If only some of your pages require database connectivity you can manually connect to your database by adding this +line of code in any function where it is needed, or in your class constructor to make the database +available globally in that class.

+ +$this->load->database(); + +

If the above function does not contain any information in the first parameter it will connect +to the group specified in your database config file. For most people, this is the preferred method of use.

+ + +

The first parameter of this function can optionally be used to specify a particular database group +from your config file, or you can even submit connection values for a database that is not specified in your config file. +Examples:

+ +

To choose a specific group from your config file you can do this:

+ +$this->load->database('group_name'); + +

Where group_name is the name of the connection group from your config file.

+ + +

To connect manually to a desired database you can pass an array of values:

+ +$config['hostname'] = "localhost";
+$config['username'] = "myusername";
+$config['password'] = "mypassword";
+$config['database'] = "mydatabase";
+$config['dbdriver'] = "mysql";
+$config['dbprefix'] = "";
+$config['pconnect'] = FALSE;
+$config['db_debug'] = TRUE;
+$config['active_r'] = TRUE;
+
+$this->load->database($config);
+ +

For information on each of these values please see the configuration page. + +

Or you can submit your database values as a Data Source Name. DSNs must have this prototype: + +$dsn = 'dbdriver://username:password@hostname/database';
+
+$this->load->database('$dsn');
+ +

Note that if you use a DSN you will not be able to specify some of the default values like you can if you use a connection array.

+ + + + +

Connecting to Multiple Databases

+ +

If you need to connect to more than one database simultaneously you can do so as follows:

+ + +$DB1 = $this->load->database('group_one', TRUE);
+$DB2 = $this->load->database('group_two', TRUE); +
+ +

Note: Change the words "group_one" and "group_two" to the specific group names you are connecting to (or +you can pass the connection values as indicated above).

+ +

By setting the second parameter to TRUE (boolean) the function will return the database object.

+ +
+

When you connect this way, you will use your object name to issue commands rather than the syntax used throughout this guide. In other words, rather than issuing commands with:

+ +

$this->db->query();
$this->db->result();
etc...

+ +

You will instead use:

+ +

$DB1->query();
$DB1->result();
etc...

+ +
+ + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/examples.html b/user_guide/libraries/database/examples.html new file mode 100644 index 000000000..e738ba825 --- /dev/null +++ b/user_guide/libraries/database/examples.html @@ -0,0 +1,183 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + + +
+ + + +
+ + + +
+ + +

Database Quick Start: Example Code

+ +

The following page contains example code showing how the database class is used. For complete details please +read the individual pages describing each function.

+ + +

Initializing the Database Class

+ +

The following code loads and initializes the database class based on your configuration settings:

+ +$this->load->database(); + +

Once loaded the class is ready to be used as described below.

+ +

Note: If all your pages require database access you can connect automatically. See the connecting page for details.

+ + +

Standard Query With Multiple Results (Object Version)

+ +$query = $this->db->query('SELECT name, title, email FROM my_table');
+
+foreach ($query->result() as $row)
+{
+    echo $row->title;
+    echo $row->name;
+    echo $row->email;
+}
+
+echo 'Total Results: ' . $query->num_rows(); +
+ +

The above result() function returns an array of objects. Example: $row->title

+ + +

Standard Query With Multiple Results (Array Version)

+ +$query = $this->db->query('SELECT name, title, email FROM my_table');
+
+foreach ($query->result_array() as $row)
+{
+    echo $row['title'];
+    echo $row['name'];
+    echo $row['email'];
+}
+ +

The above result_array() function returns an array of standard array indexes. Example: $row['title']

+ + +

Standard Query With Single Result

+ +$query = $this->db->query('SELECT name FROM my_table LIMIT 1');
+
+$row = $query->row();
+echo $row->name;
+
+ + +

Standard Insert

+ + +$sql = "INSERT INTO mytable (title, name)
+        VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")";
+
+$this->db->query($sql);
+
+echo $this->db->affected_rows(); +
+ + + + +

Active Record Query

+ +

The Active Record Pattern gives you a simplified means of retrieving data:

+ + +$query = $this->db->get('table_name');
+
+foreach ($query->result() as $row)
+{
+    echo $row->title;
+}
+ + +

Active Record Insert

+ + +$data = array(
+               'title' => $title,
+               'name' => $name,
+               'date' => $date
+            );
+
+$this->db->insert('mytable', $data); +

+// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/fields.html b/user_guide/libraries/database/fields.html new file mode 100644 index 000000000..dd2def9a3 --- /dev/null +++ b/user_guide/libraries/database/fields.html @@ -0,0 +1,144 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + +
+ + + +
+ + + +
+ + +

Field Data

+ + +

Retrieving Field Names

+

Sometimes it's helpful to gather the field names.

+ +

$this->db->field_names();

+

Returns an array containing the field names. You must supply the table name to the function:

+ + +$fields = $this->db->field_names('table_name');

+ +foreach ($fields as $field)
+{
+   echo $field;
+} +
+ + + +

Retrieving Field MetaData

+

Sometimes it's helpful to gather the field names or other metadata, like the column type, max length, etc.

+ +

$this->db->field_data();

+

Returns an array of objects containing field information.

+ +

Note: Not all databases provide meta-data.

+ +

Usage example:

+ + +$fields = $this->db->field_data('table_name');

+ +foreach ($fields as $field)
+{
+   echo $field->name;
+   echo $field->type;
+   echo $field->max_length;
+   echo $field->primary_key;
+} +
+ +

If you have run a query already you can use the result oject instead of supplying the table name:

+ + +$query = $this->db->query("YOUR QUERY");
+$fields = $query->field_data(); +
+ + +

The following data is available from this function if supported by your database:

+ + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/index.html b/user_guide/libraries/database/index.html new file mode 100644 index 000000000..a8e7c8e77 --- /dev/null +++ b/user_guide/libraries/database/index.html @@ -0,0 +1,99 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + +
+ + + +
+ + +

The Database Class

+ +

Code Igniter comes with a full-featured and very fast abstracted database class that supports both traditional +structures and Active Record patterns. The database functions offer clear, simple syntax.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/queries.html b/user_guide/libraries/database/queries.html new file mode 100644 index 000000000..57fd916ef --- /dev/null +++ b/user_guide/libraries/database/queries.html @@ -0,0 +1,180 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + + +
+ + + +
+ + +

Queries

+ +

To submit a query, use the following function:

+ +$this->db->query('YOUR QUERY HERE'); + +

The query() function returns a database result object +which you can use to show your results. You will typically assign the query to your own variable, like this:

+ +$query = $this->db->query('YOUR QUERY HERE'); + + +

Escaping Queries

+ +

It's a very good security practice to escape your data before sumbiting it into your database. +Code Igniter has two functions that help you do this:

+ +
    + +
  1. $this->db->escape() This function determines the data type so that it +can escape only string data. It also automatically adds single quotes around the data so you don't have to: + +$sql = "INSERT INTO table (title) VALUES(".$this->db->escape($title).")"; + + +
  2. $this->db->escape_str() This function escapes the data passed to it, regardless of type. +Most of the time you'll use the above function rather then this one. Use the function like this: + +$sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; + + +
  3. +
+ + + +


Query Bindings

+ + +

Bindings enable you to simplify your query syntax by letting the system put the queries together for you. Consider the following example:

+ + +$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; +

+$this->db->query($sql, array(3, 'live', 'Rick')); +
+ +

The question marks in the query are automatically replaced with the values in the array in the second parameter of the query function.

+

The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don't have to remember to manually escape data; the engine does it automatically for you.

+ + + +


Query Helper Functions

+ + +

$this->db->last_query();

+ +

Returns the last query that was run (the query string, not the result). Example:

+ +$str = $this->db->last_query();
+
+// Produces: SELECT * FROM sometable.... +
+ + +

The following two functions help simplify the process of writing database INSERTs and UPDATEs.

+ + +

$this->db->insert_string();

+

This function simplifies the process of writing database inserts. It returns a correctly formatted SQL insert string. Example:

+ +$data = array('name' => $name, 'email' => $email, 'url' => $url);
+
+$str = $this->db->insert_string('table_name', $data); +
+ +

The first parameter is the table name, the second is an associative array with the data to be inserted. The above example produces:

+INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@your-site.com', 'www.your-site.com') + + + +

$this->db->update_string();

+

This function simplifies the process of writing database updates. It returns a correctly formatted SQL update string. Example:

+ +$data = array('name' => $name, 'email' => $email, 'url' => $url);
+
+$where = "author_id = 1 AND status = 'active'"; +

+$str = $this->db->update_string('table_name', $data, $where); +
+ +

The first parameter is the table name, the second is an associative array with the data to be inserted, and the third parameter is the "where" clause. The above example produces:

+ UPDATE exp_weblog SET name = 'Rick', email = 'rick@your-site.com', url = 'www.your-site.com' WHERE author_id = 1 AND status = 'active' + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/results.html b/user_guide/libraries/database/results.html new file mode 100644 index 000000000..7e6b95d2f --- /dev/null +++ b/user_guide/libraries/database/results.html @@ -0,0 +1,235 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + +
+ + + +
+ + + +

Query Results

+ + +

There are several ways to generate query results:

+ +

result()

+ +

This function returns the query result as an array of objects, or FALSE on failure. + + Typically you'll use this in a foreach loop, like this:

+ + + $query = $this->db->query("YOUR QUERY");
+
+ foreach ($query->result() as $row)
+ {
+    echo $row->title;
+    echo $row->name;
+    echo $row->body;
+ }
+ +

If you run queries that might not produce a result, you are encouraged to test the result first:

+ + + $query = $this->db->query("YOUR QUERY");
+
+ if ($query->num_rows() > 0)
+ {
+    foreach ($query->result() as $row)
+    {
+       echo $row->title;
+       echo $row->name;
+       echo $row->body;
+    }
+ } +
+ +

result_array()

+ +

This function returns the query result as a pure array, or FALSE on failure. Typically you'll use this in a foreach loop, like this:

+ + $query = $this->db->query("YOUR QUERY");
+
+ foreach ($query->result_array() as $row)
+ {
+    echo $row['title'];
+    echo $row['name'];
+    echo $row['body'];
+ }
+ + +

row()

+ +

This function returns a single result row. If your query has more than one row, it returns only the first row. + The result is returned as an object. Here's a usage example:

+ + $query = $this->db->query("YOUR QUERY");
+
+ if ($query->num_rows() > 0)
+ {
+    $row = $query->row(); +

+    echo $row->title;
+    echo $row->name;
+    echo $row->body;
+ } +
+ +

If you want a specific row returned you can submit the row number as a digit in the first parameter: + + $row = $query->row(5); + + +

row_array()

+ +

Identical to the above row() function, except it returns an array. Example:

+ + + $query = $this->db->query("YOUR QUERY");
+
+ if ($query->num_rows() > 0)
+ {
+    $row = $query->row_array(); +

+    echo $row['title'];
+    echo $row['name'];
+    echo $row['body'];
+ } +
+ + +

If you want a specific row returned you can submit the row number as a digit in the first parameter: + + $row = $query->row_array(5); + + +

In addition, you can walk forward/backwards/first/last through your results using these variations:

+ +

+ $row = $query->first_row()
+ $row = $query->last_row()
+ $row = $query->next_row()
+ $row = $query->previous_row() +

+ +

By default they return an object unless you put the word "array" in the parameter:

+ +

+ $row = $query->first_row('array')
+ $row = $query->last_row('array')
+ $row = $query->next_row('array')
+ $row = $query->previous_row('array') +

+ + +


Query Result Helpers

+ +

The following functions provide useful information when dealing with query results.

+ +

$query->num_rows()

+

The number of rows returned by the query. Note: $query is the variable that the query was assigned to:

+ +$query = $this->db->query('SELECT * FROM my_table');

+echo $query->num_rows(); +
+ +

$query->num_fields()

+

The number of FIELDS returned by the query. Make sure to call the function using your query result object:

+ +$query = $this->db->query('SELECT * FROM my_table');

+echo $query->num_fields(); +
+ + +

$this->db->insert_id()

+

The insert ID number when performing database inserts.

+ +

$this->db->affected_rows()

+

Displays the number of affected rows, when doing "write" type queries (insert, update, etc.).

+

Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database class has a small hack that allows it to return the +correct number of affected rows. By default this hack is enabled but it can be turned off in the database driver file.

+ + +

$this->db->version()

+

Outputs the database version you are running:

+ +echo $this->db->version(); + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/database/table_data.html b/user_guide/libraries/database/table_data.html new file mode 100644 index 000000000..7d340d4e8 --- /dev/null +++ b/user_guide/libraries/database/table_data.html @@ -0,0 +1,116 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + + +
+ + + +
+ +

Table Data

+ +

These functions let you fetch table information.

+ +

$this->db->tables();

+ +

Returns an array containing the names of all the tables in the database you are currently connected to. Example:

+ +$tables = $this->db->tables()
+
+foreach ($tables as $table)
+{
+   echo $table;
+} +
+ + +

$this->db->table_exists();

+ +

Sometimes it's helpful to know whether a particular table exists before running an operation on it. +Returns a boolean TRUE/FALSE. Usage example:

+ + +if ($this->db->table_exists('table_name'))
+{
+   // some code...
+} +
+ +

Note: Replace table_name with the name of the table you are looking for.

+ + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/email.html b/user_guide/libraries/email.html new file mode 100644 index 000000000..25f5f4adc --- /dev/null +++ b/user_guide/libraries/email.html @@ -0,0 +1,294 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Email Class

+ +

Code Igniter's robust Email Class supports the following features:

+ + + + + +

Sending Email

+ +

Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file.

+ +

Here is a basic example demonstrating how you might send email. Note: This example assumes you are sending the email from one of your +controllers.

+ +$this->load->library('email');
+
+$this->email->from('your@your-site.com', 'Your Name');
+$this->email->to('someone@some-site.com');
+$this->email->cc('another@another-site.com');
+$this->email->bcc('them@their-site.com');
+
+$this->email->subject('Email Test');
+$this->email->message('Testing the email class.');
+
+$this->email->send();
+
+echo $this->email->print_debugger();
+ + + + +

Setting Email Preferences

+ +

There are 17 different preferences available to tailor how your email messages are sent. You can either set them manually +as described here, or automatically via preferences stored in your config file, described below:

+ +

Preferences are set by passing an array of preference values to the email initialize function. Here is an example of how you might set some preferences:

+ +$config['protocol'] = 'sendmail';
+$config['mailpath'] = '/usr/sbin/sendmail';
+$config['charset'] = 'iso-8859-1';
+$config['wordwrap'] = TRUE;
+
+$this->email->initialize($config);
+ +

Note: Most of the preferences have default values that will be used if you do not set them.

Setting Email Preferences in your Config File + +

If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called the email.php, add the $config +array in that file. Then save the file at config/email.php and it will be used automatically. You +will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

+ + + + +

Email Preferences

+ +

The following is a list of all the preferences that can be set when sending email.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescription
useragentCode IgniterNoneThe "user agent".
protocolmailmail, sendmail, or smtpThe mail sending protocol.
mailpath/usr/sbin/sendmailNoneThe server path to Sendmail.
smtp_hostNo DefaultNoneSMTP Server Address.
smtp_userNo DefaultNoneSMTP Username.
smtp_passNo DefaultNoneSMTP Password.
smtp_port25NoneSMTP Port.
smtp_timeout5NoneSMTP Timeout (in seconds).
wordwrapTRUETRUE or FALSE (boolean)Enable word-wrap.
wrapchars76 Character count to wrap at.
mailtypetexttext or htmlType of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work.
charsetutf-8Character set (utf-8, iso-8859-1, etc.).
validateFALSETRUE or FALSE (boolean)Whether to validate the email address.
priority31, 2, 3, 4, 5Email Priority. 1 = highest. 5 = lowest. 3 = normal.
newline\n"\r\n" or "\n"Newline character. (Use "\r\n" to comply with RFC 822).
bcc_batch_modeFALSETRUE or FALSE (boolean)Enable BCC Batch Mode.
bcc_batch_size200NoneNumber of emails in each BCC batch.
+ + +

Email Function Reference

+ +

$this->email->from()

+

Sets the email address and name of the person sending the email:

+$this->email->from('you@your-site.com', 'Your Name'); + +

$this->email->reply_to()

+

Sets the reply-to address. If the information is not provided the information in the "from" function is used. Example:

+$this->email->reply_to('you@your-site.com', 'Your Name'); + + +

$this->email->to()

+

Sets the email address(s) of the recipient(s). Can be a single email, a comma-delimited list or an array:

+ +$this->email->to('someone@some-site.com'); +$this->email->to('one@some-site.com, two@some-site.com, three@some-site.com'); + +$list = array('one@some-site.com, two@some-site.com, three@some-site.com');

+$this->email->to('$list');
+ +

$this->email->cc()

+

Sets the CC email address(s). Just like the "to", can be a single email, a comma-delimited list or an array.

+ +

$this->email->bcc()

+

Sets the BCC email address(s). Just like the "to", can be a single email, a comma-delimited list or an array.

+ + +

$this->email->subject()

+

Sets the email subject:

+$this->email->subject('This is my subject'); + +

$this->email->message()

+

Sets the email message body:

+$this->email->message('This is my message'); + +

$this->email->alt_message()

+

Sets the alternative email message body:

+$this->email->alt_message('This is the alternative message'); + +

This is an optional message string which can be used if you send HTML formatted email. It lets you specify an alternative +message with no HTML formatting which is added to the header string for people who do not accept HTML email. +If you do not set your own message Code Igniter will extract the message from your HTML email and strip the tags.

+ + + +

$this->email->clear()

+

Initializes all the email variables to an empty state. This function is intended for use if you run the email sending function +in a loop, permitting the data to be reset between cycles.

+foreach ($list as $name => $address)
+{
+    $this->email->clear();

+ +    $this->email->to($address);
+    $this->email->from('your@your-site.com');
+    $this->email->subject('Here is your info '.$name);
+    $this->email->message('Hi '.$name.' Here is the info you requested.');
+    $this->email->send();
+}
+ + +

$this->email->send()

+

The Email sending function. Returns boolean TRUE or FALSE based on success for failure, enabling it to be used +conditionally.

+ + +

$this->email->attach()

+

Enables you to send an attachment. Put the file path/name in the first parameter. Note: Use a file path, not a URL. +For multiple attachments use the function multiple times. For example:

+ +$this->email->attach('/path/to/photo1.jpg');
+$this->email->attach('/path/to/photo2.jpg');
+$this->email->attach('/path/to/photo3.jpg');
+
+$this->email->send();
+ + +

$this->email->print_debugger()

+

Returns a string containing any server messages, the email headers, and the email messsage. Useful for debugging.

+ + +

Overriding Word Wrapping

+ +

If you have word wrapping enabled (recommended to comply with RFC 822) and you have a very long link in your email it can +get wrapped too, causing it to become un-clickable by the person receiving it. Code Igniter lets you manually override +word wrapping within part of your message like this: + +The text of your email that
+gets wrapped normally.
+
+{unwrap}http://www.some-site.com/a_long_link_that_should_not_be_wrapped.html{/unwrap}
+
+More text that will be
+wrapped normally.
+ +

Place the item you do not want word-wrappd between: {unwrap} {/unwrap} + + +

+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/encryption.html b/user_guide/libraries/encryption.html new file mode 100644 index 000000000..e24e11df9 --- /dev/null +++ b/user_guide/libraries/encryption.html @@ -0,0 +1,187 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Encrypt Class

+ +

The Encrypt Class provides two-way data encryption. It uses a scheme that pre-compiles +the message using a randomly hashed bitwise XOR encoding scheme, which is then encrypted using +the Mcrypt library. If Mcrypt is not available on your server the encoded message will +still provide a reasonable degree of security for encrypted sessions or other such "light" purposes. +If Mcrypt is available, you'll effectively end up with a double-encrypted message string, which should +provide a very high degree of security.

+ + +

Setting your Key

+ +

A key is a piece of information that controls the cryptographic process and permits an encrypted string to be decoded. +In fact, the key you chose will provide the only means to decode data that was encrypted with that key, +so not only must you chose the key carefully, you must must never change it if you intend use it for persistent data.

+ +

It goes without saying that you should guard your key carefully. +Should someone gain access to your key, the data will be easily decoded. If your server is not totally under your control +it's impossible to ensure key security so you may want to think carefully before using it for anything +that requires high security, like storing credit card numbers.

+ +

To take maximum advantage of the encryption algorithm, your key should be 32 characters in length (128 bits). +The key should be as random a string as you can concoct, with numbers and uppercase and lowercase letters. +Your key should not be a simple text string. In order to be cryptographically secure it +needs to be as random as possible.

+ +

Your key can be either stored in your application/config/config.php, or you can design your own +storage mechanism and pass the key dynamically when encoding/decoding.

+ +

To save your key to your application/config/config.php, open the file and set:

+$config['encryption_key'] = "YOUR KEY"; + + +

Message Length

+ +

It's important for you to know that the encoded messages the encryption function generates will be approximately 2.6 times longer than the original +message. For example, if you encrypt the string "my super secret data", which is 21 characters in length, you'll end up +with an encoded string that is roughly 55 characters (we say "roughly" because the encoded string length increments in +64 bit clusters, so it's not exactly linear). Keep this information in mind when selecting your data storage mechanism. Cookies, +for example, can only hold 4K of information.

+ + +

Initializing the Class

+ +

Like most other classes in Code Igniter, the Encrypt class is initialized in your controller using the $this->load->library function:

+ +$this->load->library('encrypt'); +

Once loaded, the Encrypt library object will be available using: $this->encrypt

+ + +

$this->encrypt->encode()

+ +

Performs the data encryption and returns it as a string. Example:

+ +$msg = 'My secret message';
+
+$encrypted_string = $this->encrypt->encode($msg);
+ +

You can optionally pass your encryption key via the second parameter if you don't want to use the one in your config file:

+ + +$msg = 'My secret message';
+$key = 'super-secret-key';
+
+$encrypted_string = $this->encrypt->encode($msg, $key);
+ + +

$this->encrypt->decode()

+ +

Decrypts an encoded string. Example:

+ + +$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';
+
+$plaintext_string = $this->encrypt->decode($encrypted_string);
+ + +

$this->encrypt->set_cypher();

+ +

Permits you to set an Mcrypt cypher. By default it uses MCRYPT_RIJNDAEL_256. Example: +$this->encrypt->set_cypher('MCRYPT_BLOWFISH'); +

Please visit php.net for a list of available cyphers.

+ +

If you'd like to manually test whether your server supports Mcrypt you can use:

+echo ( ! function_exists('mcrypt_encrypt')) ? 'Nope' : 'Yup'; + + +

$this->encrypt->set_mode();

+ +

Permits you to set an Mcrypt mode. By default it uses MCRYPT_MODE_ECB. Example: +$this->encrypt->set_mode('MCRYPT_MODE_CFB'); +

Please visit php.net for a list of available modes.

+ + +

$this->encrypt->sha1();

+

SHA1 encoding function. Provide a string and it will return a 160 bit one way hash. Note: SHA1, just like MD5 is non-decodable. Example:

+$hash = $this->encrypt->sha1('Some string'); + +

Many PHP installations have SHA1 support by default so if all you need is to encode a hash it's simpler to use the native +function:

+ +$hash = sha1('Some string'); + +

If your server does not support SHA1 you can use the provided function.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/file_uploading.html b/user_guide/libraries/file_uploading.html new file mode 100644 index 000000000..7fabb095d --- /dev/null +++ b/user_guide/libraries/file_uploading.html @@ -0,0 +1,429 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

File Uploading Class

+ +

Code Igniter's File Uploading Class permits files to be uploaded. You can set various +preferences, restricting the type and size of the files.

+ + +

The Process

+ +

Uploading a file involves the following general process:

+ + + + +

To demonstrate this process here is brief tutorial. Afterward you'll find reference information.

+ +

Creating the Upload Form

+ + + +

Using a text editor, create a form called upload_form.php. In it, place this code and save it to your applications/views/ +folder:

+ + + + +

You'll notice we are using a form helper to create the opening form tag. File uploads require a multipart form, so the helper +creates the proper syntax for you. You'll also notice we have an $error variable. This is so we can show error messages in the event +the user does something wrong.

+ + +

The Success Page

+ +

Using a text editor, create a form called upload_success.php. +In it, place this code and save it to your applications/views/ folder:

+ + + + +

The Controller

+ +

Using a text editor, create a controller called upload.php. In it, place this code and save it to your applications/controllers/ +folder:

+ + + + + +

The Upload Folder

+ +

You'll need a destination folder for your uploaded images. Create a folder at the root of your Code Igniter installation called +uploads and set its file permissions to 777.

+ + +

Try it!

+ +

To try your form, visit your site using a URL similar to this one:

+ +www.your-site.com/index.php/upload/ + +

You should see an upload form. Try uploading an image file (either a jpg, gif, or png). If the path in your +controller is correct it should work.

+ + +

 

+ +

Reference Guide

+ + +

Initializing the Upload Class

+ +

Like most other classes in Code Igniter, the Upload class is initialized in your controller using the $this->load->library function:

+ +$this->load->library('upload'); +

Once the Upload class is loaded, the object will be available using: $this->upload

+ + +

Setting Preferences

+ +

Similar to other libraries, you'll control what is allowed to be upload based on your preferences. In the controller you +built above you set the following preferences:

+ +$config['upload_path'] = './uploads/';
+$config['allowed_types'] = 'gif|jpg|png';
+$config['max_size'] = '100';
+$config['max_width'] = '1024';
+$config['max_height'] = '768';
+
+$this->upload->initialize($config);
+ +

The above preferences should be fairly self-explanatory. Below is a table describing all available preferences.

+ + +

Preferences

+ +

The following preferences are available. The default value indicates what will be used if you do not specify that preference.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescription
upload_pathNoneNoneThe path to the folder where the upload should be placed. The folder must be writable and the path can be absolute or relative.
allowed_typesNoneNoneThe mime types corresponding to the types of files you allow to be uploaded. Usually the file extension can be used as the mime type. Separate multiple types with a pipe.
overwriteFALSETRUE/FALSE (boolean)If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the same name exists.
max_size0NoneThe maximum size (in kilobytes) that the file can be. Set to zero for no limit. Note: Most PHP installations have their own limit, as specified in the php.ini file. Usually 2 MB (or 2048 KB) by default.
max_width0NoneThe maximum width (in pixels) that the file can be. Set to zero for no limit.
max_height0NoneThe maximum height (in pixels) that the file can be. Set to zero for no limit.
encrypt_nameFALSETRUE/FALSE (boolean)If set to TRUE the file name will be converted to a random encrypted string. This can be useful if you would like the file saved with a name that can not be discerned by the person uploading it.
remove_spacesTRUETRUE/FALSE (boolean)If set to TRUE, any spaces in the file name will be converted to underscores. This is recommended.
+ + +

Setting preferences in a config file

+ +

If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called the upload.php, add the $config +array in that file. Then save the file in: config/upload.php and it will be used automatically. You +will NOT need to use the $this->upload->initialize function if you save your preferences in a config file.

+ + +

Function Reference

+ +

The following functions are available

+ + +

$this->upload->do_upload()

+ +

Performs the upload based on the preferences you've set. Note: The upload routine expects the file to come from a form field +called userfile, and the form must be a "multipart type:

+ +<form method="post" action="some_action" enctype="multipart/form-data" /> + + +

$this->upload->display_errors()

+ +

Retrieves any error messages if the do_upload() function returned false. The function does not echo automatically, it +returns the data so you can assign it however you need.

+ +

Formatting Errors

+

By default the above function wraps any errors within <p> tags. You can set your own delimiters like this:

+ +$this->upload->display_errors('<p>', '</p>'); + +

$this->upload->data()

+ +

This is a helper function that returns an array containing all of the data related to the file you uploaded. +Here is the array prototype:

+ +Array
+(
+    [file_name]    => mypic.jpg
+    [file_type]    => image/jpeg
+    [file_path]    => /path/to/your/upload/
+    [full_path]    => /path/to/your/upload/jpg.jpg
+    [raw_name]     => mypic
+    [orig_name]    => mypic.jpg
+    [file_ext]     => .jpg
+    [file_size]    => 22.2
+    [is_image]     => 1
+    [image_width]  => 800
+    [image_height] => 600
+    [image_type]   => jpeg
+    [image_size_str] => width="800" height="200"
+)
+ +

Explanation

+ +

Here is an explanation of the above array items.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ItemDescription
file_nameThe name of the file that was uploaded including the file extension.
file_typeThe file's Mime type
file_pathThe absolute server path to the file
full_pathThe absolute server path including the file name
raw_nameThe file name without the extension
orig_nameThe original file name. This is only useful if you use the encrypted name option.
file_extThe file extension with period
file_sizeThe file size in kilobytes
is_imageWhether the file is an image or not. 1 = image. 0 = not.
image_widthImage width.
image_heigthImage height
image_typeImage type. Typically the file extension without the period.
image_size_strA string containing the width and height. Useful to put into an image tag.
+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/image_lib.html b/user_guide/libraries/image_lib.html new file mode 100644 index 000000000..ae043b53a --- /dev/null +++ b/user_guide/libraries/image_lib.html @@ -0,0 +1,669 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Image Manipulation Class

+ +

Code Igniter's Image Manipulation class lets you perform the following actions:

+ + + +

All three major image libraries are supported: GD/GD2, NetPBM, and ImageMagick

+ +

Note: Watermarking is only available using the GD/GD2 library. +In addition, even though other libraries are supported, GD is required in +order for the script to calculate the image properties. The image processing, however, will be performed with the +library you specify.

+ + +

Initializing the Class

+ +

Like most other classes in Code Igniter, the image class is initialized in your controller +using the $this->load_library function:

+$this->load->library('image_lib'); + +

Once the library is loaded it will be ready for use. The image library object you will use to call all functions is: $this->image_lib

+ + +

Processing an Image

+ +

Regardless of the type of processing you would like to perform (resizing, cropping, rotation, or watermarking), the general process is +identical. You will set some preferences corresponding to the action you intend to perform, then +call one of four available processing functions. For example, to create an image thumbnail you'll do this:

+ +$config['image_library'] = 'GD';
+$config['source_image'] = '/path/to/image/mypic.jpg';
+$config['create_thumb'] = TRUE;
+$config['maintain_ratio'] = TRUE;
+$config['width'] = 75;
+$config['height'] = 50;
+
+$this->image_lib->initialize($config); +
+
+$this->image_lib->resize();
+ +

The above code tells the image_resize function to look for an image called mypic.jpg +located in the source_image folder, then create a thumbnail that is 75 X 50 pixels using the GD2 image_library. +Since the maintain_ratio option is enabled, the thumb will be as close to the target width and +height as possible while preserving the original aspect ratio. The thumbnail will be called mypic_thumb.jpg +

+ +

Note: In order for the image class to be allowed to do any processing, the +folder containing the image files must have file permissions of 777.

+ + +

Processing Functions

+ +

There are four available processing functions:

+ + + +

These functions return boolean TRUE upon success and FALSE for failure. If they fail you can retrieve the +error message using this function:

+ +echo $this->image_lib->display_errors(); + +

A good practice is use the processing function conditionally, showing an error upon failure, like this:

+ +if ( ! $this->image_lib->resize())
+{
+    echo $this->image_lib->display_errors();
+}
+ +

Note: You can optionally specify the HTML formatting to be applied to the errors, by submitting the opening/closing +tags in the function, like this:

+ +$this->image_lib->display_errors('<p>', '</p>'); + + +

Preferences

+ +

The 14 available preferences described below allow you to tailor the image processing to suit your needs.

+ +

Note that not all preferences are available for every +function. For example, the x/y axis preferences are only available for image cropping. Likewise, the width and height +preferences have no effect on cropping. The "availability" column indicates which functions support a given preference.

+ +

Availability Legend:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescriptionAvailability
image_libraryGD2GD, GD2, ImageMagick, NetPBMSets the image library to be used.R, C, X, W
library_pathNoneNoneSets the server path to your ImageMagick or NetPBM library. If you use either of those libraries you must supply the path.R, C, X
source_imageNoneNoneSets the source image name/path. The path must be a relative or absolute server path, not a URL.R, C, S, W
dynamic_outputFALSETRUE/FALSE (boolean)Determines whether the new image file should be written to disk or generated dynamically. Note: If you choose the dynamic setting, only one image can be shown at a time, and it can't be positioned on the page. It simply outputs the raw image dynamically to your browser, along with image headers.R, C, X, W
quality90%1 - 100%Sets the quality of the image. The higher the quality the larger the file size.R, C, X, W
new_imageNoneNoneSets the destination image name/path. You'll use this preference when creating an image copy. The path must be a relative or absolute server path, not a URL.R
widthNoneNoneSets the width you would like the image set to.R
heightNoneNoneSets the height you would like the image set to.R
create_thumbFALSETRUE/FALSE (boolean)Tells the image processing function to create a thumb.R
thumb_marker_thumbNoneSpecifies the thumbnail indicator. It will be inserted just before the file extension, so mypic.jpg would become mypic_thumb.jpgR
maintain_ratioTRUETRUE/FALSE (boolean)Specifies whether to maintain the original aspect ratio when resizing or use hard values.R
master_dimautoauto, width, heightSpecifies what to use as the master axis when resizing or creating thumbs. For example, let's say you want to resize an image to 100 X 75 pixels. If the source image size does not allow perfect resizing to those dimensions, this setting determines which axis should be used as the hard value. "auto" sets the axis automatically based on whether the image is taller then wider, or vice versa.R
rotation_angleNone90, 180, 270, vrt, horSpecifies the angle of rotation when rotating images. Note that PHP rotates counter-clockwise, so a 90 degree rotation to the right must be specified as 270.X
x_axisNoneNoneSets the X coordinate in pixels for image cropping. For example, a setting of 30 will crop an image 30 pixels from the left.C
y_axisNoneNoneSets the Y coordinate in pixels for image cropping. For example, a setting of 30 will crop an image 30 pixels from the top.C
+ + +

Setting preferences in a config file

+ +

If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called the image_lib.php, add the $config +array in that file. Then save the file in: config/image_lib.php and it will be used automatically. You +will NOT need to use the $this->image_lib->initialize function if you save your preferences in a config file.

+ + +

$this->image_lib->resize()

+ +

The image resizing function lets you resize the original image, create a copy (with or without resizing), +or create a thumbnail image.

+ +

For practical purposes there is no difference between creating a copy and creating +a thumbnail except a thumb will have the thumbnail marker as part of the name (ie, mypic_thumb.jpg).

+ +

All preferences listed in the table above are available for this function except these three: rotation, x_axis, and y_axis.

+ +

Creating a Thumbnail

+ +

The resizing function will create a thumbnail file (and preserve the original) if you set this preference so TRUE:

+ +$config['create_thumb'] = TRUE; + +

This single preference determines whether a thumbnail is created or not.

+ +

Creating a Copy

+ +

The resizing function will create a copy of the image file (and preserve the original) if you set +a path and/or a new filename using this preference:

+ +$config['new_image'] = '/path/to/new_image.jpg'; + +

Notes regarding this preference:

+ + + +

Resizing the Original Image

+ +

If neither of the two preferences listed above (create_thumb, and new_image) are used, the resizing function will instead +target the original image for processing.

+ + +

$this->image_lib->crop()

+ +

The cropping function works nearly identically to the resizing function except it requires that you set +preferences for the X and Y axis (in pixels) specifying where to crop, like this:

+ +$config['x_axis'] = '100';
+$config['x_axis'] = '40';
+ +

All preferences listed in the table above are available for this function except these: rotation, width, height, create_thumb, new_image.

+ +

Here's an example showing how you might crop an image:

+ +$config['image_library'] = 'imagemagick';
+$config['library_path'] = '/usr/X11R6/bin/';
+$config['source_image'] = '/path/to/image/mypic.jpg';
+$config['x_axis'] = '100';
+$config['y_axis'] = '60';
+
+$this->image_lib->initialize($config); +
+
+if ( ! $this->image_lib->crop())
+{
+    echo $this->image_lib->display_errors();
+}
+ + +

Note: Without a visual interface it is difficult to crop images, so this function is not very useful +unless you intend to build such an interface. That's exactly what we did using for the photo +gallery module in ExpressionEngine, the CMS we develop. We added a JavaScript UI that lets the cropping +area be selected.

+ +

$this->image_lib->rotate()

+ +

The image rotation function requires that the angle of rotation be set via its preference:

+ +$config['rotation_angle'] = '90'; + +

There are 5 rotation options:

+ +
    +
  1. 90 - rotates counter-clockwise by 90 degrees.
  2. +
  3. 180 - rotates counter-clockwise by 180 degrees.
  4. +
  5. 270 - rotates counter-clockwise by 270 degrees.
  6. +
  7. hor - flips the image horizontally.
  8. +
  9. vrt - flips the image vertically.
  10. +
+ +

Here's an example showing how you might rotate an image:

+ +$config['image_library'] = 'netpbm';
+$config['library_path'] = '/usr/bin/';
+$config['source_image'] = '/path/to/image/mypic.jpg';
+$config['rotation_angle'] = 'hor';
+
+$this->image_lib->initialize($config); +
+
+if ( ! $this->image_lib->rotate())
+{
+    echo $this->image_lib->display_errors();
+}
+ + + +

 

+

Image Watermarking

+ +

The Watermarking feature requires the GD/GD2 library.

+ + +

Two Types of Watermarking

+ +

There are two types of watermarking that you can use:

+ + + + +

Watermarking an Image

+ +

Just as with the other function (resizing, cropping, and rotating) the general process for watermarking +involves setting the preferences corresponding to the action you intend to perform, then +calling the watermark function. Here is an example:

+ + +$config['source_image'] = '/path/to/image/mypic.jpg';
+$config['wm_text'] = 'Copyright 2006 - John Doe';
+$config['wm_type'] = 'text';
+$config['wm_font_path'] = './system/fonts/texb.ttf';
+$config['wm_font_size'] = '16';
+$config['wm_text_color'] = 'ffffff';
+$config['wm_vrt_alignment'] = 'bottom';
+$config['wm_hor_alignment'] = 'center';
+$config['wm_padding'] = '20';
+
+$this->image_lib->initialize($config); +
+
+$this->image_lib->watermark();
+ + +

The above example will use a 16 pixel True Type font to create the text "Copyright 2006 - John Doe". The watermark +will be positioned at the bottom/center of the image, 20 pixels from the bottom of the image.

+ +

Note: In order for the image class to be allowed to do any processing, the image file must have file permissions of 777.

+ + +

Watermarking Preferences

+ +

This table shown the preferences that are available for both types of watermarking (text or overlay)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescription
wm_typetexttype, overlaySets the type of watermarking that should be used.
source_imageNoneNoneSets the source image name/path. The path must be a relative or absolute server path, not a URL.
dynamic_outputFALSETRUE/FALSE (boolean)Determines whether the new image file should be written to disk or generated dynamically. Note: If you choose the dynamic setting, only one image can be shown at a time, and it can't be positioned on the page. It simply outputs the raw image dynamically to your browser, along with image headers.
quality90%1 - 100%Sets the quality of the image. The higher the quality the larger the file size.
paddingNoneA numberThe amount of padding, set in pixels, that will be applied to the watermark to set it away from the edge of your images.
wm_vrt_alignmentbottomtop, middle, bottomSets the vertical alignment for the watermark image.
wm_hor_alignmentcenterleft, center, rightSets the horizontal alignment for the watermark image.
wm_vrt_offsetNoneNoneYou may specify a horizontal offset (in pixels) to apply to the watermark position. The offset normally moves the watermark to the right, except if you have your alignment set to "right" then your offset value will move the watermark toward the left of the image.
wm_hor_offsetNoneNoneYou may specify a horizontal offset (in pixels) to apply to the watermark position. The offset normally moves the watermark down, except if you have your alignment set to "bottom" then your offset value will move the watermark toward the top of the image.
+ + + +

Text Preferences

+

This table shown the preferences that are available for the text type of watermarking.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescription
wm_textNoneNoneThe text you would like shown as the watermark. Typically this will be a copyright notice.
wm_font_pathNoneNoneThe server path to the True Type Font you would like to use Code Igniter includes a font in the system/fonts folder. If you do not use this option, the native GD font will be used.
wm_font_size16NoneThe size of the text. Note: If you are not using the True Type option above, the number is set using a range of 1 - 5. Otherwise, you can use any valid pixel size for the font you're using.
wm_font_colorffffffNoneThe font color, specified in hex. Note, you must use the full 6 character hex value (ie, 993300), rather than the three character abbreviated version (ie fff).
wm_shadow_colorNoneNoneThe color of the drop shadow, specified in hex. If you leave this blank a drop shadow will not be used. Note, you must use the full 6 character hex value (ie, 993300), rather than the three character abbreviated version (ie fff).
wm_shadow_distance3NoneThe distance (in pixels) from the font that the drop shadow should appear.
+ + + + +

Overlay Preferences

+

This table shown the preferences that are available for the overlay type of watermarking.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefault ValueOptionsDescription
wm_overlay_pathNoneNoneThe server path to the image you wish to use as your watermark. Required only if you are using the overlay method.
wm_opacity501 - 100Image opacity. You may specify the opacity (i.e. transparency) of your watermark image. This allows the watermark to be faint and not completely obscure the details from the original image behind it. A 50% opacity is typical.
wm_x_transp4A numberIf your watermark image is a PNG or GIF image, you may specify a color on the image to be "transparent". This setting (along with the next) will allow you to specify that color. This works by specifying the "X" and "Y" coordinate pixel (measured from the upper left) within the image that corresponds to a pixel representative of the color you want to be transparent.
wm_y_transp4A numberAlong with the previous setting, this allows you to specify the coordinate to a pixel representative of the color you want to be transparent.
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/input.html b/user_guide/libraries/input.html new file mode 100644 index 000000000..0878f9d1e --- /dev/null +++ b/user_guide/libraries/input.html @@ -0,0 +1,207 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Input Class

+ +

The Input Class serves two purposes:

+ +
    +
  1. It pre-processes global input data for security.
  2. +
  3. It provides some helper functions for fetching input data and pre-processing it.
  4. +
+ +

Note: This class is initialized automatically by the system so there is no need to do it manually.

+ + +

Security Filtering

+ +

The security filtering function is called automatically when a new controller is invoked. It does the following:

+ + + + +

XSS Filtering

+ +

Code Igniter comes with a Cross Site Scripting Hack prevention filter which can either run automatically to filter +all POST and COOKIE data that is encountered, or you can run it on a per item basis. By default it does not +run globally since it requires a bit of processing overhead, and since you may not need it in all cases.

+ +

The XSS filter looks for commonly used techniques to trigger Javascript or other types of code that attempt to hijack cookies +or do other malicious things. If anything disallowed is encountered it is rendered safe by converting the data to character entities.

+ +

+Note: This function should only be used to deal with data upon submission. It's not something that should be used for general runtime processing since it requires a fair amount of processing overhead.

+ + +

To filter data through the XSS filter use this function:

+ +

$this->input->xss_clean()

+ +

Here is an usage example:

+ +$data = $this->input->xss_clean($data); + +

If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your +application/config/config.php file and setting this: + +$config['global_xss_filtering'] = TRUE; + +

Note: If you use the form validation class, it gives you the option of XSS filtering as well.

+ + + + +

Using POST or COOKIE Data

+ +

Code Igniter comes with two helper functions that let you fetch POST or COOKIE items. The main advantage of using the provided +functions rather then fetching an item directly ($_POST['something']) is that the functions will check to see if the item is set and +return false (boolean) if not. This lets you conveniently use data without having to test whether an item exists first. +In other words, normally you might do something like this: + + +if ( ! isset($_POST['something']))
+{
+    $something = FALSE;
+}
+else
+{
+    $something = $_POST['something'];
+}
+ +

With Code Igniter's built in functions you can simply do this:

+ +$something = $this->input->post('something'); + +

The two functions are:

+ +

$this->input->post()

+ +

The first parameter will contain the name of the POST item you are looking for:

+ +$this->input->post('some_data'); + +

The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.

+ +

The second optional parameter lets you run the data through the XSS filter. It's enabled by setting the second parameter to boolean TRUE;

+ +$this->input->post('some_data', TRUE); + +

$this->input->cookie()

+ +

This function is identical to the post function, only it fetches cookie data:

+ +$this->input->cookie('some_data', TRUE); + + + + +

$this->input->ip_address()

+

Returns the IP address for the current user. If the IP address is not valid, the function will return an IP of: 0.0.0.0

+echo $this->input->ip_address(); + + +

$this->input->valid_ip($ip)

+ +

Takes an IP address as input and returns TRUE or FALSE (boolean) if it is valid or not. Note: The $this->input->ip_address() function above +validates the IP automatically.

+ +if ( ! valid_id($ip))
+{
+     echo 'Not Valid';
+}
+else
+{
+     echo 'Valid';
+}
+ + +

$this->input->user_agent()

+

Returns the user agent (web browser) being used by the current user. Returns FALSE if it's not available.

+echo $this->input->user_agent(); + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/language.html b/user_guide/libraries/language.html new file mode 100644 index 000000000..98ef4b090 --- /dev/null +++ b/user_guide/libraries/language.html @@ -0,0 +1,130 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Language Class

+ +

The Language Class provides functions to retrieve language files and lines of text for purposes of internationalization.

+ +

In your Code Igniter system folder you'll find one called language containing sets of language files. You can create +your own language files as needed in order to display error and other messages in other languages.

+ +

Creating Language Files

+ +

Language files must be named with _lang.php as the file extension. For example, let's say you want to create a file +containing error messages. You might name it: error_lang.php

+ +

Within the file you will assign each line of text to an array called $lang with this prototype:

+ +$lang['language_key'] = "The actual message to be shown"; + +

Note: It's a good practice to use a common prefix for all messages in a given file to avoid collisions with +similarly named items in other files:

+ +$lang['error_email_missing'] = "You must submit an email address";
+$lang['error_url_missing'] = "You must submit a URL";
+$lang['error_username_missing'] = "You must submit a username";
+ + +

Loading A Language File

+ +

In order to fetch a line from a particular file you must load the file first. Loading a language file is done with the following code:

+ +$this->lang->load('filename', 'language'); + +

Where filename is the name of the file you wish to load (without the file extension), and language +is the language set containing it (ie, english). If the second parameter is missing, the default language set in your +application/config/config.php file will be used.

+ + +

Fetching a Line of Text

+ +

Once your desired language file is loaded you can access any line of text using this function:

+ +$this->lang->line('language_key'); + +

Where language_key is the array key corresponding to the line you wish to show.

+ +

Note: This function simply returns the line. It does not echo it for you.

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/loader.html b/user_guide/libraries/loader.html new file mode 100644 index 000000000..630a2ea6f --- /dev/null +++ b/user_guide/libraries/loader.html @@ -0,0 +1,171 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Loader Class

+ +

Loader, as the name suggests, is used to load elements. These elements can be libraries (classes) View files, +Helpers, Plugins, or your own files.

+ +

Note: This class is initialized automatically by the system so there is no need to do it manually.

+ +

The following functions are available in this class:

+ + + +

$this->load->view('file_name', $data, true/false)

+ +

This function is used to load your View files. If you haven't read the Views section of the +user guide it is recommended that you do since it shows you how this function is typically used.

+ +

The first parameter is required. It is the name of the view file you would like to load.

+ +

The second optional parameter can take +an associative array or an object as input, which it runs through the PHP extract function to +convert to variables that can be used in your view files. Again, read the Views page to learn +how this might be useful.

+ +

The third optional parameter lets you change the behavior of the function so that it returns data as a string +rather than sending it to your browser. This can be useful if you want to process the data in some way. If you +set the parameter to true (boolean) it will return data. The default behavior is false, which sends it +to your browser. Remember to assign it to a variable if you wan the data returned:

+ +$string = $this->load->view('myfile', '', true); + + + +

$this->load->library('class_name')

+ +

This function is used to load core classes. Where class_name is the name of the class you want to load. +Note: We use the terms "class" and "library" interchangeably.

+ +

For example, if you would like to send email with Code Igniter, the first step is to load the email class within your controller:

+ +$this->load->library('email'); + +

Once loaded, the library will be ready for use. Each library is described in detail in its own page, so please read the +information regarding each one you would like to use.

+ + + +

$this->load->database('options', true/false)

+ +

This function lets you load the database class. The two parameters are optional. Please see the +database section for more info.

+ + +

$this->load->scaffolding('table_name')

+ +

This function lets you enable scaffolding. Please see the +scaffolding section for more info.

+ + + +

$this->load->vars($array)

+ +

This function takes an associative array as input and generates variables using the PHP extract function. +This function produces the same result as using the second parameter of the $this->load->view() function above. The reason you might +want to use this function independently is if you would like to set some global variables in the constructor of your controller +and have them become available in any view file loaded from any function. You can have multiple calls to this function. The data get cached +and merged into one array for conversion to variables. +

+ + +

$this->load->helper('file_name')

+

This function loads helper files, where file_name is the name of the file, without the _helper.php extension.

+ + +

$this->load->plugin('file_name')

+

This function loads plugins files, where file_name is the name of the file, without the _plugin.php extension.

+ +

$this->load->file('filepath/filename', true/false)

+

This is a generic file loading function. Supply the filepath and name in the first parameter and it will open and read the file. +By default the data is sent to your browser, just like a View file, but if you set the second parameter to true (boolean) +it will instead return the data as a string.

+ + +

$this->load->lang('file_name')

+

This function is an alias of the language loading function: $this->lang->load()

+ +

$this->load->config('file_name')

+

This function is an alias of the config file loading function: $this->config->load()

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/output.html b/user_guide/libraries/output.html new file mode 100644 index 000000000..1a4537af6 --- /dev/null +++ b/user_guide/libraries/output.html @@ -0,0 +1,112 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Output Class

+ +

The Output class is a small class with one main function: To send the finalized web page to the requesting browser. It is +also responsible for caching your web pages, if you use that feature.

+ +

Note: This class is initialized automatically by the system so there is no need to do it manually.

+ +

Under normal circumstances you won't even notice the Output class since it works transparently without your intervention. +For example, when you use the Loader class to load a view file, it's automatically +passed to the Output class, which will be called automatically by Code Igniter at the end of system execution. +It is possible, however, for you to manually intervene with the output if you need to, using either of the two following functions:

+ +

$this->output->set_output();

+ +

Permits you to manually set the final output string. Usage example:

+ +$this->output->set_output($data); + +

Important: If you do set your output manually, it must be the last thing done in the function you call it from. +For example, if you build a page in one of your controller functions, don't set the output until the end.

+ + +

$this->output->get_output();

+ +

Permits you to manually retrieve any output that has been sent for storage in the output class. Usage example:

+$string = $this->output->get_output(); + +

Note that data will only be retrievable from this function if it has been previously sent to the output class by one of the +Code Igniter functions like $this->load->view().

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/pagination.html b/user_guide/libraries/pagination.html new file mode 100644 index 000000000..3f4e56935 --- /dev/null +++ b/user_guide/libraries/pagination.html @@ -0,0 +1,218 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Pagination Class

+ +

Code Igniter's Pagination class is very easy to use, and it is 100% customizable, ether dynamically or via stored preferences.

+ +

If you are not familiar with the term "pagination", it refers to links that allows you to navigate from page to page, like this:

+ +« First  < 1 2 3 4 5 >  Last » + +

Example

+ +

Here is a simple example showing how to create pagination in one of your controller functions:

+ + +$this->load->library('pagination');

+$config['base_url'] = 'http://www.your-site.com/index.php/test/page/';
+$config['total_rows'] = '200';
+$config['per_page'] = '20'; +

+$this->pagination->initialize($config); + +

+echo $this->pagination->create_links();
+ +

Notes:

+ +

The $config array contains your configuration variables. It is passed to the $this->pagination->initialize function as shown above. Although there are some twenty items you can configure, at +minimum you need the three shown. Here is a description of what those items represent:

+ + + +

The create_links() function returns an empty string when there is no pagination to show. + + +

Setting preferences in a config file

+ +

If you prefer not to set preferences using the above method, you can instead put them into a config file. +Simply create a new file called the pagination.php, add the $config +array in that file. Then save the file in: config/pagination.php and it will be used automatically. You +will NOT need to use the $this->pagination->initialize function if you save your preferences in a config file.

+ + +

Customizing the Pagination

+ +

The following is a list of all the preferences you can pass to the initialization function to tailor the display.

+ + +

$config['uri_segment'] = 3;

+ +

The pagination function automatically determines which segment of your URI contains the page number. If you need +something different you can specify it.

+ +

$config['num_links'] = 2;

+ +

The number of "digit" links you would like before and after the the selected page number. For example, the number 2 +will place two digits on either side, as in the example links at the very top of this page.

+ +

Adding Enclosing Markup

+ +

If you would like to surround the entire pagination with some markup you can do it with these two prefs:

+ +

$config['full_tag_open'] = '<p>';

+

The opening tag placed on the left side of the entire result.

+ +

$config['full_tag_close'] = '</p>';

+

The closing tag placed on the right side of the entire result.

+ + +

Customizing the First Link

+ +

$config['first_link'] = 'First';

+

The text you would like shown in the "first" link on the left.

+ +

$config['first_tag_open'] = '<div>';

+

The opening tag for the "first" link.

+ +

$config['first_tag_close'] = '</div>';

+

The closing tag for the "first" link.

+ +

Customizing the Last Link

+ +

$config['last_link'] = 'Last';

+

The text you would like shown in the "last" link on the right.

+ +

$config['last_tag_open'] = '<div>';

+

The opening tag for the "last" link.

+ +

$config['last_tag_close'] = '</div>';

+

The closing tag for the "last" link.

+ +

Customizing the "Next" Link

+ +

$config['next_link'] = '&gt';

+

The text you would like shown in the "next" page link.

+ +

$config['next_tag_open'] = '<div>';

+

The opening tag for the "next" link.

+ +

$config['next_tag_close'] = '</div>';

+

The closing tag for the "next" link.

+ +

Customizing the "Previous" Link

+ +

$config['prev_link'] = '&lt';

+

The text you would like shown in the "previous" page link.

+ +

$config['prev_tag_open'] = '<div>';

+

The opening tag for the "previous" link.

+ +

$config['prev_tag_close'] = '</div>';

+

The closing tag for the "previous" link.

+ +

Customizing the "Current Page" Link

+ +

$config['cur_tag_open'] = '<b>';

+

The opening tag for the "current" link.

+ +

$config['cur_tag_close'] = '</b>';

+

The closing tag for the "current" link.

+ + +

Customizing the "Digit" Link

+ +

$config['num_tag_open'] = '<div>';

+

The opening tag for the "digit" link.

+ +

$config['num_tag_close'] = '</div>';

+

The closing tag for the "digit" link.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/parser.html b/user_guide/libraries/parser.html new file mode 100644 index 000000000..f8ddd41c3 --- /dev/null +++ b/user_guide/libraries/parser.html @@ -0,0 +1,214 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + + + +

Template Parser Class

+ +

The Template Parser Class enables you to parse pseudo-variables contained within your view files. It can parse simple +variables or variable tag pairs. If you've never used a template engine, pseudo-variables look like this:

+ +<html>
+<head>
+<title>{blog_title}</title>
+</head>
+<body>
+
+<h3>{blog_heading}</h3>
+
+{blog_entries}
+<h5>{title}</h5>
+<p>{body}</p>
+{/blog_entries}
+ +</body>
+</html>
+ +

These variables are not actual PHP variables, but rather plain text representations that allow you to eliminate +PHP from your templates (view files).

+ +

Note: Code Igniter does not require you to use this class +since using pure PHP in your view pages lets them run a little faster. However, some developers prefer to use a template engine if +they work with designers who they feel would find some confusion working with PHP.

+ +

Also Note: The Template Parser Class is not not a +full-blown template parsing solution. We've kept it very lean on purpose in order to maintain maximum performance. + +

+ + +

Initializing the Class

+ +

Like most other classes in Code Igniter, the Parser class is initialized in your controller using the $this->load->library function:

+ +$this->load->library('parser'); +

Once loaded, the Parser library object will be available using: $this->parser

+ +

The following functions are available in this library:

+ +

$this->parser->parse()

+ +

This variable accepts a template name and data array as input, and it generates a parsed version. Example:

+ +$this->load->library('parser');
+
+$data = array(
+            'blog_title' => 'My Blog Title',
+            'blog_heading' => 'My Blog Heading'
+            );
+
+$this->parser->parse('blog_template', $data);
+ +

The first parameter contains the name of the view file (in this example the file would be called blog_template.php), +and the second parameter contains an associative array of data to be replaced in the template. In the above example, the +template would contain two variables: {blog_title} and {blog_heading}

+ +

There is no need to "echo" or do something with the data returned by $this->parser->parse(). It is automatically +passed to the output class to be sent to the browser. However, if you do want the data returned instead of sent to the output class you can +pass TRUE (boolean) to the third parameter:

+ +$string = $this->parser->parse('blog_template', $data, TRUE); + + +

Variable Pairs

+ +

The above example code allows simple variables to be replaced. What if you would like an entire block of variables to be +repeated, with each iteration containing new values? Consider the template example we showed at the top of the page:

+ +<html>
+<head>
+<title>{blog_title}</title>
+</head>
+<body>
+
+<h3>{blog_heading}</h3>
+
+{blog_entries}
+<h5>{title}</h5>
+<p>{body}</p>
+{/blog_entries}
+ +</body>
+</html>
+ +

In the above code you'll notice a pair of variables: {blog_entries} data... {/blog_entries}. +In a case like this, the entire chunk of data between these pairs would be repeated multiple times, corresponding +to the number of rows in a result.

+ +

Parsing variable pairs is done using the identical code shown above to parse single variables, +except, you will add a multi-dimensional array corresponding to your variable pair data. +Consider this example:

+ + +$this->load->library('parser');
+
+$data = array(
+              'blog_title'   => 'My Blog Title',
+              'blog_heading' => 'My Blog Heading',
+              'blog_entries' => array(
+                                      array('title' => 'Title 1', 'body' => 'Body 1'),
+                                      array('title' => 'Title 2', 'body' => 'Body 2'),
+                                      array('title' => 'Title 3', 'body' => 'Body 3'),
+                                      array('title' => 'Title 4', 'body' => 'Body 4'),
+                                      array('title' => 'Title 5', 'body' => 'Body 5')
+                                      )
+            );
+
+$this->parser->parse('blog_template', $data);
+ +

If your "pair" data is coming from a database result, which is already a multi-dimensional array, you can simply +use the database result function:

+ + +$query = $this->db->query("SELECT * FROM blog");
+
+$this->load->library('parser');
+
+$data = array(
+              'blog_title'   => 'My Blog Title',
+              'blog_heading' => 'My Blog Heading',
+              'blog_entries' => $query->result_array()
+            );
+
+$this->parser->parse('blog_template', $data);
+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/sessions.html b/user_guide/libraries/sessions.html new file mode 100644 index 000000000..1050e1102 --- /dev/null +++ b/user_guide/libraries/sessions.html @@ -0,0 +1,283 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Session Class

+ +

The Session class permits you maintain a user's "state" and track their activity while they browse your site. +The Session class stores session information for each user as serialized (and optionally encrypted) data in a cookie. +It can also store the session data in a database table for added security, as this permits the session ID in the +user's cookie to be matched against the stored session ID. By default only the cookie is saved. If you choose to +use the database option you'll need to create the session table as indicated below. +

+ +

Note: The Session class does not utilize native PHP sessions. It +generates its own session data, offering more flexibility for developers.

+ +

Initializing a Session

+ +

Sessions will typically run globally with each page load, so the session class must either be +initialized in your +controller constructors, or it can be +auto-loaded by the system. +For the most part the session class will run unattended in the background, so simply initializing the class +will cause it to read, create, and update sessions.

+ + +

To initialize the Session class manually in your controller constructor, use the $this->load->library function:

+ +$this->load->library('session'); +

Once loaded, the Sessions library object will be available using: $this->session

+ + +

How do Sessions work?

+ +

When a page is loaded, the session class will check to see if valid session data exists in the user's session cookie. +If sessions data does not exist (or if it has expired) a new session will be created and saved in the cookie. +If a session does exist, its information will be updated and the cookie will be updated.

+ +

It's important for you to understand that once initialized, the Session class runs automatically. There is nothing +you need to do to cause the above behavior to happen. You can, as you'll see below, work with session data or +even add your own data to a user's session, but the process of reading, writing, and updating a session is automatic.

+ + +

What is Session Data?

+ +

A session, as far as Code Igniter is concerned, is simply an array containing the following information:

+ + + +

The above data is stored in a cookie as a serialized array with this prototype:

+ +[array]
+(
+     'session_id'    => random hash,
+     'ip_address'    => 'string - user IP address',
+     'user_agent'    => 'string - user agent data',
+     'last_activity' => timestamp,
+     'last_visit'    => timestamp
+)
+ +

If you have the encryption option enabled, the serialized array will be encrypted before being stored in the cookie, +making the data highly secure and impervious to being read or altered by someone. More info regarding encryption +can be found here, although the Session class will take care of initializing +and encrypting the data automatically.

+ +

Note: Session cookies are only updated every five minutes to reduce processor load. If you repeatedly reload a page +you'll notice that the "last activity" time only updates if five minutes or more has passed since the last time +the cookie was written.

+ +

Retrieving Session Data

+ +

Any piece of information from the session array is available using the following function:

+ +$this->session->userdata('item'); + +

Where item is the array index corresponding to the item you wish to fetch. For example, to fetch the session ID you +will do this:

+ +$session_id = $this->session->userdata('session_id'); + +

Note: The function returns FALSE (boolean) if the item you are trying to access does not exist.

+ + +

Adding Custom Session Data

+ +

A useful aspect of the session array is that you can add your own data to it and it will be stored in the user's cookie. +Why would you want to do this? Here's one example:

+ +

Let's say a particular user logs into your site. Once authenticated, +you could add their username and email address to the session cookie, making that data globally available to you without +having to run a database query when you need it.

+ +

To add your data to the session array involves passing an array containing your new data to this function:

+ +$this->session->set_userdata($array); + +

Where $array is an associative array containing your new data. Here's an example:

+ + +$newdata = array(
+                   'username'  => 'johndoe',
+                   'email'     => 'johndoe@some-site.com',
+                   'logged_in' => TRUE
+               );
+
+$this->session->set_userdata($newdata);
+ +

Note: Cookies can only hold 4KB of data, so be careful not to exceed the capacity. The +encryption process in particular produces a longer data string than the original so keep careful track of how much data you are storing.

+ +

Saving Session Data to a Database

+ +

While the session data array stored in the user's cookie contains a Session ID, +unless you store session data in a database there is no way to validate it. For some applications that require little or no +security, session ID validation may not be needed, but if your application requires security, validation is mandatory.

+ +

When session data is available in a database, every time a valid session is found in the user's cookie, a database +query is performed to match it. If the session ID does not match, the session is destroyed. Session IDs can never +be updated, they can only be generated when a new session is created.

+ +

In order to store sessions, you must first create a database table for this purpose. Here is the basic +prototype required by the session class:

+ + + +

Note: By default the table is called ci_sessions, but you can name it anything you want +as long as you update the application/config/config.php file so that it contains the name you have chosen. +Once you have created your database table you can enable the database option in your config.php file as follows:

+ +$config['sess_use_database'] = TRUE; + +

Once enabled, the Session class will store session data in the DB.

+ +

Session Preferences

+ +

You'll find the following Session related preferences in your application/config/config.php file:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PreferenceDefaultOptionsDescription
sess_cookie_nameci_sessionNoneThe name you world the session cookie saved as.
sess_expiration7200NoneThe number of seconds you would like the session to last. The default value is 2 hours (7200 seconds). +If you would like a non-expiring session set the value to zero: 0
sess_encrypt_cookieTRUETRUE/FALSE (boolean)Whether to encrypt the session data.
sess_use_databaseFALSETRUE/FALSE (boolean)Whether to save the session data to a database. You must create the table before enabling this option.
sess_table_nameci_sessionsAny valid SQL table nameThe name of the session database table.
sess_match_ipFALSETRUE/FALSE (boolean)Whether to match the user's IP address when reading the session data. Note that some ISPs dynamically +changes the IP, so if you want a non-expiring session you will likely set this to FALSE.
sess_match_useragentTRUETRUE/FALSE (boolean)Whether to match the User Agent when reading the session data.
+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/trackback.html b/user_guide/libraries/trackback.html new file mode 100644 index 000000000..71b9be040 --- /dev/null +++ b/user_guide/libraries/trackback.html @@ -0,0 +1,251 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Trackback Class

+ +

The Trackback Class provides functions that enable you to send and receive Trackback data.

+ + +

If you are not familiar with Trackbacks you'll find more information here.

+ +

Initializing the Class

+ +

Like most other classes in Code Igniter, the Trackback class is initialized in your controller using the $this->load->library function:

+ +$this->load->library('trackback'); +

Once loaded, the Trackback library object will be available using: $this->trackback

+ + +

Sending Trackbacks

+ +

A Trackback can be sent from any of your controller functions using code similar to this example: + +$this->load->library('trackback');
+
+$tb_data = array(
+                'ping_url'  => 'http://some-site.com/trackback/456',
+                'url'       => 'http://www.my-site.com/blog/entry/123',
+                'title'     => 'The Title of My Entry',
+                'excerpt'   => 'The entry content.',
+                'blog_name' => 'My Blog Name',
+                'charset'   => 'utf-8'
+                );
+
+if ( ! $this->trackback->send($tb_data))
+{
+     echo $this->trackback->display_errors();
+}
+else
+{
+     echo 'Trackback was sent!';
+}
+ +

Description of array data:

+ + + +

The Trackback sending function returns TRUE/FALSE (boolean) on success or failure. If it fails, you can retrieve the error message using:

+ +$this->trackback->display_errors(); + + +

Receiving Trackbacks

+ +

Before you can receive Trackbacks you must create a weblog. If you don't have a blog yet there's no point in continuing.

+ +

Receiving Trackbacks is a little more complex than sending them, only because you will need a database table in which to store them, +and you will need to validate the incoming trackback data. You are encouraged to implement a thorough validation process to +guard against spam and duplicate data. You may also want to limit the number of Trackbacks you allow from a particular IP within +a given span of time to further curtail spam. The process of receiving a Trackback is quite simple; +the validation is what takes most of the effort.

+ +

Your Ping URL

+ +

In order to accept Trackbacks you must display a Trackback URL next to each one of your weblog entries. This will be the URL +that people will use to send you Trackbacks (we will refer to this as your "Ping URL").

+ +

Your Ping URL must point to a controller function where your Trackback receiving code is located, and the URL +must contain the ID number for each particular entry, so that when the Trackback is received you'll be +able to associate it with a particular entry.

+ +

For example, if your controller class is called Trackback, and the receiving function is called receive, your +Ping URLs will look something like this:

+ +http://www.your-site.com/index.php/trackback/receive/entry_id + +

Where entry_id represents the individual ID number for each of your entries.

+ + +

Creating a Trackback Table

+ +

Before you can receive Trackbacks you must create a table in which to store them. Here is a basic prototype for such a table:

+ + + + +

The Trackback specification only requires four pieces of information to be sent in a Trackback (url, title, excerpt, blog_name), +but to make the data more useful we've added a few more fields in the above table schema (date, IP address, etc.).

+ +

Processing a Trackback

+ +

Here is an example showing how you will receive and process a Trackback. The following +code is intended for use within the controller function where you expect to receive Trackbacks.

+ +$this->load->library('trackback');
+$this->load->database();
+
+if ($this->uri->segment(3) == FALSE)
+{
+    $this->trackback->send_error("Unable to determine the entry ID");
+}
+
+if ( ! $this->trackback->receive())
+{
+    $this->trackback->send_error("The Trackback did not contain valid data");
+}
+
+$data = array(
+                'tb_id'      => '',
+                'entry_id'   => $this->uri->segment(3),
+                'url'        => $this->trackback->data('url'),
+                'title'      => $this->trackback->data('title'),
+                'excerpt'    => $this->trackback->data('excerpt'),
+                'blog_name'  => $this->trackback->data('blog_name'),
+                'tb_date'    => time(),
+                'ip_address' => $this->input->ip_address()
+                );
+
+$sql = $this->db->insert_string('trackbacks', $data);
+$this->db->query($sql);
+
+$this->trackback->send_success();
+ +

Notes:

+ +

The entry ID number is expected in the third segment of your URL. This is based on the URI example we gave earlier:

+ +http://www.your-site.com/index.php/trackback/receive/entry_id + +

Notice the entry_id is in the third URI, which you can retrieve using:

+ +$this->uri->segment(3); + +

In our Trackback receiving code above, if the third segment is missing, we will issue an error. Without a valid entry ID, there's no +reason to continue.

+ +

The $this->trackback->receive() function is simply a validation function that looks at the incoming data +and makes sure it contains the four pieces of data that are required (url, title, excerpt, blog_name). +It returns TRUE on success and FALSE on failure. If it fails you will issue an error message.

+ +

The incoming Trackback data can be retrieved using this function:

+ +$this->trackback->data('item') + +

Where item represents one of these four pieces of info: url, title, excerpt, or blog_name

+ +

If the Trackback data is successfully received, you will issue a success message using:

+ +$this->trackback->send_success(); + +

Note: The above code contains no data validation, which you are encouraged to add.

+ + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/unit_testing.html b/user_guide/libraries/unit_testing.html new file mode 100644 index 000000000..182e29e31 --- /dev/null +++ b/user_guide/libraries/unit_testing.html @@ -0,0 +1,210 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Unit Testing Class

+ +

Unit testing is an approach to software development in which tests are written for each function in your application. +If you are not familiar with the concept you might do a little googling on the subject.

+ +

Code Igniter's Unit Test class is quite simple, consisting of an evaluation function and two result functions. +It's not intended to be a full-blown test suite but rather a simple mechanism to evaluate your code +to determine if it is producing the correct data type and result. +

+ + +

Initializing the Class

+ +

Like most other classes in Code Igniter, the Unit Test class is initialized in your controller using the $this->load->library function:

+ +$this->load->library('unit_test'); +

Once loaded, the Unit Test object will be available using: $this->unit

+ + +

Running Tests

+ +

Running a test involves supplying a test and an expected result to the following function:

+ +

$this->unit->run( test, expected result, 'test name' );

+ +

Where test is the result of the code you wish to test, +expected result is the data type you expect, and test name is an optional name you can give your test. Example:

+ +$test = 1 + 1;
+
+$expected_result = 2;
+
+$test_name = 'Adds one plus one';
+
+$this->unit->run($test, $expected_result, $test_name);
+ +

The expected result you supply can either be a literal match, or a data type match. Here's an example of a literal:

+ +$this->unit->run('Foo', 'Foo'); + +

Here is an example of a data type match:

+ +$this->unit->run('Foo', 'is_string'); + +

Notice the use of "is_string" in the second parameter? This tells the function to evaluate whether your test is producing a string +as the result. Here is a list of allowed comparison types:

+ + + + +

Generating Reports

+ +

You can either display results after each test, or your can run several tests and generate a report at the end. +To show a report directly simply echo or return the run function:

+ +echo $this->unit->run($test, $expected_result); + +

To run a full report of all tests, use this:

+ +echo $this->unit->report(); + +

The report will be formatted in an HTML table for viewing. If you prefer the raw data you can retrieve an array using:

+ +echo $this->unit->result(); + + +

Strict Mode

+ +

By default the unit test class evaluates literal matches loosely. Consider this example:

+ +$this->unit->run(1, TRUE); + +

The test is evaluating an integer, but the expected result is a boolean. PHP, however, due to it's loose data-typing +will evaluate the above code as TRUE using a normal equality test:

+ +if (1 == TRUE) echo 'This evaluates as true'; + +

If you prefer, you can put the unit test class in to strict mode, which will compare the data type as well as the value:

+ +if (1 === TRUE) echo 'This evaluates as FALSE'; + +

To enable strict mode use this:

+ +$this->unit->strict(TRUE); + +

Enabling/Disabling Unit Testing

+ +

If you would like to leave some testing in place in your scripts, but not have it run unless you need it, you can disable +unit testing using:

+ +$this->unit->active(FALSE) + + + +

Creating a Template

+ +

If you would like your test results formatted differently then the default you can set your own template. Here is an +example of a simple template. Note the required pseudo-variables:

+ + +$str = '
+<table border="0" cellpadding="4" cellspacing="1">
+    {rows}
+        <tr>
+        <td>{item}</td>
+        <td>{result}</td>
+        </tr>
+    {/rows}
+</table>';
+
+$this->unit->set_template($str); +
+ + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/uri.html b/user_guide/libraries/uri.html new file mode 100644 index 000000000..5218cea86 --- /dev/null +++ b/user_guide/libraries/uri.html @@ -0,0 +1,220 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

URI Class

+ +

The URI Class provides functions that help you retrieve information from your URI strings.

+ +

Note: This class is initialized automatically by the system so there is no need to do it manually.

+ +

$this->uri->segment(n)

+ +

Permits you to retrieve a specific segment. Where n is the segment number you wish to retrieve. +Segments are numbered from left to right. For example, if your full URL is this:

+ +http://www.your-site.com/index.php/news/local/metro/crime_is_up + +

The segment numbers would be this:

+ +
    +
  1. news
  2. +
  3. local
  4. +
  5. metro
  6. +
  7. crime_is_up
  8. +
+ +

By default the function returns FALSE (boolean) if the segment does not exist. There is an optional second parameter that +permits you to set your own default value if the segment is missing. +For example, this would tell the function to return the number zero in the event of failure:

+ +$product_id = $this->uri->segment(3, 0); + +

It helps avoid having to write code like this:

+ +if ($this->uri->segment(3) === FALSE)
+{
+    $product_id = 0;
+}
+else
+{
+    $product_id = $this->uri->segment(3);
+}
+
+ + +

$this->uri->slash_segment(n)

+ +

This function is almost identical to the one above, except it adds a trailing and/or leading slash based on the second +parameter. If the parameter is not used, a trailing slash added. Examples:

+ +$this->uri->slash_segment(3);
+$this->uri->slash_segment(3, 'leading');
+$this->uri->slash_segment(3, 'both');
+ +

Returns:

+ +
    +
  1. segment/
  2. +
  3. /segment
  4. +
  5. /segment/
  6. +
+ + +

$this->uri->uri_to_assoc(n)

+ +

This function lets you turn URI segments into and associative array of key/value pairs. Consider this URI:

+ +index.php/user/search/name/joe/location/UK/gender/male + +

Using this function you can turn the URI into an associative array with this prototype:

+ +[array]
+(
+    'name' => 'joe'
+    'location' => 'UK'
+    'gender' => 'male'
+)
+ +

The first parameter of the function lets you set an offset. By default it is set to 3 since your +URI will normally contain a controller/function in the first and second segments. Example:

+ + +$array = $this->uri->uri_to_assoc(3);
+
+echo $array['name']; +
+ + +

The second parameter lets you set default key names, so that the array returned by the function will always contain expected indexes, even if missing from the URI. Example:

+ + +$default = array('name', 'gender', 'location', 'type', 'sort');
+
+$array = $this->uri->uri_to_assoc(3, $default);
+ +

If the URI does not contain a value in your default, an array index will be set to that name, with a value of FALSE.

+ +

Lastly, if a corresponding value is not found for a given key (if there is an odd number of URI segments) the value will be set to FALSE (boolean).

+ + +

$this->uri->assoc_to_uri()

+ +

Takes an associative array as input and generates a URI string from it. The array keys will be included in the string. Example:

+ +$array = array('product' => 'shoes', 'size' => 'large', 'color' => 'red');
+
+$str = $this->uri->assoc_to_str($array);
+
+// Produces: product/shoes/size/large/color/red +
+ + +

$this->uri->uri_string()

+ +

Returns a string with the complete URI. For example, if this is your full URL:

+ +http://www.your-site.com/index.php/news/local/345 + +

The function would return this:

+ +news/local/345 + + +

$this->uri->total_segments()

+ +

Returns the total number of segments.

+ + + +

$this->uri->segment_array()

+ +

Returns an array containing the URI segments. For example:

+ + +$segs = $this->uri->segment_array();
+
+foreach ($segs as $segment)
+{
+    echo $segment;
+    echo '<br />';
+}
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/validation.html b/user_guide/libraries/validation.html new file mode 100644 index 000000000..2489aa6e9 --- /dev/null +++ b/user_guide/libraries/validation.html @@ -0,0 +1,674 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Form Validation

+ +

Before explaining Code Igniter's approach to data validation, let's describe the ideal scenario:

+ +
    +
  1. A form is displayed.
  2. +
  3. You fill it in and submit it.
  4. +
  5. If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data along with an error message describing the problem.
  6. +
  7. This process continues until you have submitted a valid form.
  8. +
+ +

On the receiving end, the script must:

+ +
    +
  1. Check for required data.
  2. +
  3. Verify that the data is of the correct type, and meets the correct criteria. (For example, if a username is submitted +it must be validated to contain only permitted characters. It must be of a minimum length, +and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.) +
  4. Sanitize the data for security.
  5. +
  6. Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)
  7. +
  8. Prep the data for insertion in the database.
  9. +
+ + +

Although there is nothing complex about the above process, it usually requires a significant +amount of code, and to display error messages, various control structures are usually placed within the form HTML. +Form validation, while simple to create, is generally very messy and tedious to implement.

+ +Code Igniter provides a comprehensive validation framework that truly minimizes the amount of code you'll write. +It also removes all control structures from your form HTML, permitting it to be clean and free of code. + +

Overview

+ +

In order to implement Code Igniter's form validation you'll need three things:

+ +
    +
  1. A View file containing the form.
  2. +
  3. A View file containing a "success" message to be displayed upon successful submission.
  4. +
  5. A controller function to receive and process the submitted data.
  6. +
+ +

Let's create those three things, using a member sign-up form as the example.

+ +

The Form

+ +

Using a text editor, create a form called myform.php. In it, place this code and save it to your applications/views/ +folder:

+ + + + + +

The Success Page

+ + +

Using a text editor, create a form called formsuccess.php. In it, place this code and save it to your applications/views/ +folder:

+ + + + + +

The Controller

+ +

Using a text editor, create a controller called form.php. In it, place this code and save it to your applications/controllers/ +folder:

+ + + + + +

Try it!

+ +

To try your form, visit your site using a URL similar to this one:

+ +www.your-site.com/index.php/form/ + +

If you submit the form you should simply see the form reload. That's because you haven't set up any validation +rules yet, which we'll get to in a moment.

+ + +

Explanation

+ +

You'll notice several things about the above pages:

+ +

The form (myform.php) is a standard web form with a couple exceptions:

+ +
    +
  1. It uses a form helper to create the form opening. +Technically, this isn't necessary. You could create the form using standard HTML. However, the benefit of using the helper +is that it generates the action URL for you, based on the URL in your config file. This makes your application more portable +and flexible in the event your URLs change.
  2. + +
  3. At the top of the form you'll notice the following variable: +<?=$this->validation->error_string; ?> + +

    This variable will display any error messages sent back by the validator. If there are no messages it returns nothing.

    +
  4. +
+ +

The controller (form.php) has one function: index(). This function initializes the validation class and +loads the form helper and URL helper used by your view files. It also runs +the validation routine. Based on +whether the validation was successful it either presents the form or the success page.

+ +

Since you haven't told the validation class to validate anything yet, it returns "false" (boolean false) by default. The run() +function only returns "true" if it has successfully applied your rules without any of them failing.

+ + +

Setting Validation Rules

+ +

Code Igniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data +at the same time. Let's see it in action, we'll explain it afterwards.

+ +

In your controller (form.php), add this code just below the validation initialization function:

+ +$rules['username'] = "required";
+$rules['password'] = "required";
+$rules['passconf'] = "required";
+$rules['email'] = "required";
+
+$this->validation->set_rules($rules);
+ +

Your controller should now look like this:

+ + + +

Now submit the form with the fields blank and you should see the error message. +If you submit the form with all the fields populated you'll see your success page.

+ +

Note: The form fields are not yet being re-populated with the data when +there is an error. We'll get to that shortly, once we're through explaining the validation rules.

+ + +

Changing the Error Delimiters

+ +

By default, the system adds a paragraph tag (<p>) around each error message shown. You can easily change these delimiters with +this code, placed in your controller:

+ +$this->validation->set_error_delimiters('<div class="error">', '</div>'); + +

In this example, we've switched to using div tags.

+ +

Cascading Rules

+ +

Code Igniter lets you pipe multiple rules together. Let's try it. Change your rules array like this:

+ + +$rules['username'] = "required|min_length[5]|max_length[12]";
+$rules['password'] = "required|matches[passconf]";
+$rules['passconf'] = "required";
+$rules['email'] = "required|valid_email";
+ +

The above code requires that:

+ +
    +
  1. The username field be no shorter than 5 characters and no longer than 12.
  2. +
  3. The password field must match the password confirmation field.
  4. +
  5. The email field must contain a valid email address.
  6. +
+ +

Give it a try!

+ +

Note: There are numerous rules available which you can read about in the validation reference.

+ + +

Prepping Data

+ +

In addition to the validation functions like the ones we used above, you can also prep your data in various ways. +For example, you can set up rules like this: + +$rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
+$rules['password'] = "trim|required|matches[passconf]|md5";
+$rules['passconf'] = "trim|required";
+$rules['email'] = "trim|required|valid_email";
+ +

In the above, we are "trimming" the fields, converting the password to MD5, and running the username through +the "xss_clean" function, which removes malicious data.

+ +

Any native PHP function that accepts one parameter can be used as a rule, like htmlspecialchars, +trim, MD5, etc.

+ +

Note: You will generally want to use the prepping functions after +the validation rules so if there is an error, the original data will be shown in the form.

+ +

Callbacks: Your own Validation Functions

+ +

The validation system supports callbacks to your own validation functions. This permits you to extend the validation class +to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can +create a callback function that does that. Let's create a simple example.

+ +

In your controller, change the "username" rule to this:

+ +$rules['username'] = "callback_username_check"; + +

Then add a new function called username_check to your controller. Here's how your controller should look:

+ + + + +

Reload your form and submit it with the word "test" as the username. You can see that the form field data was passed to your +callback function for you to process.

+ +

To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix.

+ +

The error message was set using the $this->validation->set_message function. +Just remember that the message key (the first parameter) must match your function name.

+ +

Note: You can apply your own custom error messages to any rule, just by setting the +message similarly. For example, to change the message for the "required" rule you will do this:

+ +$this->validation->set_message('required', 'Your custom message here'); + +

Re-populating the form

+ +

Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data. +This is done similarly to your rules. Add the following code to your controller, just below your rules:

+ +$fields['username'] = 'Username';
+$fields['password'] = 'Password';
+$fields['passconf'] = 'Password Confirmation';
+$fields['email'] = 'Email Address';
+
+$this->validation->set_fields($fields);
+ +

The array keys are the actual names of the form fields, the value represents the full name that you want shown in the +error message.

+ +

The index function of your controller should now look like this:

+ + + + + +

Now open your myform.php view file and update the value in each field so that it has an object corresponding to its name:

+ + + + + +

Now reload your page and submit the form so that it triggers an error. Your form fields should be populated +and the error messages will contain a more relevant field name.

+ + + +

Showing Errors Individually

+ +

If you prefer to show an error message next to each form field, rather than as a list, you can change your form so that it looks like this:

+ + + + +

If there are no errors, nothing will be shown. If there is an error, the message will appear, wrapped in the delimiters you +have set (<p> tags by default).

+ +

Note: To display errors this way you must remember to set your fields using the $this->validation->set_fields +function described earlier. The errors will be turned into variables that have "_error" after your field name. +For example, your "username" error will be available at:
$this->validation->username_error.

+ + +

Rule Reference

+ +

The following is a list of all the native rules that are available to use:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RuleParameterDescriptionExample
requiredNoReturns FALSE if the form element is empty. 
matchesYesReturns FALSE if the form element does not match the one in the parameter.matches[form_item]
min_lengthYesReturns FALSE if the form element is shorter then the parameter value.min_length[6]
max_lengthYesReturns FALSE if the form element is longer then the parameter value.max_length[12]
exact_lengthYesReturns FALSE if the form element is not exactly the parameter value.exact_length[8]
alphaNoReturns FALSE if the form element contains anything other than alphabetical characters. 
alpha_numericNoReturns FALSE if the form element contains anything other than alpha-numeric characters. 
alpha_dashNoReturns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes. 
numericNoReturns FALSE if the form element contains anything other than numeric characters. 
valid_emailNoReturns FALSE if the form element does not contain a valid email address. 
+ +

Note: These rules can also be called as discreet functions. For example:

+ +$this->validation->required($string); + +

Note: You can also use any native PHP functions that permit one parameter.

+ + + +

Prepping Reference

+ +

The following is a list of all the prepping functions that are available to use:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameParameterDescription
xss_cleanNoRuns the data through the XSS filtering function, described in the Input Class page.
prep_for_formNoConverts special characters so that HTML data can be shown in a form field without breaking it.
prep_urlNoAdds "http://" to URLs if missing.
strip_image_tagsNoStrips the HTML from image tags leaving the raw URL.
encode_php_tagsNoConverts PHP tags to entities.
+ +

Note: You can also use any native PHP functions that permit one parameter, +like trim, htmlspecialchars, urldecode, etc.

+ + +

Setting Custom Error Messages

+ +

All of the native error messages are located in the following language file: language/english/validation_lang.php

+ +

To set your own custom message you can either edit that file, or use the following function:

+ +$this->validation->set_message('rule', 'Error Message'); + +

Where rule corresponds to the name of a particular rule, and Error Message is the text you would like displayed.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/libraries/xmlrpc.html b/user_guide/libraries/xmlrpc.html new file mode 100644 index 000000000..f8ef59951 --- /dev/null +++ b/user_guide/libraries/xmlrpc.html @@ -0,0 +1,485 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

XML-RPC and XML-RPC Server Classes

+ + +

Code Igniter's XML-RPC classes permit you to send requests to another server, or set up +your own XML-RPC server to receive requests.

+ + +

What is XML-RPC?

+ +

Quite simply it is a way for two computers to communicate over the internet using XML. +One computer, which we will call the client, sends an XML-RPC request to +another computer, which we will call the server. Once the server receives and processes the request it +will send back a response to the client.

+ +

For example, using the MetaWeblog API, an XML-RPC Client (usually a desktop publishing tool) will +send a request to an XML-RPC Server running on your site. This request might be a new weblog entry +being sent for publication, or it could be a request for an existing entry for editing. + +When the XML-RPC Server receives this request it will examine it to determine which class/method should be called to process the request. +Once processed, the server will then send back a response message.

+ +

For detailed spcifications, you can visit the XML-RPC site.

+ +

Initializing the Class

+ +

Like most other classes in Code Igniter, the XML-RPC and XML-RPCS classes are initialized in your controller using the $this->load->library function:

+ +

To load the XML-RPC class you will use: +$this->load->library('xmlrpc'); +

Once loaded, the xml-rpc library object will be available using: $this->xmlrpc

+ +

To load the XML-RPC Server class you will use: +$this->load->library('xmlrpcs'); +

Once loaded, the xml-rpcs library object will be available using: $this->xmlrpcs

+ + + +

Sending XML-RPC Requests

+ +

To send a request to an XML-RPC server you must specify the following information:

+ + + +

Here is a basic example that sends a simple Weblogs.com ping to the Ping-o-Matic

+ + +$this->load->library('xmlrpc');
+
+$this->xmlrpc->server('http://rpc.pingomatic.com/', 80);
+$this->xmlrpc->method('weblogUpdates.ping');
+ +
+$request = array('My Photoblog', 'http://www.my-site.com/photoblog/');
+$this->xmlrpc->request($request);
+
+if ( ! $this->xmlrpc->send_request())
+{
+    echo $xmlrpc->display_error();
+} +
+ +

Explanation

+ +

The above code initializes the XML-RPC class, sets the server URL and method to be called (weblogUpdates.ping). The +request (in this case, the title and URL of your site) is placed into an array for transportation, and +compiled using the request() function. +Lastly, the full request is sent. If the send_request() method returns false we will display the error message +sent back from the XML-RPC Server.

+ +

Anatomy of a Request

+ +

An XML-RPC request is simply the data you are sending to the XML-RPC server. Each piece of data in a request +is referred to as a request parameter. The above example has two parameters: +The URL and title of your site. When the XML-RPC server receives your request, it will look for parameters it requires.

+ +

Request parameters must be placed into an array for transportation, and each parameter can can be one +of seven data types (strings, numbers, dates, etc.). If your parameters are something other than strings +you will have to include the data type in the request array.

+ +

Here is an example of a simple array with three parameters:

+ +$request = array('John', 'Doe', 'www.some-site.com');
+$this->xmlrpc->request($request);
+ +

If you use data types other than strings, or if you have several different data types, you will place +each parameter into its own array, with the data type in the second position:

+ + +$request = array (
+                   array('John', 'string'),
+                   array('Doe', 'string'),
+                   array(FALSE, 'boolean'),
+                   array(12345, 'int')
+                 ); +
+$this->xmlrpc->request($request);
+ +The Data Types section below has a full list of data types.

+ + + +

Creating an XML-RPC Server

+ +

An XML-RPC Server acts as a traffic cop of sorts, waiting for incoming requests and redirecting them to the +appropriate functions for processing.

+ +

To create your own XML-RPC server involves initializing the XML-RPC Server class in your controller where you expect the incoming +request to appear, then setting up an array with mapping instructions so that incoming requests can be sent to the appropriate +class and method for processing.

+ +

Here is an example to illustrate:

+ +$this->load->library('xmlrpcs');
+
+$config['functions']['new_post'];  = array('function' => 'My_blog.new_entry');
+$config['functions']['update_post'] = array('function' => 'My_blog.update_entry');
+
+$this->xmlrpcs->initialize($config);
+$this->xmlrpcs->serve();
+ +

The above example contains an array specifying two method requests that the Server allows. +The allowed methods are on the left side of the array. When either of those are received, they will be mapped to the class and method on the right. + +

In other words, if an XML-RPC Client sends a request for the new_post method, your +server will load the My_blog class and call the new_entry function. +If the request is for the update_post method, your +server will load the My_blog class and call the update_entry function.

+ +

The function names in the above example are arbitrary. You'll decide what they should be called on your server, +or if you are using standardized APIs, like the Blogger or MetaWeblog API, you'll use their function names.

+ + +

Processing Server Requests

+ +

When the XML-RPC Server receives a request and loads the class/method for processing, it will pass +an object to that method containing the data sent by the client.

+ +

Using the above example, if the new_post method is requested, the server will expect a class +to exist with this prototype:

+ +class My_blog extends Controller {
+
+    function new_post($request)
+    {
+
+    }
+} +
+ +

The $request variable is an object compiled by the Server, which contains the data sent by the XML-RPC Client. +Using this object you will have access to the request parameters enabling you to process the request. When +you are done you will send a Response back to the Client.

+ +

Below is a real-world example, using the Blogger API. One of the methods in the Blogger API is getUserInfo(). +Using this method, an XML-RPC Client can send the Server a username and password, in return the Server sends +back information about that particular user (nickname, user ID, email address, etc.). Here is how the processing +function might look:

+ + +class My_blog extends Controller {
+
+    function getUserInfo($request)
+    {
+ +        $username = 'smitty';
+        $password = 'secretsmittypass';

+ +        $this->load->library('xmlrpc');
+    
+        $parameters = $request->output_parameters();
+    
+        if ($parameters['1'] != $username AND $parameters['2'] != $password)
+        {
+            return $this->xmlrpc->send_error_message('100', 'Invalid Access');
+        }
+    
+        $response = array(array('nickname'  => array('Smitty','string'),
+                                'userid'    => array('99','string'),
+                                'url'       => array('http://yoursite.com','string'),
+                                'email'     => array('jsmith@yoursite.com','string'),
+                                'lastname'  => array('Smith','string'),
+                                'firstname' => array('John','string')
+                                ),
+                         'struct');
+
+        $this->xmlrpc->send_response($response);
+    }
+} +
+ +

Notes:

+

The output_parameters() function retrieves an indexed array corresponding to the request parameters sent by the client. +In the above example, the output parameters will be the username and password.

+ +

If the username and password sent by the client were not valid, and error message is returned using send_error_message().

+ +

If the operation was successful, the client will be sent back a response array containing the user's info.

+ + +

Formatting a Response

+ +

Similar to Requests, Responses must be formatted as an array. However, unlike requests, a response is an array +that contains a single item. This item can be an array with several additional arrays, but there +can be only one primary array index. In other words, the basic prototype is this:

+ +$request = array('Response data', 'array'); + +

Responses, however, usually contain multiple pieces of information. In order to accomplish this we must put the response into its own +array so that the primary array continues to contain a single piece of data. Here's an example showing how this might be accomplished:

+ + +$request = array (
+                   array(
+                         'first_name' => array('John', 'string'),
+                         'last_name' => array('Doe', 'string'),
+                         'member_id' => array(123435, 'int'),
+                         'todo_list' => array(array('clean house', 'call mom', 'water plants'), 'array'),
+                        ),
+                 'struct'
+                 ); +
+ +

Notice that the above array is formatted as a struct. This is the most common data type for responses.

+ +

As with Requests, a response can be on of the seven data types listed in the Data Types section.

+ + +

Sending an Error Response

+ +

If you need to send the client an error response you will use the following:

+ +return $this->xmlrpc->send_error_message('123', 'Requested data not available'); + +

The first parameter is the error number while the second parameter is the error message.

+ + + + + + +

Creating Your Own Client and Server

+ +

To help you understand everything we've covered thus far, let's create a couple controllers that act as +XML-RPC Client and Server. You'll use the Client to send a request to the Server and receive a response.

+ +

The Client

+ +

Using a text editor, create a controller called xmlrpc_client.php. +In it, place this code and save it to your applications/controllers/ folder:

+ + + +

Note: In the above code we are using a "url helper". You can find more information in the Helpers Functions page.

+ +

The Server

+ +

Using a text editor, create a controller called xmlrpc_server.php. +In it, place this code and save it to your applications/controllers/ folder:

+ + + +

Try it!

+ +

Now visit the your site using a URL similar to this:

+www.your-site.com/index.php/xmlrpc_client/ + +

You should now see the message you sent to the server, and its response back to you.

+ +

The client you created sends a message ("How's is going?") to the server, along with a reqest for the "Greetings" method. +The Server receives the request and maps it to the "process" function, where a response is sent back.

+ + + +

 

+

XML-RPC Function Reference

+ +

$this->xmlrpc->server()

+

Sets the URL and port number of the server to which a request is to be sent:

+$this->xmlrpc->server('http://www.sometimes.com/pings.php', 80); + +

$this->xmlrpc->timeout()

+

Set a time out period (in seconds) after which the request will be canceled:

+$this->xmlrpc->timeout(6); + +

$this->xmlrpc->method()

+

Sets the method that will be requested from the XML-RPC server:

+$this->xmlrpc->method('method'); + +

Where method is the name of the method.

+ +

$this->xmlrpc->request()

+

Takes an array of data and builds request to be sent to XML-RPC server:

+$request = array(array('My Photoblog', 'string'), 'http://www.yoursite.com/photoblog/');
+$this->xmlrpc->request($request);
+ +

$this->xmlrpc->send_request()

+

The request sending function. Returns boolean TRUE or FALSE based on success for failure, enabling it to be used conditionally.

+ +

$this->xmlrpc->set_debug(TRUE);

+

Enables debugging, which will display a variety of information and error data helpful during development.

+ + +

$this->xmlrpc->display_error()

+

Returns an error message as a string if your request failed for some reason.

+echo $this->xmlrpc->display_error(); + +

$this->xmlrpc->display_response()

+

Returns the response from the remote server once request is received. The response will typically be an associative array.

+$this->xmlrpc->display_response(); + +

$this->xmlrpc->send_error_message()

+

This function lets you send an error message from your server to the client. First parameter is the error number while the second parameter +is the error message.

+return $this->xmlrpc->send_error_message('123', 'Requested data not available'); + +

$this->xmlrpc->send_response()

+

Lets you send the response from your server to the client. An array of of valid data values must be sent with this method.

+$response = array(
+                 array(
+                        'flerror' => array(FALSE, 'boolean'),
+                        'message' => "Thanks for the ping!")
+                     )
+                 'struct');
+return $this->xmlrpc->send_response($response);
+ + + +

Data Types

+ +

According to the XML-RPC spec there are seven types +of values that you can send via XML-RPC:

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/license.html b/user_guide/license.html new file mode 100644 index 000000000..4bc941547 --- /dev/null +++ b/user_guide/license.html @@ -0,0 +1,113 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + + +
+ + + + +
+ + + +
+ +

Code Igniter License Agreement

+ +

Copyright (c) 2006, pMachine, Inc.
+All rights reserved.

+ +

This license is a legal agreement between you and pMachine Inc. for the use of Code Igniter Software (the "Software"). By obtaining the Software you agree to comply with the terms and conditions of this license.

+ +

Permitted Use

+

You are permitted to use, copy, modify, and distribute the Software and its documentation, with or without modification, for any purpose, provided that the following conditions are met:

+ +
    +
  1. A copy of this license agreement must be included with the distribution.
  2. +
  3. Redistributions of source code must retain the above copyright notice in all source code files.
  4. +
  5. Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution.
  6. +
  7. Any files that have been modified must carry notices stating the nature of the change and the names of those who changed them.
  8. +
  9. Products derived from the Software must include an acknowledgment that they are derived from Code Igniter in their documentation and/or other materials provided with the distribution.
  10. +
  11. Products derived from the Software may not be called "Code Igniter", nor may "Code Igniter" appear in their name, without prior written permission from pMachine, Inc.
  12. +
+ +

Indemnity

+

You agree to indemnify and hold harmless the authors of the Software and any contributors for any direct, indirect, incidental, or consequential third-party claims, actions or suits, as well as any related expenses, liabilities, damages, settlements or fees arising from your use or misuse of the Software, or a violation of any terms of this license.

+ +

Disclaimer of Warranty

+

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF QUALITY, PERFORMANCE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.

+ +

Limitations of Liability

+

YOU ASSUME ALL RISK ASSOCIATED WITH THE INSTALLATION AND USE OF THE SOFTWARE. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS OF THE SOFTWARE BE LIABLE FOR CLAIMS, DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE. LICENSE HOLDERS ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USE AND ASSUME ALL RISKS ASSOCIATED WITH ITS USE, INCLUDING BUT NOT LIMITED TO THE RISKS OF PROGRAM ERRORS, DAMAGE TO EQUIPMENT, LOSS OF DATA OR SOFTWARE PROGRAMS, OR UNAVAILABILITY OR INTERRUPTION OF OPERATIONS.

+ + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/overview/appflow.html b/user_guide/overview/appflow.html new file mode 100644 index 000000000..0322a043e --- /dev/null +++ b/user_guide/overview/appflow.html @@ -0,0 +1,101 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Application Flow Chart

+ +

The following graphic illustrates how data flows throughout the system:

+ +
+ + +
    +
  1. The index.php serves as the front controller, initializing the base resources needed to run Code Igniter.
  2. +
  3. The Router examines the HTTP request to determine what should be done with it.
  4. +
  5. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
  6. +
  7. Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
  8. +
  9. The Controller loads the model, core libraries, plugins, helpers, and any other resources needed to process the specific request.
  10. +
  11. The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so +that on subsequent requests it can be served.
  12. +
+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/overview/at_a_glance.html b/user_guide/overview/at_a_glance.html new file mode 100644 index 000000000..188ced259 --- /dev/null +++ b/user_guide/overview/at_a_glance.html @@ -0,0 +1,168 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Code Igniter at a Glance

+ + +

Code Igniter is an Application Framework

+ +

Code Igniter is a toolkit for people who build web application using PHP. Its goal is to enable you to develop projects must faster than you could if you were writing code +from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and +logical structure to access these libraries. Code Igniter lets you creatively focus on your project by +minimizing the amount of code needed for a given task.

+ +

Code Igniter is Free

+

Code Igniter is licensed under an Apache/BSD-style open source license so you can use it however you please. +For more information please read the license agreement.

+ + +

Code Igniter Runs on PHP 4

+

Code Igniter is written to be compatible with PHP 4. Although we would have loved to take advantage of the better object handling +in PHP 5 since it would have simplified some things we had to find creative solutions for (looking your way, multiple inheritance), +at the time of this writing PHP 5 is not in widespread use, which means we would be alienating most of our +potential audience. Major OS vendors like RedHat have yet to support PHP 5, and they are unlikely to do so until 2007, so +we felt that it did not serve the best interests of the PHP community to write Code Igniter in PHP 5.

+ +

Note: Code Igniter will run on PHP 5. It simply does not take advantage of any native features that are only available in that version.

+ +

Code Igniter is Light Weight

+

Truly light weight. The core system requires only a few very small libraries. This is in stark contrast to many frameworks that require significantly more resources. +Additional libraries are loaded dynamically upon request, based on your needs for a given process, so the base system +is very lean and quite fast. +

+ +

Code Igniter Uses M-V-C

+

Code Igniter uses the Model-View-Controller approach, which allows great separation between logic and presentation. +This is particularly good for projects in which designers are working with your template files, as the code these file contain will be minimized. We describe MVC in more detail on its own page.

+ +

Code Igniter Generates Clean URLs

+

The URLs generated by Code Igniter are clean and search-engine friendly. Rather than using the standard "query string" +approach to URLs that is synonymous with dynamic systems, Code Igniter uses a segment-based approach:

+ +www.your-site.com/news/article/345 + +

Note: By default the index.php file is included in the URL but it can be removed using a simple .htaccess file.

+ +

Code Igniter Packs a Punch

+

Code Igniter comes with a very nice set of libraries that enable the most commonly needed web development tasks, +like connecting to a database, sending email, validating form data, maintaining sessions, manipulating images, and more.

+ +

Code Igniter is Extensible

+

The system can be easily extended through the use of plugins and helper files, or even through class extensions or standard includes.

+ +

Code Igniter Does Not Require a Template Engine

+

Template engines simply can not match the performance of native PHP, and the syntax that must be learned to use a template +engine is usually only marginally easier than learning the basics of PHP. Consider this block of PHP code:

+ +<ul>
+
+<?php foreach ($addressbook as $name):?>
+
+<li><?=$name?></li>
+
+<?php endforeach; ?>
+
+</ul>
+ +

Contrast this with the pseudo-code used by a template engine:

+ +<ul>
+
+{foreach from=$addressbook item="name"}
+
+<li>{$name}</li>
+
+{/foreach}
+
+</ul>
+ +

Yes, the template engine example is a bit cleaner, but it comes at the price of performance, as the pseudo-code must be converted +back into PHP to run. Since one of our goals is maximum performance, we opted to not require the use of a template engine.

+ +

That said, Code Igniter does come with a simple template engine class which you can optionally use. Or, if you +prefer using a full-blown template engine such as Smarty, there's no reason why you can't use it with Code Igniter. +Just include your template engine script when you write your controllers, and continue working as you normally do.

+ +

Code Igniter is Thoroughly Documented

+

Programmers love to code and hate to write documentation. We're no different, of course, but +since documentation is as important as the code itself, +we are committed to doing it. Our source code is extremely clean and well commented as well.

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/overview/features.html b/user_guide/overview/features.html new file mode 100644 index 000000000..3cb1ba1f8 --- /dev/null +++ b/user_guide/overview/features.html @@ -0,0 +1,122 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Code Igniter Features

+ +

Features in and of themselves are a very poor way to judge an application since they tell you nothing +about the user experience, or how intuitively or intelligently it is designed. Features +don't reveal anything about the quality of the code, or the performance, or the attention to detail, or security practices. +The only way to really judge an app is to try it and get to know the code. Installing +Code Igniter is child's play so we encourage you to do just that. In the mean time here's a list of Code Igniter's main features.

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/overview/goals.html b/user_guide/overview/goals.html new file mode 100644 index 000000000..0fdd4d1a9 --- /dev/null +++ b/user_guide/overview/goals.html @@ -0,0 +1,103 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + + +

Design and Architectural Goals

+ +

Our goal for Code Igniter is maximum performance, capability, and flexibility in the smallest, lightest possible package.

+ +

To meet this goal we are committed to benchmarking, re-factoring, and simplifying at every step of the development process, +rejecting anything that doesn't further the stated objective.

+ +

From an technical and architectural standpoint, Code Igniter was created with the following objectives:

+ + + +

Code Igniter is a dynamically instantiated, loosely coupled system with high component singularity. It strives for simplicity, flexibility, and high performance in a small footprint package.

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/overview/index.html b/user_guide/overview/index.html new file mode 100644 index 000000000..8ddbdad36 --- /dev/null +++ b/user_guide/overview/index.html @@ -0,0 +1,89 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Code Igniter Overview

+ +

The following pages describe the broad concepts behind Code Igniter:

+ + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/overview/mvc.html b/user_guide/overview/mvc.html new file mode 100644 index 000000000..4f251e4d2 --- /dev/null +++ b/user_guide/overview/mvc.html @@ -0,0 +1,105 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Model-View-Controller

+ +

Code Igniter is based on the Model-View-Controller development pattern. + +MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.

+ + + +

Code Igniter has a fairly loose approach to MVC since Models are not required. +If you don't need the added separation, or find that maintaining models requires more complexity than you +want, you can ignore them and build your application minimally using Controllers and Views. Code Igniter also +enables you to incorporate your own existing scripts, or even develop core libraries for the system, + enabling you to work in a way that makes the most sense to you.

+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/scripts/hacks.txt b/user_guide/scripts/hacks.txt new file mode 100644 index 000000000..f29e5a77a --- /dev/null +++ b/user_guide/scripts/hacks.txt @@ -0,0 +1,9 @@ +I did the following hack in moo.fx.js: + +At line 79 in the toggle: function() function, I added: + +document.getElementById('nav').style.display = 'block'; + + + +-- Rick Ellis \ No newline at end of file diff --git a/user_guide/scripts/moo.fx.js b/user_guide/scripts/moo.fx.js new file mode 100755 index 000000000..953e87c64 --- /dev/null +++ b/user_guide/scripts/moo.fx.js @@ -0,0 +1,119 @@ +/* +moo.fx, simple effects library built with prototype.js (http://prototype.conio.net). +by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE. +for more info (http://moofx.mad4milk.net). +10/24/2005 +v(1.0.2) +*/ + +//base +var fx = new Object(); +fx.Base = function(){}; +fx.Base.prototype = { + setOptions: function(options) { + this.options = { + duration: 500, + onComplete: '' + } + Object.extend(this.options, options || {}); + }, + + go: function() { + this.duration = this.options.duration; + this.startTime = (new Date).getTime(); + this.timer = setInterval (this.step.bind(this), 13); + }, + + step: function() { + var time = (new Date).getTime(); + var Tpos = (time - this.startTime) / (this.duration); + if (time >= this.duration+this.startTime) { + this.now = this.to; + clearInterval (this.timer); + this.timer = null; + if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10); + } + else { + this.now = ((-Math.cos(Tpos*Math.PI)/2) + 0.5) * (this.to-this.from) + this.from; + //this time-position, sinoidal transition thing is from script.aculo.us + } + this.increase(); + }, + + custom: function(from, to) { + if (this.timer != null) return; + this.from = from; + this.to = to; + this.go(); + }, + + hide: function() { + this.now = 0; + this.increase(); + }, + + clearTimer: function() { + clearInterval(this.timer); + this.timer = null; + } +} + +//stretchers +fx.Layout = Class.create(); +fx.Layout.prototype = Object.extend(new fx.Base(), { + initialize: function(el, options) { + this.el = $(el); + this.el.style.overflow = "hidden"; + this.el.iniWidth = this.el.offsetWidth; + this.el.iniHeight = this.el.offsetHeight; + this.setOptions(options); + } +}); + +fx.Height = Class.create(); +Object.extend(Object.extend(fx.Height.prototype, fx.Layout.prototype), { + increase: function() { + this.el.style.height = this.now + "px"; + }, + + toggle: function() { + if (this.el.offsetHeight > 0) this.custom(this.el.offsetHeight, 0); + else this.custom(0, this.el.scrollHeight); + } +}); + +fx.Width = Class.create(); +Object.extend(Object.extend(fx.Width.prototype, fx.Layout.prototype), { + increase: function() { + this.el.style.width = this.now + "px"; + }, + + toggle: function(){ + if (this.el.offsetWidth > 0) this.custom(this.el.offsetWidth, 0); + else this.custom(0, this.el.iniWidth); + } +}); + +//fader +fx.Opacity = Class.create(); +fx.Opacity.prototype = Object.extend(new fx.Base(), { + initialize: function(el, options) { + this.el = $(el); + this.now = 1; + this.increase(); + this.setOptions(options); + }, + + increase: function() { + if (this.now == 1) this.now = 0.9999; + if (this.now > 0 && this.el.style.visibility == "hidden") this.el.style.visibility = "visible"; + if (this.now == 0) this.el.style.visibility = "hidden"; + if (window.ActiveXObject) this.el.style.filter = "alpha(opacity=" + this.now*100 + ")"; + this.el.style.opacity = this.now; + }, + + toggle: function() { + if (this.now > 0) this.custom(1, 0); + else this.custom(0, 1); + } +}); \ No newline at end of file diff --git a/user_guide/scripts/moo.fx.pack.js b/user_guide/scripts/moo.fx.pack.js new file mode 100755 index 000000000..8b4228329 --- /dev/null +++ b/user_guide/scripts/moo.fx.pack.js @@ -0,0 +1,241 @@ +/* +moo.fx pack, effects extensions for moo.fx. +by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE +for more info visit (http://moofx.mad4milk.net). +Wednesday, November 16, 2005 +v1.0.4 +*/ + +//text size modify, now works with pixels too. +fx.Text = Class.create(); +fx.Text.prototype = Object.extend(new fx.Base(), { + initialize: function(el, options) { + this.el = $(el); + this.setOptions(options); + if (!this.options.unit) this.options.unit = "em"; + }, + + increase: function() { + this.el.style.fontSize = this.now + this.options.unit; + } +}); + +//composition effect, calls Width and Height alltogheter +fx.Resize = Class.create(); +fx.Resize.prototype = { + initialize: function(el, options) { + this.h = new fx.Height(el, options); + if (options) options.onComplete = null; + this.w = new fx.Width(el, options); + this.el = $(el); + }, + + toggle: function(){ + this.h.toggle(); + this.w.toggle(); + }, + + modify: function(hto, wto) { + this.h.custom(this.el.offsetHeight, this.el.offsetHeight + hto); + this.w.custom(this.el.offsetWidth, this.el.offsetWidth + wto); + }, + + custom: function(hto, wto) { + this.h.custom(this.el.offsetHeight, hto); + this.w.custom(this.el.offsetWidth, wto); + }, + + hide: function(){ + this.h.hide(); + this.w.hide(); + } +} + +//composition effect, calls Opacity and (Width and/or Height) alltogheter +fx.FadeSize = Class.create(); +fx.FadeSize.prototype = { + initialize: function(el, options) { + this.el = $(el); + this.el.o = new fx.Opacity(el, options); + if (options) options.onComplete = null; + this.el.h = new fx.Height(el, options); + this.el.w = new fx.Width(el, options); + }, + + toggle: function() { + this.el.o.toggle(); + for (var i = 0; i < arguments.length; i++) { + if (arguments[i] == 'height') this.el.h.toggle(); + if (arguments[i] == 'width') this.el.w.toggle(); + } + }, + + hide: function(){ + this.el.o.hide(); + for (var i = 0; i < arguments.length; i++) { + if (arguments[i] == 'height') this.el.h.hide(); + if (arguments[i] == 'width') this.el.w.hide(); + } + } +} + +//intended to work with arrays. +var Multi = new Object(); +Multi = function(){}; +Multi.prototype = { + initialize: function(elements, options){ + this.options = options; + this.el = this.getElementsFromArray(elements); + for (i=0;i 0 && this.el[i] != el && this.el[i].h.timer == null && el.h.timer == null){ + this.el[i].fs.toggle(mode); + setTimeout(function(){el.fs.toggle(mode);}.bind(el), delay); + } + + } + }, + + hide: function(el, mode){ + el.fs.hide(mode); + } +}); + +var Remember = new Object(); +Remember = function(){}; +Remember.prototype = { + initialize: function(el, options){ + this.el = $(el); + this.days = 365; + this.options = options; + this.effect(); + var cookie = this.readCookie(); + if (cookie) { + this.fx.now = cookie; + this.fx.increase(); + } + }, + + //cookie functions based on code by Peter-Paul Koch + setCookie: function(value) { + var date = new Date(); + date.setTime(date.getTime()+(this.days*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + document.cookie = this.el+this.el.id+this.prefix+"="+value+expires+"; path=/"; + }, + + readCookie: function() { + var nameEQ = this.el+this.el.id+this.prefix + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); + } + return false; + }, + + custom: function(from, to){ + if (this.fx.now != to) { + this.setCookie(to); + this.fx.custom(from, to); + } + } +} + +fx.RememberHeight = Class.create(); +fx.RememberHeight.prototype = Object.extend(new Remember(), { + effect: function(){ + this.fx = new fx.Height(this.el, this.options); + this.prefix = 'height'; + }, + + toggle: function(){ + if (this.el.offsetHeight == 0) this.setCookie(this.el.scrollHeight); + else this.setCookie(0); + this.fx.toggle(); + }, + + resize: function(to){ + this.setCookie(this.el.offsetHeight+to); + this.fx.custom(this.el.offsetHeight,this.el.offsetHeight+to); + }, + + hide: function(){ + if (!this.readCookie()) { + this.fx.hide(); + } + } +}); + +fx.RememberText = Class.create(); +fx.RememberText.prototype = Object.extend(new Remember(), { + effect: function(){ + this.fx = new fx.Text(this.el, this.options); + this.prefix = 'text'; + } +}); + + +//use to attach effects without using js code, just classnames and rel attributes. +ParseClassNames = Class.create(); +ParseClassNames.prototype = { + initialize: function(options){ + var babies = document.getElementsByTagName('*') || document.all; + for (var i = 0; i < babies.length; i++) { + var el = babies[i]; + //attach the effect, from the classNames; + var effects = this.getEffects(el); + for (var j = 0; j < effects.length; j++) { + if (j == 1 && options) options.onComplete = null; + el[effects[j]+"fx"] = new fx[effects[j]](el, options); + } + //execute methods, from rel + if (el.rel) { + el.crel = el.rel.split(' '); + if (el.crel[0].indexOf("fx_") > -1) { + var event = el.crel[0].replace('fx_', ''); + var tocompute = this.getEffects($(el.crel[1])); + el["on"+event] = function(){ + for (var f = 0; f < tocompute.length; f++) { + $(this.crel[1])[tocompute[f]+"fx"][this.crel[2] || "toggle"](this.crel[3] || null, this.crel[4] || null); + } + } + } + } + } + }, + + getEffects: function(el){ + var effects = new Array(); + var css = el.className.split(' '); + for (var i = 0; i < css.length; i++) { + if (css[i].indexOf('fx_') > -1) { + var effect = css[i].replace('fx_', ''); + effects.push(effect); + } + } + return effects; + } +} \ No newline at end of file diff --git a/user_guide/scripts/nav.js b/user_guide/scripts/nav.js new file mode 100644 index 000000000..be0f7b1a8 --- /dev/null +++ b/user_guide/scripts/nav.js @@ -0,0 +1,116 @@ +function create_menu(basepath) +{ + var base = (basepath == 'null') ? '' : basepath; + + document.write( + '' + + '
' + + + '

User Guide Home

' + + + '

Basic Info

' + + '' + + + '

Installation

' + + '' + + + '

Introduction

' + + '' + + + '
' + + + '

General Topics

' + + '' + + + '
' + + + + '

Class Reference

' + + '' + + + '
' + + + '

Helper Reference

' + + '' + + + + '

Additional Resources

' + + '' + + + '
'); +} \ No newline at end of file diff --git a/user_guide/scripts/prototype.lite.js b/user_guide/scripts/prototype.lite.js new file mode 100755 index 000000000..f1520e2c6 --- /dev/null +++ b/user_guide/scripts/prototype.lite.js @@ -0,0 +1,127 @@ +/* Prototype JavaScript framework + * (c) 2005 Sam Stephenson + * + * Prototype is freely distributable under the terms of an MIT-style license. + * + * For details, see the Prototype web site: http://prototype.conio.net/ + * +/*--------------------------------------------------------------------------*/ + + +//note: this is a stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net). + +var Class = { + create: function() { + return function() { + this.initialize.apply(this, arguments); + } + } +} + +Object.extend = function(destination, source) { + for (property in source) { + destination[property] = source[property]; + } + return destination; +} + +Function.prototype.bind = function(object) { + var __method = this; + return function() { + return __method.apply(object, arguments); + } +} + +function $() { + var elements = new Array(); + + for (var i = 0; i < arguments.length; i++) { + var element = arguments[i]; + if (typeof element == 'string') + element = document.getElementById(element); + + if (arguments.length == 1) + return element; + + elements.push(element); + } + + return elements; +} + +//------------------------- + +document.getElementsByClassName = function(className) { + var children = document.getElementsByTagName('*') || document.all; + var elements = new Array(); + + for (var i = 0; i < children.length; i++) { + var child = children[i]; + var classNames = child.className.split(' '); + for (var j = 0; j < classNames.length; j++) { + if (classNames[j] == className) { + elements.push(child); + break; + } + } + } + + return elements; +} + +//------------------------- + +if (!window.Element) { + var Element = new Object(); +} + +Object.extend(Element, { + remove: function(element) { + element = $(element); + element.parentNode.removeChild(element); + }, + + hasClassName: function(element, className) { + element = $(element); + if (!element) + return; + var a = element.className.split(' '); + for (var i = 0; i < a.length; i++) { + if (a[i] == className) + return true; + } + return false; + }, + + addClassName: function(element, className) { + element = $(element); + Element.removeClassName(element, className); + element.className += ' ' + className; + }, + + removeClassName: function(element, className) { + element = $(element); + if (!element) + return; + var newClassName = ''; + var a = element.className.split(' '); + for (var i = 0; i < a.length; i++) { + if (a[i] != className) { + if (i > 0) + newClassName += ' '; + newClassName += a[i]; + } + } + element.className = newClassName; + }, + + // removes whitespace-only text node children + cleanWhitespace: function(element) { + element = $(element); + for (var i = 0; i < element.childNodes.length; i++) { + var node = element.childNodes[i]; + if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) + Element.remove(node); + } + } +}); \ No newline at end of file diff --git a/user_guide/toc.html b/user_guide/toc.html new file mode 100644 index 000000000..9935c7301 --- /dev/null +++ b/user_guide/toc.html @@ -0,0 +1,182 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + + +
+ + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/user_guide/userguide.css b/user_guide/userguide.css new file mode 100644 index 000000000..4da90dc65 --- /dev/null +++ b/user_guide/userguide.css @@ -0,0 +1,406 @@ +body { + margin: 0; + padding: 0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 14px; + color: #4F5155; + background: #fff url(images/background.jpg) repeat-x left top; +} + +a { + color: #003399; + background-color: transparent; + text-decoration: none; + font-weight: normal; +} +a:visited { + color: #003399; + background-color: transparent; + text-decoration: none; +} +a:hover { + color: #000; + text-decoration: none; + background-color: transparent; +} + +#breadcrumb { + float: left; + background-color: transparent; + margin: 10px 0 0 42px; + padding: 0; + font-size: 10px; + color: #666; +} +#breadcrumb_right { + float: right; + width: 175px; + background-color: transparent; + padding: 8px 8px 3px 0; + text-align: right; + font-size: 10px; + color: #666; +} +#nav { + background-color: #5d5d5d; + margin: 0; + padding: 0; +} +#nav2 { + background: #fff url(images/nav_bg.jpg) repeat-x left top; + padding: 0 180px 0 0; + margin: 0; + text-align: right; +} +#nav_inner { + background-color: transparent; + padding: 8px 12px 0 20px; + margin: 0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; +} + +#nav_inner h3 { + font-size: 12px; + color: #fff; + margin: 0; + padding: 0; +} + +#nav_inner .td_sep { + background: transparent url(images/nav_separator.jpg) repeat-y left top; + width: 25%; + padding: 0 0 0 20px; +} +#nav_inner .td { + width: 25%; +} +#nav_inner p { + color: #eee; + background-color: transparent; + padding:0; + margin: 0 0 10px 0; +} +#nav_inner ul { + list-style-image: url(images/arrow.gif); + padding: 0 0 0 18px; + margin: 8px 0 12px 0; +} +#nav_inner li { + padding: 0; + margin: 0 0 4px 0; +} + +#nav_inner a { + color: #eee; + background-color: transparent; + text-decoration: none; + font-weight: normal; +} + +#nav_inner a:visited { + color: #eee; + background-color: transparent; + text-decoration: none; +} + +#nav_inner a:hover { + color: #ccc; + text-decoration: none; + background-color: transparent; +} + +#masthead { + margin: 0 40px 0 35px; + padding: 0 0 0 6px; + border-bottom: 1px solid #999; +} + +#masthead h1 { +background-color: transparent; +color: #003399; +font-size: 18px; +font-weight: normal; +margin: 0; +padding: 0 0 6px 0; +} + +#searchbox { + background-color: transparent; + padding: 6px 40px 0 0; + text-align: right; + font-size: 10px; + color: #666; +} + +#img_welcome { + border-bottom: 1px solid #D0D0D0; + margin: 0 40px 0 40px; + padding: 0; + text-align: center; +} + +#content { + margin: 20px 40px 0 40px; + padding: 0; +} + +#content p { + margin: 10px 20px 12px 0; +} + +#content h1 { +color: #333; +font-weight: normal; +font-size: 22px; +margin: 0 0 15px 0; +padding: 0; +} + +#content h2 { + background-color: transparent; + border-bottom: 1px solid #D0D0D0; + color: #444; + font-size: 16px; + font-weight: bold; + margin: 24px 0 2px 0; + padding: 5px 0 6px 0; +} + +#content h3 { + background-color: transparent; + color: #333; + font-size: 14px; + font-weight: bold; + margin: 22px 0 12px 0; + padding: 0 0 0 0; +} + +#content h4 { + background-color: transparent; + color: #444; + font-size: 14px; + font-weight: bold; + margin: 22px 0 0 0; + padding: 0 0 0 0; +} + +#content img { + margin: auto; + padding: 0; +} + +#content code { + font-family: Monaco, Verdana, Sans-serif; + font-size: 12px; + background-color: #f9f9f9; + border: 1px solid #D0D0D0; + color: #002166; + display: block; + margin: 14px 0 14px 0; + padding: 12px 10px 12px 10px; +} + +#content pre { + font-family: Monaco, Verdana, Sans-serif; + font-size: 12px; + background-color: #f9f9f9; + border: 1px solid #D0D0D0; + color: #002166; + display: block; + margin: 14px 0 14px 0; + padding: 12px 10px 12px 10px; +} + +#content .path { + background-color: #EBF3EC; + border: 1px solid #99BC99; + color: #005702; + text-align: center; + margin: 0 0 14px 0; + padding: 5px 10px 5px 8px; +} + +#content dfn { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + color: #00620C; + font-weight: bold; + font-style: normal; +} +#content var { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + color: #8F5B00; + font-weight: bold; + font-style: normal; +} +#content samp { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + color: #480091; + font-weight: bold; + font-style: normal; +} +#content kbd { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + color: #A70000; + font-weight: bold; + font-style: normal; +} + +#content ul { + list-style-image: url(images/arrow.gif); + padding: 0 0 0 18px; + margin: 8px 0 12px 0; +} + +#content li { + padding: 0; + margin: 0 0 6px 0; +} + +#content li p { + margin-left: 0; + margin-right: 0; +} + +#content .tableborder { + border: 1px solid #999; +} +#content th { + font-weight: bold; + text-align: left; + font-size: 12px; + background-color: #666; + color: #fff; + padding: 4px; +} + +#content .td { + font-weight: normal; + font-size: 12px; + padding: 6px; + background-color: #f3f3f3; +} + +#content .tdpackage { + font-weight: normal; + font-size: 12px; +} + +#content .important { + background: #FBE6F2; + border: 1px solid #D893A1; + color: #333; + margin: 10px 0 5px 0; + padding: 10px; +} + +#content .important p { + margin: 6px 0 8px 0; + padding: 0; +} + +#content .important .leftpad { + margin: 6px 0 8px 0; + padding-left: 20px; +} + +#content .critical { + background: #FBE6F2; + border: 1px solid #E68F8F; + color: #333; + margin: 10px 0 5px 0; + padding: 10px; +} + +#content .critical p { + margin: 5px 0 6px 0; + padding: 0; +} + + +#footer { +background-color: transparent; +font-size: 10px; +padding: 16px 0 15px 0; +margin: 20px 0 0 0; +text-align: center; +} + +#footer p { + font-size: 10px; + color: #999; + text-align: center; +} +#footer address { + font-style: normal; +} + +.center { + text-align: center; +} + +img { + padding:0; + border: 0; + margin: 0; +} + +.nopad { + padding:0; + border: 0; + margin: 0; +} + + +form { + margin: 0; + padding: 0; +} + +.input { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + color: #333; + border: 1px solid #B3B4BD; + width: 100%; + font-size: 11px; + height: 1.5em; + padding: 0; + margin: 0; +} + +.textarea { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 14px; + color: #143270; + background-color: #f9f9f9; + border: 1px solid #B3B4BD; + width: 100%; + padding: 0; + margin: 0; +} + +.select { + background-color: #fff; + font-size: 11px; + font-weight: normal; + color: #333; + padding: 0; + margin: 0 0 3px 0; +} + +.checkbox { + background-color: transparent; + padding: 0; + border: 0; +} + +.submit { + background-color: #000; + color: #fff; + font-weight: normal; + font-size: 10px; + border: 1px solid #fff; + margin: 0; + padding: 1px 5px 2px 5px; +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b