Showing posts with label Codeigniter. Show all posts
Showing posts with label Codeigniter. Show all posts

Mysql Join query Codeigniter

Mysql Join query Codeigniter

code loads and initializes the database class based on your
configuration settings.

$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(); 



Mysql Join query  Codeigniter


$this->db->select('*');    
$this->db->from('tbl1');
$this->db->join('tbl2', 'tbl1.id = tbl2.id');
$this->db->join('tbl3', 'tbl1.id = tbl3.id');
$query = $this->db->get();
 
The above get() function retrieves all the results
 from the supplied table. 

Checking the values of the form-codeigniter

Checking the values of the form-codeigniter


We need to ensure that all of the form fields have been filled in. We can do this by
simply using the empty()PHP function.
Before we do this, we want to assign the value of the form fields to variables.
This makes it easy for us by saving us from having to type out
$this->input->post('name')every time. Here's the code for this; it should be placed inside
the ifstatement where the comment // process data herewas.
$name = $this->input->post('name');
$email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
With that out of the way, we can check to see if any of the fields were left blank, and
show an error if they were.
if(empty($name) OR empty($email) OR empty($subject) OR
empty($message))
{
show_404("The form submitted left fields blank, all fields are
required. Please go back and fill in all of the fields.");
}
Let me explain this code. What we do in the if statement is say "If the name is
empty, or the email is empty, or the subject is empty or the message is empty:
show this error". I've used ORin place of ||in this instance as it's more readable,
and is recommended by the CodeIgniter Style Guide.

Validate the e-mail
The next step that we need to take is to ensure that the email is correctly formatted.
The Email Helper gives us an easy solution. It contains a function that checks
whether a string is in the format email@domain.com. Here's how we check
the e-mail:
if(!valid_email($email))
{
show_404("The email address provided is not a valid email. Please go
back and fill in all of the fields.");
}

Top codeigniter interview question and answers

codeigniter interview question

 What is codeigniter?
Codeigniter is open source , web application framework.Its is for building websites using php.Codeigniter is loosely based on MVC pattern.Most simple framework in php , which is you will easily learn.Its mostly known for its speed as compare to other frameworks in php.
Its goal is to enable you to develop projects much 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.

 When and who developed codeigniter?
The first public version of CodeIgniter was released on February 28, 2006.

 What are the features of codeigniter?
 Codeigniter is free to use,its an open source framework.
 Its light weight.The core system requires only a few very small libraries.Not like other frameworks that require heavy file libraries.
Why codeigniter?
 CodeIgniter is Fast.Its faster than any other framework in php.
 The URLs generated by CodeIgniter are clean and search-engine friendly.You will change any url to what ever you want from files.
 CodeIgniter is Extensible.The system can be easily extended through the use of your own libraries, helpers, or through class extensions or system hooks.

What is MVC
 CodeIgniter Uses MVC(Model View Controller) which allows great separation between logic and presentation.

 CodeIgniter requires nearly zero configuration,does not require you to use the command line,not forced to learn a templating language.

 Full Featured database classes with support for several platforms,Security and XSS Filtering,Error Logging.
 Explain Codeigniter File Structure.

When you download Codeigniter you will see the following folder structure :-

    application
        cache
        Config
        Controllers
        core
        errors
        helpers
        hooks
        language
        libraries
        logs
        models
        thirdparty
        views
    system
        core
        database
        fonts
        helpers
        language
        libraries
 Explain MVC in Codeigniter.
  Controller:- The Controller serves as an intermediary between the Model
, the View. controller mediates input, converting it to
commands for the model or view.

Model:-The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert,
and update information in your database.The model consists of application data and business rules.

View:-The View is the information that is being presented to a user. A View will normally be a web page.A view can be any output representation of data.

What are the hooks in codeigniter?
CodeIgniter’s Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files.How ever you like to cause some action to take place at a particular stage in the execution process.
he hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file:
$config['enable_hooks'] = TRUE;

Hooks are defined in application/config/hooks.php file.For example
    $hook['pre_controller'] = array(
     'class'    => 'MyClass',
     'function' => 'Myfunction',
     'filename' => 'Myclass.php',
     'filepath' => 'hooks',
     'params'   => array('test', 'test1', 'webs')
     );

What are the helpers in codeigniter?
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.

Loading a helper file is quite simple using the following function:
    $this->load->helper('name');

How you will use or add codeigniter libraries?
All of the available libraries are located in your system/libraries folder. In most cases, to use one of these classes involves initializing it within a controller using the following initialization function:-
    $this->load->library('class name');

codeigniter-Creating loops

Creating loops in view files has been a stumbling block for a few developers. By
passing a multidimensional array to a view file, you can easily establish a loop in
any of your view files. Let's take a look at an example.
<?php
class Todo extends Controller
{
function index()
{
$data['todo_list'] = array("buy food", "clean up", "mow lawn");
$this->load->view('todo', $data);
}
}
?>
This is a very simple Controller. Your view file for this would be as follows:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $heading; ?></h1>
<?php echo $content;?>
<h2>My Todo List</h2>
<?php
foreach($todo_list as $item)
{
echo $item;
}
?>
</body>
</html>

Returning views as data
Youare also able to return view files as data; this can be useful if you wish to process
this data in some way. Simply set the third parameter to boolean TRUE—and it will
return the view data.

$this->load->view('welcome', NULL, TRUE);

CodeIgniter uses an output buffer to take all calls to the load view function, and
processes them all at once, sending the whole page to the browser at the same time.
So when you return views as data, you will be able to save the contents of theview
inside a variable for whatever use you need.

CodeIgniter models

All CodeIgniter models have the same initial structure:

< ?php
class Page_model extends Model{
function Page_model(){
parent::Model();
}
}
? >

The first function is the code that retrieves the home page

< ?php
class Page_model extends Model{
function Page_model(){
parent::Model();
}
function fetchHomePage(){
$data = array();
$options = array(‘status’ = > ‘live’, ‘type’= > ‘home’);
$q = $this- > db- > getwhere(‘pages’, $options, 1);
if ($q- > num_rows() > 0){
$data = $q- > row_array();
}
return $data;
$q- > free_result();
}
}
? >

Notice that the name of the model  Page_model  is both the
 name of the class and the name of the initializing function.
 This file is stored in the /system/application/models/ folder
 of your project, more than likely with a name
 like page_model.php.

Let's Make A Master Template codeigniter

A simple CSS file, it ’ s time to create a generic Template view that
you can reuse throughout your application. In this master template, which
you can name template.php, are a series of embedded PHP calls that load
certain subviews, such as header, navigation, and footer.

These subviews contain the HTML and PHP that you will create in the
 next few sections. Notice in the following code that you ’ re also trying
to load a subview with $main. This variable will contain the name of a
subview that is dynamically set within the controller and allows you a
 great deal of flexibility as you code your application.

< !DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd” >
< html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en” >
< head >
< meta http-equiv=”content-type” content=”text/html; charset=utf-8” / >
< title > < ?php echo $title; ? > < /title >
< link href=” < ?= base_url();? > css/default.css” rel=”stylesheet” type=”text/css” / >
< script type=”text/javascript” >
// < ![CDATA[
base_url = ‘ < ?= base_url();? > ’;
//]] >
< /script >
< /head >
< body >
< div id=”wrapper” >
< div id=”header” >
< ?php $this- > load- > view(‘header’);? >
< /div >
< div id=”nav” >
< ?php $this- > load- > view(‘navigation’);? >
< /div >
< div id=”main” >
< ?php $this- > load- > view($main);? >
< /div >
< div id=”footer” >
< ?php $this- > load- > view(‘footer’);? >
< /div >
< /div >
< /body >
< /html >

what is CodeIgniter Helpers?

Helpers, as their name implies, help you with specific tasks. Unlike libraries, helpers are not object -oriented but procedural in nature. Each helper contains one or more functions, each focusing on a
specific task, with zero dependence on other functions.

Helpers can either be loaded locally or autoloaded in /system/application/config/autoload.php.

CodeIgniter's  helpers:

Array —  The   Array helpercontains functions that help you work with arrays. For example, the
random_element()function takes an array as input and returns a random element from it.

Cookie —  The   Cookie helpercontains functions that help you set, read, and delete cookie data.

Date —  The   Date helpercontains functions that help you work with dates. For example, the
now function returns the current time as a UNIX time stamp.

Directory —  The   Directory helpercontains a single function that helps you work with directories.
For example, the directory_mapfunction reads a specified directory path and builds an array
of it that contains all of its files and subdirectories.


Download —  The   Download helpercontains a single function that helps you download data
easily. The force_download()function generates server headers that force data to be
downloaded instead of viewed in a browser.

File —  The   File helpercontains functions that help you read, write, and delete files.

Form —  The   Form helpercontains functions that help you build forms. It is probably one of the
most used helpers in the CodeIgniter toolbox.

HTML —  The   HTML helpercontains functions that help you create HTML blocks quickly and
easily. For example, the ul()function can turn an array of items into a bulleted list.

Inflector —  The   Inflector helpercontains functions that help you to turn words into plural or
singular form, to apply camel case, or to turn words separated by spaces into an underscored
phrase.

Security —  The   Security helpercontains security - related functions like xss_clean(),  which
filters out any code that may be used in a cross site scripting hack.

Smiley —  The   Smiley helpercontains functions that help you manage emoticons. The functions
in this helper might seem superfluous, but become invaluable if you are coding a bulletin board
or chat application.

String —  The   String helpercontains functions that help you work with strings, like the random_
string  function, which as its name implies, creates random strings based on type and length
arguments.

Text —  The   Text helpercontains functions that help you work with text. For example, the word_
limiter function can limit a string to a certain number of words, which is useful if you ’ re
trying to limit user input on a form.

Typography —  The   Typography helpercontains a single function that helps you format text in
appropriate ways. For example, the auto_typography()function wraps paragraphs with < p >
and < /p > , converts line breaks to < br/ > , and converts quotes, dashes, and ellipses properly.

PHP, you can use the substr()function instead of the word_limiter or character_limiter
made available by the Text helper. Certainly, you ’ re not forced to use helpers, but they ’ re made available
to you, and they do a fine job of saving time and effort.


Codeigniter Database Library

The  Database librarycontains a series of helpful functions that make it easy for you to create and run
queries and process the result sets from those queries.

The first thing to note about the Database library in CodeIgniter is that it allows you to pass in simple
SQL queries. At the end of the day, many people who are new to CodeIgniter find this to be a great
comfort. Although some of the built - in Active Record patterns provide helpful shortcuts, just knowing
that you can bypass all of that and send in a complex query.

$sql = “select a.name, a.id, b.groupname
from persons a, groups b
where a.group_id = b.id
group by b.groupname, a.name”;
$Q = $this- > db- > query($sql); 

To loop over the result set of that query, you can use either the result()or result_array() methods,
depending on whether you like to process your results as an object or as an array.

$sql = “select a.name, a.id, b.groupname
from persons a, groups b
where a.group_id = b.id
group by b.groupname, a.name”;
$Q = $this- > db- > query($sql);
foreach ($Q- > result() as $row){
echo $row- > name;
echo $row- > id;
echo $row- > groupname;
}
//here’s the alternative approach, with result_array
foreach ($Q- > result_array() as $row){
echo $row[‘name’];
echo $row[‘id’];
echo $row[‘groupname’];
}

If you need a count of rows in a result set, use the num_rows() method:
$sql = “select a.name, a.id, b.groupname
from persons a, groups b
where a.group_id = b.id
group by b.groupname, a.name”;
$Q = $this- > db- > query($sql);
if ($Q- > num_rows()){
foreach ($Q- > result() as $row){
echo $row- > name;
echo $row- > id;
echo $row- > groupname;
}
}
Sometimes you may have a query that generates just one result row.

codeigniter routes page

The  routes.php filelets you remap URI requests to specific controller functions. For example, you may
have a controller named sitewith a function named index. The URI for this controller/function
combination might be:
http://www.example.com/site/index
Furthermore, if your site controller had a pagesfunction that accepted a numeric ID for database
lookup, the URI might look like this:
http://www.example.com/site/pages/4
In some cases, you might want to remap one or more of these default routes. For example, the second
example might be better displayed as this:
http://www.example.com/about_us/
In that case, your routes.php file would contain a rule like this:
$route[‘about_us’] = “site/pages/4”;
For right now, though, this kind of manipulation falls under “ advanced  usage, ”  so  don ’ t  worry  too  much
about it. However, please do note that this kind of thing is possible. Also, be aware that two “ reserved
routes ” exist: default_controller and scaffolding_trigger.
$route[‘default_controller’] = “welcome”;
The default_controller route tells CodeIgniter which controller should be loaded if no controller is
identified. For simplicity ’ s sake, keep this setting.

CodeIgniter Libraries

CodeIgniter libraries help you do your job faster and more efficiently. Each libraryis really a PHP class
with various methods that you can use once the library is loaded by a controller.

CodeIgniter gives  the following libraries:
Benchmarking —  The   Benchmarking libraryis always active. Use it to determine the time
difference between any two marked points in code and to calculate memory usage.

Calendaring —  The   Calendaring librarymust be loaded by a controller. Use it to dynamically
create calendars for given months and years, with some control over formatting and appearance.

Config —  The   Config libraryis initialized automatically by the system. Use it to retrieve
configuration information.

Database —  The   Database libraryis a very powerful set of methods that must be loaded. You ’ ll
be using this library so much that the next subsection of this chapter focuses on it exclusively.

Email —  The   Email librarymust be loaded. It includes a very powerful set of tools that simplifies
the job of sending e - mails.

Encryption —  The   Encryption librarymust be loaded. It provides you with powerful two - way
encryption methods.

File Uploading —  The   File Uploading librarymust be loaded. Use this library whenever you need
to handle file uploads. It includes powerful validation features that can restrict a file by mime
type, size in kilobytes, or even image dimensions.

FTP —  The   FTP librarymust be loaded. Use this library to transfer files to a remote server only
standard FTP is supported, by the way.

HTML Table —  The   HTML Table librarymust be loaded. Use this very versatile library to
autogenerate HTML tables from arrays or database result sets.

Image Manipulation —  The   Image Manipulation librarymust be loaded. Use it to resize images,
create thumbnails, crop or rotate images, and watermark images. Some functions require further
PHP support such as GD/GD2.

Input and Security —  The   Input and Security librarymust be loaded. Use it to pre - process  input
data from forms and URLs and to handle some security functions such as guarding against
XSS attacks.

Language —  The   Language librarymust be loaded. Use this library to load different sets of
language files for internationalization.

Loader —  The   Loader libraryis automatically loaded. You will use this library primarily to load
views with your controller, but it is also used to load libraries.

Output —  The   Output libraryis automatically loaded. This library has one main function: Send
the finalized web page to the requesting browser. It is also used for caching.

Pagination — The  Pagination librarymust be loaded. Use this labor - saving library to paginate
database results for performance and usability. You can control how many records to display per
page, how many records to pull from the database, and the look and feel of different parts of the
pagination.

Session —  The   Session librarymust be loaded. Use CodeIgniter ’ s Session library to maintain
state information about a user. This library does not use PHP ’ s  built - in  sessions  —  instead,  it
generates its own session data. Because this library is so important, a separate subsection of this
chapter is devoted to it.

e-mail parameters-Codeigniter

The next thing that we will need to do is to set our e-mail parameters, the sender,
the recipient, any e-mail address to send a carbon copy or blind carbon copy to, the
subject of our e-mail, and the message body. Take a look at the following code and
see if you can distinguish the different parts of our e-mail:

$this->email->from('you@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@person.com');
$this->email->bcc('theboss@example.com');
$this->email->subject('Email Test');
$this->email->message('This is a simple test we wrote for the email
class.');


Hopefully you can read the previous code example pretty easily. This is one of the
benefits of CodeIgniter and its libraries. It's very easy to read CodeIgniter code. In
the first line of code we set our e-mail address, which is the address that we will send
the e-mail from, and also pass along a name to identify ourselves. In the next line,
we set the recipient, who is the person that we are sending the e-mail to. The next
line down is an e-mail address to send a carbon copy of the e-mail to. A carbon copy
is simply a copy of the e-mail, just sent to another person. The final line of the first
block is the e-mail address to which we will send a blind carbon copy to. A blind
carbon copy is the same as a carbon copy, except for the other recipients of the
e-mail do not know that this person also has received a copy of this e-mail.


Now, to send our e-mail we simply call the sendfunction of the e-mail library. Here's
how we do it.
$this->email->send();

There is another function available to us from this library. It's a debugger that echo's
out some information provided to us by the various mail sending protocols, and
we are also notified what has been sent and whether or not the e-mail was sent
successfully. To show the debugging information, we use the following line of code:
echo $this->email->print_debugger();

code looks like this:

$this->load->library('email');
$this->email->from('you@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@person.com');
$this->email->bcc('theboss@example.com');
$this->email->subject('Email Test');
$this->email->message('This is a simple test we wrote for the email
class.');
$this->email->send();
echo $this->email->print_debugger();


You are not just limited to sending e-mail from inside Controllers; e-mails can also be
sent from Models.

Retrieving data-Codeigniter


Retrieving POST data

Toretrieve post data, you should use the function shown next. The first parameter is
the name of the POST item that you are looking for.
$this->input->post('some_field');

This function returns the item it if exists, and returns FALSE if it does not. The
second function lets you run the data through the XSS filter without writing any
more code. This is an easier way of running the XSS filter on a per-item basis.
$this->input->post('some_field', TRUE);

Retrieving GET data

The function for retrieving GET data is identical to the POST function, except that it
only retrieves GET data.
$this->input->get('some_field', TRUE);

Retrieving GET and POST data

This function will search through the GET and POST streams for data; looking inside
POST first, then GET. It works in the same way as the previous functions.
$this->input->get_post('some_field', TRUE);

Retrieving COOKIE data

This function is the same as those listed previously, but will only look in the
COOKIE data.
$this->input->cookie('some_field', TRUE);

Retrieving SERVER data

This function is the same as the previous examples, except it only returns
SERVER data.
$this->input->server('some_field', TRUE);

IP Addresses

Toretrieve the user's IP address, you should use the next function. If the IP address
isn't valid, it will return 0.0.0.0.
$this->input->ip_address();
To validate an IP address, you should use the next function. It will return TRUE or
FALSE. The previous function validates the IP automatically.
if ( ! $this->input->valid_ip($ip))
{
echo "Not a valid IP";
}
else
{
echo "Valid IP!";
}

CodeIgniter system Folder

The system/ folder is where all the action happens. This folder contains all the CodeIgniter code of
consequence, organized into various folders:

application —  The   application foldercontains the application you ’ re building. Basically, this
folder contains your models, views, controllers, and other code (like helpers and class
extensions). In other words, this folder is where you ’ ll do 99 percent of your work.

cache —  The   cache foldercontains all cached pages for your application. In Chapter 9 , you learn
more about caching and how to turn your super - speedy development application into a
blazingly fast live application.

codeigniter —  The   codeigniter folderis where CodeIgniter ’ s core classes live. You have almost no
reason to go in here. All of your work will occur in the application folder. Even if your intent is
to extend the CodeIgniter core, you would do it with hooks, and hooks live in the application
folder.

database —  The   database foldercontains core database drivers and other database utilities. Again,
there ’ s no good reason for you to be in this folder.
fonts —  The   fonts foldercontains font - related information and utilities. Again, there ’ s no reason
to spend any time here.

helpers —  The   helpers foldercontains standard CodeIgniter helpers (such as date, cookie, and
URL helpers). You ’ ll make frequent use of helpers in your CodeIgniter career and can even
extend helpers thanks to improvements introduced in CodeIgniter version 1.6.

language —  The   language foldercontains language files. You can ignore it for now.

libraries —  The   libraries foldercontains standard CodeIgniter libraries (to help you with e - mail,
calendars, file uploads, and more). You can create your own libraries or extend (and even
replace) standard ones, but those will be saved in the application/libraries directory to keep
them separate from the standard CodeIgniter libraries saved in this particular folder.

logs —  The   logs folderis the folder CodeIgniter uses to write error and other logs to.


plugins —  The   plugins foldercontains plugins. Plugins and helpers are very similar, in that they
both allow developers to quickly address an issue or create content like forms, links, etc..

However, the main difference between them is that plugins usually consist of one function,
while helpers often have many functions bundled inside them.

CodeIgniter config.php

The  config.php filecontains a series of configuration options all of them stored in a PHP array called,
appropriately enough, $config) that CodeIgniter uses to keep track of your application ’ s  information
and settings.

The first configuration option you need to set inside config.php is the base URL of your application. You
do that by setting the absolute URL (including the http:// part) for $config[ ‘ base_url ’ ], like so:
$config[‘base_url’] = “http://www.example.com/test/”;

Once  you ’ ve set this configuration option, you can recall it whenever you want using the CodeIgniter
base_url()function, which can be a very handy thing to know. This one feature keeps you from
having to rewrite hard - coded URLs in your application, when you migrate from development to test or
from test to production.

The second thing you need to do is set a value for your home page by editing the $config[ ‘ index_
page ’ ]configuration option. CodeIgniter ships with a value of “ index.php ”  for  this  option,  which
means that index.php will appear in all of your URLs. Many CodeIgniter developers prefer to keep this
value blank, like so:
$config[‘index_page’] = ‘’;
To make this work, you need to include an .htaccess file to the CodeIgniter root directory, After  you ’ ve set this option value, there ’ s very little to do.
 For now, leave all the other values at their
default settings:
$config[‘uri_protocol’] = “AUTO”;
$config[‘url_suffix’] = “”;
$config[‘language’] = “english”;
$config[‘charset’] = “UTF-8”;
$config[‘enable_hooks’] = FALSE;
$config[‘subclass_prefix’] = ‘MY_’;
$config[‘permitted_uri_chars’] = ‘a-z 0-9~%.:_-’;
$config[‘enable_query_strings’] = FALSE;
$config[‘controller_trigger’] = ‘c’;
$config[‘function_trigger’] = ‘m’;
$config[‘log_threshold’] = 0;
$config[‘log_path’] = ‘’;
$config[‘log_date_format’] = ‘Y-m-d H:i:s’;


$config[‘cache_path’] = ‘’;
$config[‘encryption_key’] = “enter_a_32_character_string_here”;
$config[‘sess_cookie_name’] = ‘ci_session’;
$config[‘sess_expiration’] = 7200;
$config[‘sess_encrypt_cookie’] = TRUE;
$config[‘sess_use_database’] = FALSE;
$config[‘sess_table_name’] = ‘ci_sessions’;
$config[‘sess_match_ip’] = FALSE;
$config[‘sess_match_useragent’] = TRUE;
$config[‘cookie_prefix’] = “”;
$config[‘cookie_domain’] = “”;
$config[‘cookie_path’] = “/”;
$config[‘global_xss_filtering’] = TRUE;
$config[‘compress_output’] = FALSE;
$config[‘time_reference’] = ‘local’;
$config[‘rewrite_short_tags’] = FALSE

For more details on each of these configuration options, simply read the comments embedded in /
system/application/config/config.php. You will also get more detail on certain settings as you work
through the sections of the book and tweak the configuration as needed. For example, at some point, you
will want to use encryption for security purposes or set your logging threshold for debugging, and they
both require making changes to this file.

CodeIgniter ’ s Global XSS Filtering option is set to FALSE by default. The online User Guide suggests
that setting this to TRUE adds a lot of performance overhead to the system. However, at this point, it is
better to have some global protection put in place. That way you can be assured of some security
precautions while you ’ re in development. Chapter 9 discusses security issues in more depth, but for
now, it ’ s good to have something in place while you ’ re  developing.

In the same security vein, notice that sess_encrypt_cookie has been set to TRUE, and that you are to
enter a 32 - character encryption salt in encryption_key. Doing these two things will encrypt any
sessions and provide a salt for any hashing methods you use. Be sure to use a random string of upper -
and lowercase letters and numbers.

One final note before moving on: Make sure that you write down your encryption key and keep it safe
somewhere, or, at least, maintain good backups. You ’ ll need the key to retrieve other information, so if
your site is compromised or erased or if you lose your key any other way, you ’ ll be glad you have a
record  of  it.

Codeigniter count_all for pagination


work on count_all condition.. you can use below method to find out total number of rows..


public function count_all() {
    $this->db->select ( 'COUNT(*) AS `numrows`' );
    $this->db->where ( array (
            'type' => 'Original'
    ) );
    $query = $this->db->get ( 'story_tbl' );
    return $query->row ()->numrows;
}

ou could also use the built-in num_rows() function...
$query = $this->db->where('type', 'original')->get('story_tbl');
return $query->num_rows();