$config['encryption_key'] = "o2xda01";
$encrypt->encode($message);
$encrypt->decode($encrypted_string);
IMPORTANT POINTS
1) 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. Keep
this information in mind when selecting your data
storage mechanism. Cookies, for example, can only
hold 4K of information.
ConfigManager Class
$config = ConfigManager::getInstance();
$a = $config->item(‘encryption_key’);
IMPORTANT POINTS
Please note that the config object is already
instantiated in common.php file and you can access
it using $config variable. So use that object wherever
there is need to use it and don’t modify $config
variable in your scripts as well, as some base
libraries are also using it.
ErrorManager Class
$error = ErrorManager::getInstance();
$error->showError($message);
$error->showMessage($message, ‘<p
class=”error”>’, ‘</p>’);
Where ‘<p class=”error”>’ and ‘</p>’ defines the
opening and closing tag of message.
$error->showMessage($message);
IMPORTANT POINTS
Please note that the error object is already
instantiated in common.php file and you can access
it using $error variable. So use that object wherever
there is need to use it and don’t modify $error
variable in your scripts as well, as some base
libraries are also using it.
JavascriptManager Class
$rules[‘Password’] = array(“isNotEqual|
ConfirmPassword” => “Your passwords do not
match”);
Function Use
isEmpty Checks whether a field is
empty or not
isNumeric Checks whether a field
value is numeric or not
isOfExactLength Checks whether a field
has exactly n number of
characters
isOfMinLength Checks whether a field
has minimum n number
of characters
isOfMaxLength Checks whether a field
has maximum n number
of characters
isAtleastOneNotEmpty Checks whether the
value of either of the two
control is blank or not
isNotEqual Check whether the value
of two control equals or
not
isValidEmail Check whether an Email
address is valid
isSelected Check whether the
something is selected in
the list or not
isMultipleSel Check whether the
something is selected in
the multi select list or not
isChecked Check whether a
checkbox or radio button
is checked or not.
IMPORTANT POINTS
PagingManager Class
$pagingStr = $paging->doPaging($totalRecords);
IMPORTANT POINTS
The normal paging class that we are using till date,
also contains the sql query as one of the parameter
but this new paging class doesn’t make use of sql
query, as this unnecessarily complicates the things.
The paging class just needs the total number of
records to return the paging string. However you can
use 2 important functions of this paging class i.e
$paging->getStart()
$paging->getOffset()
to get the start and offset points that can use in your
query with LIMIT clause i.e on a pagesize of 10, these
function will return 0, 10 for page 1 and so on.
Email Class:
Email class is used for sending emails through SMTP,
mail function or send mail.
$emailErrrors = $email->display_errors($openTag,
$closeTag);
Important Points
Default Val
Property Options Description
ue
The path to the
folder where
the upload
should be
placed. The
upload_path None None
folder must be
writable and
the path can
be absolute or
relative.
allowed_typ None None The mime
es 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.
If set to true, if
a file with the
same name as
the one you
are uploading
exists, it will be
TRUE/FALS
overwritten. If
overwrite FALSE E
set to false, a
(boolean)
number will be
appended to
the filename if
another with
the same name
exists.
max_size 0 None The 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.
The maximum
width (in
pixels) that the
max_width 0 None
file can be. Set
to zero for no
limit.
The maximum
height (in
pixels) that the
max_height 0 None
file can be. Set
to zero for no
limit.
If set to TRUE
the file name
will be
converted to a
random
encrypted
TRUE/FALS string. This can
encrypt_nam
FALSE E be useful if you
e
(boolean) would like the
file saved with
a name that
can not be
discerned by
the person
uploading it.
remove_spac TRUE TRUE/FALS If set to TRUE,
es E any spaces in
(boolean) the file name
will be
converted to
underscores.
This is
recommended.
$upload->do_upload($field_name)
if ( ! $upload->do_upload($field_name))
{
$error = $upload->display_errors();
}
if ( ! $upload->do_upload($field_name))
{
$error = $upload->display_errors();
}
Else
{
// get the uploaded data
$data = $upload->data();
}
Item Description
The name of the file that was uploaded
file_name
including the file extension.
file_type The file's Mime type
file_path The absolute server path to the file
The absolute server path including the
full_path
file name
raw_name The file name without the extension
The original file name. This is only
orig_name useful if you use the encrypted name
option.
file_ext The file extension with period
file_size The file size in kilobytes
Whether the file is an image or not. 1
Is_image
= image. 0 = not.
image_width Image width.
image_heigt
Image height
h
Image type. Typically the file extension
image_type
without the period.
image_size_s A string containing the width and
tr height. Useful to put into an image tag.
so in order to determine a file name, the data
function should be called first and the name can be
stored like:
$name = $data[‘file_name’];
Important Points
$settings = ($config->item(‘upload_settings’);
$settings[‘upload_path’] = APPPATH . ‘pdf’.
$upload = new UploadManager($$settings);
ImageManager Class
$imageManager = new
ImageManager($imageConfig);
$imageConfig['image_library'] = 'GD';
$imageConfig['source_image'] =
'/path/to/image/mypic.jpg';
$imageConfig['create_thumb'] = TRUE;
$imageConfig['maintain_ratio'] = TRUE;
$imageConfig['width'] = 75;
$imageConfig['height'] = 50;
$imageManager->resize();
$imageManager->resize()
$imageManager->crop()
$imageManager->rotate()
$imageManager->watermark()
These functions return boolean TRUE upon success
and FALSE for failure. If they fail you can retrieve the
error message using this function:
echo $imageManager->display_errors();
if ( ! $imageManager->resize())
{
echo $imageManager->display_errors();
}
$imageManager->display_errors('<p>', '</p>');
Preferences
$imageManager->resize()
Creating a Thumbnail
The resizing function will create a thumbnail file (and
preserve the original) if you set this preference so
TRUE:
$imageConfig['create_thumb'] = TRUE;
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:
$imageConfig['new_image'] =
'/path/to/new_image.jpg';
Notes regarding this preference:
$imageManager->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:
$imageConfig['x_axis'] = '100';
$imageConfig['x_axis'] = '40';
$imageConfig['image_library'] = 'imagemagick';
$imageConfig['library_path'] = '/usr/X11R6/bin/';
$imageConfig['source_image'] =
'/path/to/image/mypic.jpg';
$imageConfig['x_axis'] = '100';
$imageConfig['y_axis'] = '60';
$imageManager->initialize($imageConfig);
if ( ! $imageManager->crop())
{
echo $imageManager->display_errors();
}
$imageManager->rotate()
The image rotation function requires that the angle
of rotation be set via its preference:
$imageConfig['rotation_angle'] = '90';
$imageConfig['image_library'] = 'netpbm';
$imageConfig['library_path'] = '/usr/bin/';
$imageConfig['source_image'] =
'/path/to/image/mypic.jpg';
$imageConfig['rotation_angle'] = 'hor';
$imageManager->initialize($imageConfig);
if ( ! $imageManager->rotate())
{
echo $imageManager->display_errors();
}
Image Watermarking
The Watermarking feature requires the GD/GD2
library.
$imageConfig['source_image'] =
'/path/to/image/mypic.jpg';
$imageConfig['wm_text'] = 'Copyright 2006 - John
Doe';
$imageConfig['wm_type'] = 'text';
$imageConfig['wm_font_path'] =
'./system/fonts/texb.ttf';
$imageConfig['wm_font_size'] = '16';
$imageConfig['wm_text_color'] = 'ffffff';
$imageConfig['wm_vrt_alignment'] = 'bottom';
$imageConfig['wm_hor_alignment'] = 'center';
$imageConfig['wm_padding'] = '20';
$imageManager->initialize($imageConfig);
$imageManager->watermark();
Watermarking Preferences
Text Preferences
Overlay Preferences
Important Points
In order for the image class to be allowed to do any
processing, the image file must have file permissions
of 777.
Database Class
Escaping Queries
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:
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:
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()
This function returns a single result row in an array.
Example:
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);
$db->insert_id()
The insert ID number when performing database
inserts.
$db->affected_rows()
Displays the number of affected rows, when doing
"write" type queries (insert, update, etc.).
$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 $db->count_all('my_table');
$query->num_rows()
The number of rows returned by the query. Note: In
this example, $query is the variable that the query
result object is assigned to:
echo $query->num_rows();
Selecting Data
The following functions allow you to build SQL
SELECT statements.
$db->get();
Runs the selection query and returns the result. Can
be used by itself to retrieve all records from a table:
$query = $db->get('mytable');
// Produces: SELECT * FROM mytable
$query = $db->get('mytable');
$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:
$db->select();
Permits you to write the SELECT portion of your
query:
$query = $db->get('mytable');
$db->from();
Permits you to write the FROM portion of your query:
$query = $db->get();
$db->join();
Permits you to write the JOIN portion of your query:
$db->select('*');
$db->from('blogs');
$db->join('comments', 'comments.id = blogs.id');
$query = $db->get();
// Produces:
// SELECT * FROM blogs
// JOIN comments ON comments.id = blogs.id
$db->where();
This function enables you to set WHERE clauses
using one of four methods:
$db->where('name', $name);
$db->where('title', $title);
$db->where('status', $status);
// WHERE = 'Joe' AND title = 'boss' AND status =
'active'
Custom key/value method:
You can include an operator in the first parameter in
order to control the comparison:
$db->where($array);
$db->where($array);
Custom string:
You can write your own clauses manually:
$db->where($where);
$db->orwhere();
This function is identical to the one above, except
that multiple instances are joined by OR:
$db->like('title', $match);
$db->like('body', $match);
$db->like($array);
$db->groupby("title");
$db->groupby(array("title", "date");
$db->having('user_id = 45');
$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 or
RAND()
$db->orderby("title", "desc");
$db->limit();
Lets you limit the number of rows you would like
returned by the query:
$db->limit(10);
// Produces: LIMIT 10
$db->limit(10, 20);
Inserting Data
$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
);
$db->insert('mytable', $data);
Updating Data
$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
);
$db->where('id', $id);
$db->update('mytable', $data);
// Produces:
// UPDATE mytable
// SET title = '{$title}', name = '{$name}', date =
'{$date}'
// WHERE id = $id
/*
Or as an array:
Deleting Data
$db->delete();
Generates a delete SQL string and runs the query.
// Produces:
// DELETE FROM mytable
// WHERE id = $id
// Produces:
// DELETE FROM mytable
// WHERE id = $id
Important Points
1) Try to make use of Insert and Update function for
your insert and update queries as it will give you 2
main benefits:
require_once(“array.inc.php”);
$userArray[‘Status’] = 1;
// insert the user:
$db->insert(‘Users’, $userArray);
Benchmark Class
$benchmark->mark('code_start');
$benchmark->mark('code_end');
echo $benchmark->elapsed_time('code_start',
'code_end');