For creating a simple web-page ,there are three things that we need ..
First one is frontend language any one of the following--PHP,ASP.net,JAVA etc, here we use PHP and its framework that is 'Cake-PHP' .
Second is any scripting language any one of the following-- JavaScript, ASP, JSP, PHP, Perl, Tcl and Python.
here we use JavaScript .
Scripting language is a high-level programming language that is interpreted by another program at runtime rather than compiled by the computer??s processor as other programming languages (such as C and C++) are. Scripting languages, which can be embedded within HTML, commonly are used to add functionality to a Web page.It can also be used as client-side data validation(when user enter data to the browser) .
Third one is database, used as back-end of our web page. Database contain all the relevant data in the form of tables. You can use any database as MySQL ,Oracle,MSAccess etc.
Example : - Now creating a login form (web page)....
First we create a database in MySQL with the following queries-
/*Table structure for table `tbl_admins` */
DROP TABLE IF EXISTS `tbl_admins`;
CREATE TABLE `tbl_admins` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*Data for the table `tbl_admins` */
insert into `tbl_admins`(`id`,`name`,`password`,`created`,`modified`) values (1,'a','a','2011-09-12 11:36:18','2011-09-12 11:36:18');
When you download cake_php ,it contain many folders and then go to 'app' folder ,here we work for creating any web page or any website. "app" folder also contain many folders and php files.first go in 'config' folder and open "database.php" then set the database name as--
then open the 'routes.php' in the 'config' folder and change the routes as--
Router::connect('/', array('controller' => 'admins', 'action' => 'index'));
and in the 'views' folder create a folder by the name 'admins' ,in this folder create a file 'index.ctp' (it contain view for user).and write the following code---
Finally code to interact with database and to load view page is write in the controller page in the controller folder .Create a file with the name "admins_controller.php" in app/controllers ,and write the following code in that file---
here is one more file present in the 'app' folder i.e. app_controller that is extend by all controller.wrte the following code in this----
all the style define in the css folder , in the webroot folder of app folder : path /app/webroot/css....create a admin.css file and write the following css..
finally set the layout of the page .path is --app/views/laouts in layout folder create a default.ctp for default layout ,you can create multiple layout and load in to controller according to your self ...in default.ctp write the following code...(it load all the file for your web page) ..
And now you can run your web page on any browser by calling cake-php'folder name that you setted before by extracting the cake-php zip file.
First one is frontend language any one of the following--PHP,ASP.net,JAVA etc, here we use PHP and its framework that is 'Cake-PHP' .
Second is any scripting language any one of the following-- JavaScript, ASP, JSP, PHP, Perl, Tcl and Python.
here we use JavaScript .
Scripting language is a high-level programming language that is interpreted by another program at runtime rather than compiled by the computer??s processor as other programming languages (such as C and C++) are. Scripting languages, which can be embedded within HTML, commonly are used to add functionality to a Web page.It can also be used as client-side data validation(when user enter data to the browser) .
Third one is database, used as back-end of our web page. Database contain all the relevant data in the form of tables. You can use any database as MySQL ,Oracle,MSAccess etc.
Example : - Now creating a login form (web page)....
First we create a database in MySQL with the following queries-
create database if not exists `sportnews`;
/*Table structure for table `tbl_admins` */
DROP TABLE IF EXISTS `tbl_admins`;
CREATE TABLE `tbl_admins` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*Data for the table `tbl_admins` */
insert into `tbl_admins`(`id`,`name`,`password`,`created`,`modified`) values (1,'a','a','2011-09-12 11:36:18','2011-09-12 11:36:18');
When you download cake_php ,it contain many folders and then go to 'app' folder ,here we work for creating any web page or any website. "app" folder also contain many folders and php files.first go in 'config' folder and open "database.php" then set the database name as--
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'tabuser',
'password' => 'abcd1234',
'database' => 'sportnews',
'prefix' => 'tbl_',
//'encoding' => 'utf8',
);
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'tabuser',
'password' => 'abcd1234',
'database' => 'sportnews',
'prefix' => 'tbl_',
//'encoding' => 'utf8',
);
then open the 'routes.php' in the 'config' folder and change the routes as--
Router::connect('/', array('controller' => 'admins', 'action' => 'index'));
and in the 'views' folder create a folder by the name 'admins' ,in this folder create a file 'index.ctp' (it contain view for user).and write the following code---
<div class="page">
<div id="login-dialog">
<h1><?php echo __("admin_login",true)?></h1>
<div class="entry">
<center>
<div id="massage"><?php echo $session->flash();?></div>
<table width="75%" border="0">
<?php echo $form->create('Admins',array('action'=>'index','onSubmit'=>'return checkadmin()'))?>
<tr>
<td><h3><?php echo __('user_name',true)?></h3></td>
<td><h3><?php echo $form->input('Admin.name',array('type'=>'text','div'=>false,'label'=>false,'id'=>'user'))?></h3></td>
</tr>
<tr>
<td><h3><?php echo __('password',true)?></h3></td>
<td><h3><?php echo $form->input('Admin.password',array('type'=>'password','div'=>false,'label'=>false,'id'=>'pass'))?></h3></td>
</tr>
<tr>
<td> </td>
<td><?php echo $form->submit(__('login',true))?></td>
</tr>
<?php echo $form->end()?>
</table>
</center>
</div>
<div style="clear:both"></div>
</div>
</div>
<div id="login-dialog">
<h1><?php echo __("admin_login",true)?></h1>
<div class="entry">
<center>
<div id="massage"><?php echo $session->flash();?></div>
<table width="75%" border="0">
<?php echo $form->create('Admins',array('action'=>'index','onSubmit'=>'return checkadmin()'))?>
<tr>
<td><h3><?php echo __('user_name',true)?></h3></td>
<td><h3><?php echo $form->input('Admin.name',array('type'=>'text','div'=>false,'label'=>false,'id'=>'user'))?></h3></td>
</tr>
<tr>
<td><h3><?php echo __('password',true)?></h3></td>
<td><h3><?php echo $form->input('Admin.password',array('type'=>'password','div'=>false,'label'=>false,'id'=>'pass'))?></h3></td>
</tr>
<tr>
<td> </td>
<td><?php echo $form->submit(__('login',true))?></td>
</tr>
<?php echo $form->end()?>
</table>
</center>
</div>
<div style="clear:both"></div>
</div>
</div>
Finally code to interact with database and to load view page is write in the controller page in the controller folder .Create a file with the name "admins_controller.php" in app/controllers ,and write the following code in that file---
<?php
class AdminsController extends AppController
{
var $name = 'Admins';
var $uses = array('Admin');
var $layout = 'admin';
function index()
{
if($this->data)
{
$data = $this->Admin->find('count',array('conditions'=>array('Admin.name'=>$this->data['Admin']['name'] , 'Admin.password'=>$this->data['Admin']['password'])));
if($data > 0)
{
$this->Session->setFlash(__('welcome',true));
$this->redirect('/admins/index');
die;
}
else
{
$this->Session->setFlash(__('username_wrong',true));
$this->redirect('index');
die;
}
}
}
class AdminsController extends AppController
{
var $name = 'Admins';
var $uses = array('Admin');
var $layout = 'admin';
function index()
{
if($this->data)
{
$data = $this->Admin->find('count',array('conditions'=>array('Admin.name'=>$this->data['Admin']['name'] , 'Admin.password'=>$this->data['Admin']['password'])));
if($data > 0)
{
$this->Session->setFlash(__('welcome',true));
$this->redirect('/admins/index');
die;
}
else
{
$this->Session->setFlash(__('username_wrong',true));
$this->redirect('index');
die;
}
}
}
}
here is one more file present in the 'app' folder i.e. app_controller that is extend by all controller.wrte the following code in this----
<?php
class AppController extends Controller
{
var $name = "App";
var $helpers = array('Form','Html','Javascript','Session');
class AppController extends Controller
{
var $name = "App";
var $helpers = array('Form','Html','Javascript','Session');
}
all the style define in the css folder , in the webroot folder of app folder : path /app/webroot/css....create a admin.css file and write the following css..
*
{
padding: 0em;
margin: 0em;
}
body
{
background: #000000 url('../img/bg1.jpg');
padding: 35px 0px 35px 0px;
}
{
padding: 0em;
margin: 0em;
}
body
{
background: #000000 url('../img/bg1.jpg');
padding: 35px 0px 35px 0px;
}
#upbg
{
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 275px;
background: #fff url('../img/bg2.jpg') repeat-x;
z-index: 1;
}
{
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 275px;
background: #fff url('../img/bg2.jpg') repeat-x;
z-index: 1;
}
#outer
{
z-index: 2;
position: relative;
width: 82%;
border: solid 7px #fff;
background-color: #fff;
margin: 0 auto;
}
body,input
{
font-size: 10pt;
font-family: "georgia", "times new roman", serif;
color: #333333;
}
{
z-index: 2;
position: relative;
width: 82%;
border: solid 7px #fff;
background-color: #fff;
margin: 0 auto;
}
body,input
{
font-size: 10pt;
font-family: "georgia", "times new roman", serif;
color: #333333;
}
.entry {
padding: 20px 30px 10px 30px;
}
padding: 20px 30px 10px 30px;
}
#massage{
font-size:18px;
color:green;
text-align:center;
}
font-size:18px;
color:green;
text-align:center;
}
Now create a JavaScript file for client side data validation. path is -app/webroot/js and create a file by the name 'admin.js' and write the following code---
function checkadmin()
{
var user = document.getElementById('user').value;
var pass = document.getElementById('pass').value;
if(user == '' || user == null || pass == '' || pass == null)
{
document.getElementById('massage').innerHTML = "Username or password can't be blank";
return false;
}
else return true;
}
{
var user = document.getElementById('user').value;
var pass = document.getElementById('pass').value;
if(user == '' || user == null || pass == '' || pass == null)
{
document.getElementById('massage').innerHTML = "Username or password can't be blank";
return false;
}
else return true;
}
finally set the layout of the page .path is --app/views/laouts in layout folder create a default.ctp for default layout ,you can create multiple layout and load in to controller according to your self ...in default.ctp write the following code...(it load all the file for your web page) ..
<!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">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Timeless by Free CSS Templates</title>
<!--<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
--> <?php echo $html->css(array('admin.css'));
echo $this->Javascript->link(array('jquery/jquery-1.3.2.min.js','jquery/jquery.validate','admin.js'));?>
</head>
<body>
<div id="upbg"></div>
<div id="outer">
<div id="content">
<?php echo $content_for_layout;?>
</div>
<?php echo $this->element('footer');?>
</div>
</body>
</html>.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Timeless by Free CSS Templates</title>
<!--<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
--> <?php echo $html->css(array('admin.css'));
echo $this->Javascript->link(array('jquery/jquery-1.3.2.min.js','jquery/jquery.validate','admin.js'));?>
</head>
<body>
<div id="upbg"></div>
<div id="outer">
<div id="content">
<?php echo $content_for_layout;?>
</div>
<?php echo $this->element('footer');?>
</div>
</body>
</html>.
And now you can run your web page on any browser by calling cake-php'folder name that you setted before by extracting the cake-php zip file.
No comments:
Post a Comment