Basic concept of MVC /PHP codeigniter Framework

MVC-csetunesController Part:

File Name: home.php

 

<?php

class Home_controller extends CI_Controller           //home is a controller name
{
function index()
{
$this->load->view(‘home_view’);
}

function user_registration()
{
$this->load->model(‘user_model’);
$this->user_model->user_insert();
}

}

?>

 View Part:

File Name: home_view.php

<html>
<head>
<title>Regitation Form</title>
<style type=”text/css”>
form li{ list-style: none;}
</style>

</head>
<body>

<div id=”container”>
<div id=”header”> <center> <h1>User Registration</h1> </center>  </div>
<div id=”content”>

<?php echo form_open(‘home_controller/user_register’); ?>

<b>Please fill in the details below.</b><br/>

<?php echo validation_errors(); ?>
<?php echo form_open(‘form’); ?>

<label>User ID</label>
<div><input type=”text” name=”userid” value=”" size=”30″> </div>
<label>User Name</label>
<div><input type=”text” name=”username” value=”" size=”30″> </div>
<label>Department</label>
<div><input type=”text” name=”department” value=”" size=”30″> </div>

<div><input type=”submit” value=”Submit” /></div>

<?php echo form_close();?>

</div>
<div id=”sidebar1″></div>
<div id=”sidebar2″>

</div>

<div id=”footer”></div>
</div>

</body>
</html>

Model Part:

File Name: user_model.php

<?php

class User_model extends CI_Model
{

function user_insert()
{
$this->load->database();      // Connect to the Database
$userid = $this->input->post(‘userid’);
$username = $this->input->post(‘username’);
$department = $this->input->post(‘department’);
$data = array(‘userid’ => $userid, ‘username’ => $username, ‘department’ => $department);
$this->db->insert(‘usertable’,$data);      // usertable is table name

}

}

?>

 

Setting the following options

Config folder => autoload.php

$autoload['libraries'] = array(‘database’,'session’);

$autoload['helper'] = array(‘html’,'form’,'url’);

Config folder =>config.php

$config['base_url']            = ‘http://localhost/CodeIgniter_2.1.3/’;   //set your Base URL

$config['encryption_key'] = ‘session’;   // set sessoin

Config folde =>database.php

$db['default']['hostname'] = ‘localhost’;

$db['default']['username'] = ‘root’;

$db['default']['password'] = ”;

$db['default']['database'] = ‘userdb’;  // set your Database Name

Config folder =>routes.php

$route['default_controller'] = “home_controller”;  //Set your cotroller name

 

 


 

I am Ohli Ahmed ,student of Dhaka University of Engineering & Technology(DUET),Department of  Computer Science & Engineering (CSE). I have learned some  web languages such as C,C++,C#,HTML,CSS, PHP, Java, JavaScript , SQL server,Oracle 10g & MySQL database . I am still now PHP programming .

About csetunes:

CseTunes is the huge of  information gathered. There are many software’s, Tutorials & Tips in here.