It is currently Sun May 19, 2013 3:55 pm

All times are UTC


You can access below Applications



Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: what is codeigniter ?
PostPosted: Tue Jul 13, 2010 5:49 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
Hi

CodeIgniter is a toolkit for people who build web application using 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. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

Where to get CodeIgniter?


• Official website http://codeigniter.com/
• Download URL http://codeigniter.com/download.php
• Manual URL http://codeigniter.com/user_guide/

Installation steps


CodeIgniter is installed in four steps:

1. Unzip the package.

2. Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.

3. Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key.

4. If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.

If you wish to increase security by hiding the location of your CodeIgniter 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.

Advantage of Code Igniter

1. Lightweight
It is light weight, that is additional libraries are loaded dynamically based on the request given by the process. The core system requires only a few very small libraries compare to other framework.

2. Fast

3 .Uses M-V-C
Codeigniter uses Model-view-controller approach, which allows great separation between logic and presentation.

4 .Generates clean URLs

URL generated by CodeIgniter are clean and search-engine friendly.
It uses a segment-based approach.

Example.com/new/article/345


Note: By default the index.php file is included in the URL but it can be removed using a simple .htaccess file.

5. Packs a punch

Codeigniter have full range of libraries which enable the most commonly need web development tasks, like
    Accessing database
    Sending email
    Validation form data
    Maintaining sessions
    Manipulating images,
    Working with xml-RPC(Remotoer procedure call) data etc…


6. Extensible
It can be easily extended through plugins and helper libraries or class extensions or system hooks

7. Doesn’t require a template engine


8. Thoroughly documented
Code is extremely clean and well commented as well
Share |

_________________
Thanks,
A.ThangaSornam,

QualityPointTechnologies,
Ottapidaram.


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Tue Jul 13, 2010 8:55 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
hi
codeigniter uses m-v-c i.e model view controller here i will give sample code how codeigniter works around mvc.

why codeigniter use the m-v-c architecture?

The back and front end of the application are separated and communicate using the controller,it will makes the code readable and easier to understand . codeigniter separate the design(view) and back end operations ,i.e insert,delete etc(model) and connect using the controller.



what is model ?

Models have to do with connecting to a database and performing Create, Read, Update and Delete operations. Starting letter should be capital letter for the model class name where as class name equal to the file name .

what is controller ?

A Controller is simply a class file that is named in a way that can be associated with a URI.
Create the controller file form.php and the class name of the controller must be same as the file name and initial letter of the class name must be start with upper case other wise it is not valid.

In below example the Form_model functions performed the INSERT and SELECT statements. The controller will call these functions to output what it needs to display to a view. All database-related functions in CodeIgniter are set and called using a model. The front end is displayed and managed by the view.

what is view?

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 is responsible for fetching a particular view. If you have not read the Controllers page you should do so before continuing viewing.

Example

I have database sample and containing table name articles , articles table have id and title , this sample code list out the data from the articles table and allow to add new one to the articles table through form.

The application folder present in the codeigniter

form_model.php (model)

save this file in the application/models/form_model.php

Code:

<?php
class Form_model extends Model 
{
function Formmodel() {
// load the parent constructor
parent::Model();
}
function submit_posted_data() {
// db is initialized in the controller, to interact with the database.
$this->db->insert('articles',$_POST);    
}
function get_all_data() {
// again, we use the db to get the data from table ‘form’
$data['result']=$this->db->get('articles');
return $data['result'];
}
}
?>




save this file in the application/control/form.php

form.php(controller file )

Code:

<?php
class Form extends Controller 
{
function Form(){
// load Controller constructor
parent::Controller();
// load the model we will be using
$this->load->model('form_model', '', TRUE);
// load the database and connect to MySQL
$this->load->database();
// load the needed helpers
$this->load->helper(array('form','url'));
}
//Display the posted entries
function index() {
$data['title']='Form Data';
//use the model to get all entries
$data['result'] = $this->form_model->get_all_data();
// load 'forms_view' view
$this->load->view('forms_view',$data);
}
         
//Process the posted form
function submit() {
//use the model to submit the posted data
$this->form_model->submit_posted_data();
redirect('form');
}
}
?>

  



save this file in the application/view/forms_view.php


forms_view.php

Code:

 
<table border='1'>
<tr>
<th>ID</th>
<td>Article Title</td>
</tr>
<?php foreach($result->result_array() as $entry):?>
<tr>
<th><?php echo $entry['ArticleID'];?></th>
<td><?php echo $entry['ArticleTitle'];?></td>
</tr>
<?php endforeach;?>
</table>
<?php echo form_open('form/submit'); ?>
<br><br>
Titile<br>
<input type="text" name="ArticleID"><br>
Entry<br>
<input type="text" name="ArticleTitle">
<input type="submit" value="New">
</form>



after creating these three files open the browser and then type the url like as below

form is controller file name

Example: http://www.example.com/index.php/form
Share |

_________________
Thanks,
A.ThangaSornam,

QualityPointTechnologies,
Ottapidaram.


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Tue Jul 13, 2010 11:21 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
How to validate the form fields and retain the value after submitting if any error msg, in code igniter ?

using codeIgniter is easy to validate the form data .Here i give one sample code for creating form and validation

design file(html view or presenting data) store in the applicaiont/views/filename
control file(connecting the view and model file ) store in the applicaiton/controller/filename
model file(backend operation) store in the application/model/filename

using control file only we may view the file


create a design file and store it in the application/views/myform.php

myform.php

Code:

 
<body>
<?php echo validation_errors(); //form validation function return error msg if not correct other wise it return the empty
?>

<?php echo form_open('form'); ?>

<h5>Username</h5>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
<!-- if we want to display the error msg indiviually means place before the text box--><?php //echo form_error('password'); ?>
<h5>Password</h5>
<input type="password" name="password" value="<?php echo set_value('password'); ?>" size="50" />

<h5>Password Confirm</h5>
<input type="password" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" />

<h5>Email Address</h5>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" />

<div><input type="submit" value="Submit" /></div>
</form>




and create a control file name form.php (store in the application/controller/form.php)

Code:


<?php

class Form extends Controller 
{
    
    function index
()
    {
        $this->load->helper(array('form', 'url')); //load the helper file
        
        $this
->load->library('form_validation'); //load the library file
                
        $this
->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]'); // set rules for the form data
        $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');

        if ($this->form_validation->run() == FALSE) 
        
{
            $this->load->view('myform');
        }
        else
        
{
            $this->load->view('formsuccess');
        }
    }
}
?>


form_validation function return false by default , if the rules are successfully applied means it return true

validation_errors - return empty if validation success or return error message

$this-> form_validation->set rules() have three parameters
exact the name what we given to form field
user comments
set condition for form fields




and create the formsuccess page for display the enter data is correct submitted this file is for design so we should store it in the application/views/formsuccess.php

Code:
<body>
<h3>Your form was successfully submitted!</h3>

<p><?php echo anchor('form', 'Try it again!'); ?></p>
<!--if the want to check it again go back-->
</body>
       


then run this code by typing this url in the browser

http://www.example.com/index.php/form

Thanks
A.Thangasornam
Share |


Top
 Profile  
 
 Post subject: Re: what is codeingiter ?
PostPosted: Wed Jul 14, 2010 7:22 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
Hi

Codeigniter have a wonderful feature called scaffolding to manage our database through screen instead of using phpmyadmin to edit ,update,etc..

Scaffolding is easy way to manage data in the database like insert,update,edit ,delete. These operation are wants to be do means we have a secret word .using that secret word only we can work on datamainipulation in database but it is risk if insecure user knows that secret word.

How to use scaffolding?

open the routers.php in the config folder (application/config/routers.php) find the following
scaffolding["trigger"]=";
give the secret word to this and then create controller file

Code:

   
  <?php
  
class Blogscaff extends  Controller {

       function 
Blogscaff()
       {
            
parent::Controller();

            
$this->load->scaffolding('table_name');//must be pass the tablename 
       
}
}
?>
  


The above code loaded the tablename to the scaffolding function

To Run this file open the browser and type the url like following way

http://www.example.com/index.php/classname/secretword/

Example: http://www.example.com/index.php/blogscaff/abrsfsfsf/

then you can see the table data.


Thanks
A.Thangasornam
Share |


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Thu Jul 15, 2010 8:17 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
Hi
how to run the codeigniter?
After download the codeigniter , unzip the folder and create one sample applicaition(see my second post or third post) then open the system folder then find the application folder,open it and then open the config folder , there is config file
(i.e system/application/config/config.php)

and search this $config['base_url'] = " in config file

it look like this format

$config['base_url'] = "www.example.com";

you have change the url with your website url, if your are working in locahost means give the path of the codeigniter folder where it is located

example :http://localhost//codeigniter/index.php

if you used database means change the database setting also that was located in database.php file (system/application/config/database.php)

find the following code in the database.php

Code:

   $db
['default']['hostname'] = "";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci"; 


and then change the hostname,username,password,database name etc.. do your wish to set the database setting with this code

then open the browser and run your applicaiton,

http://www.example.com/index.php/controll file name

using controller file only we can run application which is creted by codeigniter. because codeigniter is m-v-c architecture.

By default, the index.php file will be included in your URLs, we may easily remove index.php using .htaccess file.

Thanks
A.Thangasornam
Share |


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Thu Jul 15, 2010 11:14 am 
Offline

Joined: Wed Mar 17, 2010 4:58 am
Posts: 69
Location: Neyveli
How to give css to form in forms_view.php file?

the code look like as below:

Code:

<html>
    <head>
        <title>Title</title>
        <style type="text/css">
        .form1
        {
        background-color:#808000;
        color:#FF0000;
        }
        </style>
    </head>
<body>
<table border='1'>
<tr>
<th>ID</th>
<td>Employee Name</td>
</tr>
<?php foreach($results->result_array() as $entry):?>
<tr>
<th><?php echo $entry['empid'];?></th>
<td><?php echo $entry['empname'];?></td>
</tr>
<?php endforeach;?>
</table>
<?php 
$attributes
=array('class'=>'form1','id'=>'id1');  // give id and name of class in associative array
echo form_open('form/submit',$attributes);  // pass the parameter while creating the form
?>
<br><br>
Title<br>
<input type="text" name="ArticleID"><br>
Entry<br>
<input type="text" name="ArticleTitle">
<input type="submit" value="New">
</form>
</body>
</html>



Thanks
vetriselvi k
Share |


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Thu Aug 05, 2010 11:27 am 
Offline
User avatar

Joined: Tue Mar 02, 2010 10:49 am
Posts: 171
Location: India/Tamilnadu/Tirunelveli
Hi ,

Do you know how to add security code (captcha) ? i used default plugin module for this, but still i get error,

Quote:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: captcha
Filename: views/account_trainer_profile_edit.php
Line Number: 148


Any suggestion?
Share |

_________________
Anbarasan k


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Sat Aug 07, 2010 11:53 am 
Offline
User avatar

Joined: Tue Mar 02, 2010 10:49 am
Posts: 171
Location: India/Tamilnadu/Tirunelveli
You know how to add unique title and Meta description in web page from mysql table?

I have one table for storing Meta information. When user logged in they have option for edit their Meta info.

How to display this Meta data info into each page from this table?
Share |

_________________
Anbarasan k


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Mon Aug 09, 2010 4:31 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
Hi anbarasan

i think this link is helpful to you for handling captcha in codeigniter. if this is not suitable what you want post your queries
clik this link

click this link

Thanks
A.Thangasornam
Share |


Top
 Profile  
 
 Post subject: Re: what is codeigniter ?
PostPosted: Mon Aug 09, 2010 4:36 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
Hi

you have database for meta information , you can code into all pages in models as well as views for edit and modify . this manipulation is like normal database operation. if you feel any other way for doing this or my post is not good answer, tell your suggestions.


Thanks
A.Thangasornam
Share |


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron