stp-1
CREATE TABLE IF NOT EXISTS `movies` (
`id` char(36) NOT NULL,
`title` varchar(255) DEFAULT NULL,
`genre` varchar(45) DEFAULT NULL,
`rating` varchar(45) DEFAULT NULL,
`format` varchar(45) DEFAULT NULL,
`length` varchar(45) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
----------------------------------------------------------------------------------------------------------
stp- 2->create controller page under(moviescontroller.php)-> D:\xampp\htdocs\cakephp_lt\app\Controller\moviescontroller.php and paste below code
----------------------------------------------------------------------------------------------------------
<?php
class MoviesController extends AppController {
public $components = array('Session');
public function index()
{
$movies = $this->Movie->find('all');
$this->set('movies', $movies);
}
public function add()
{
if (!empty($this->data)) {
$this->Movie->create($this->data);
if ($this->Movie->save()) {
$this->Session->setFlash('The movie has been saved');
$this->redirect(array('action' => 'add'));
} else {
$this->Session->setFlash
('The movie could not be saved. Please, try again.');
}
}
}
public function delete($id = null)
{
if (!$id) {
$this->Session->setFlash('Invalid id for movie');
$this->redirect(array('action' => 'index'));
}
if ($this->Movie->delete($id)) {
$this->Session->setFlash('Movie deleted');
} else {
$this->Session->setFlash(__('Movie was not deleted',
true));
}
$this->redirect(array('action' => 'index'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash('Invalid movie');
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Movie->save($this->data)) {
$this->Session->setFlash('The movie has been saved');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('The movie could not be saved. Please, try again.');
}
}
if (empty($this->data)) {
$this->data = $this->Movie->read(null, $id);
}
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash('Invalid movie');
$this->redirect(array('action' => 'index'));
}
$this->set('movie', $this->Movie->findById($id));
}
}
?>
-------------------------------------------------------------------------------------------------------------
create view file for show ,add,edit,delete under D:\xampp\htdocs\cakephp_lt\app\View\movies\(add.ctp, edit.ctp,index.ctp,view.ctp)
------------------------------------------------------------------------------------------------------------
add.ctp
------------------------------------
<div class="movies form">
<?php
echo $this->Form->create('Movie');
echo $this->Form->inputs(array('title', 'genre', 'rating', 'format', 'length'));
echo $this->Form->end('Add');
?>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link('List of bikash store', array('action' => 'index'));?></li>
</ul>
</div>
----------------------------------
edit.ctp
--------------------------------
<div class="movies form">
<?php
echo $this->Form->create('Movie');
echo $this->Form->inputs(array('id', 'title', 'genre', 'rating', 'format', 'length'));
echo $this->Form->end('Edit');
?>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link('List Movies',
array('action' => 'index'));?></li>
</ul>
</div>
----------------------------------
index.ctp
--------------------------------
<div class="movies index">
<h2>Movies</h2>
<table cellpadding="0" cellspacing="0">
<tr>
<th>Title</th>
<th>Genre</th>
<th>Rating</th>
<th>Format</th>
<th>Length</th>
<th class="actions">Actions</th>
</tr>
<?php foreach ($movies as $movie): ?>
<tr>
<td><?php echo $movie['Movie']['title']; ?> </td>
<td><?php echo $movie['Movie']['genre']; ?> </td>
<td><?php echo $movie['Movie']['rating']; ?> </td>
<td><?php echo $movie['Movie']['format']; ?> </td>
<td><?php echo $movie['Movie']['length']; ?> </td>
<td class="actions">
<?php echo $this->Html->link('View',
array('action' => 'view', $movie['Movie']['id'])); ?>
<?php echo $this->Html->link('Edit',
array('action' => 'edit', $movie['Movie']['id'])); ?>
<?php echo $this->Html->link('Delete',
array('action' => 'delete', $movie['Movie']['id']),
null, sprintf('Are you sure you want to delete %s?', $movie['Movie']['title'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link('New Movie', array('action' => 'add')); ?></li>
</ul>
</div>
----------------------------------
view.ctp
--------------------------------
<div class="movies view">
<h2>Movie</h2>
<dl>
<dt>Title</dt>
<dd><?php echo $movie['Movie']['title']; ?></dd>
<dt>Genre</dt>
<dd><?php echo $movie['Movie']['genre']; ?></dd>
<dt>Rating</dt>
<dd><?php echo $movie['Movie']['rating']; ?></dd>
<dt>Format</dt>
<dd><?php echo $movie['Movie']['format']; ?></dd>
<dt>Length</dt>
<dd><?php echo $movie['Movie']['length']; ?></dd>
<dt>Created</dt>
<dd><?php echo $movie['Movie']['created']; ?></dd>
<dt>Modified</dt>
<dd><?php echo $movie['Movie']['modified']; ?></dd>
</dl>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link
('Edit Movie', array('action' => 'edit', $movie['Movie']['id'])); ?> </li>
<li><?php echo $this->Html->link
('Delete Movie', array('action' => 'delete', $movie['Movie']['id']),
null, sprintf('Are you sure you want to delete # %s?', $movie['Movie']['id'])); ?> </li>
<li><?php echo $this->Html->link
('List Movies', array('action' => 'index')); ?> </li>
<li><?php echo $this->Html->link
('New Movie', array('action' => 'add')); ?> </li>
</ul>
</div>
----------------------------------------------------------------------
then you can also insert, updata and delete can do but if you want to validation your form fields then you have to create e a model to validatae
-------------------------------------------------------------------------
create model uder->D:\xampp\htdocs\cakephp_lt\app\Model\(movie.php)
------------------------------------------------------------------------------
you can validate for your fields using model paste below these code
----------------------------------------------
<?php
class Movie extends AppModel {
var $name = 'movie';
var $validate =array(
'title' =>array(
'alphaNumeric' =>array(
'rule' => array('minLength',2),
'required' => true,
'message' => 'Enter should be minimum 2 only')
),
'genre' =>array(
'alphaNumeric' =>array(
'rule' => array('minLength',4),
'required' => true,
'message' => 'Enter should be minimum 4 only')
),
'rating' =>array(
'alphaNumeric' =>array(
'rule' => array('minLength',2),
'required' => true,
'message' => 'Enter should be minimum 4 only')
)
);
}
?>
i hope every one can easily understand please:)
CREATE TABLE IF NOT EXISTS `movies` (
`id` char(36) NOT NULL,
`title` varchar(255) DEFAULT NULL,
`genre` varchar(45) DEFAULT NULL,
`rating` varchar(45) DEFAULT NULL,
`format` varchar(45) DEFAULT NULL,
`length` varchar(45) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
----------------------------------------------------------------------------------------------------------
stp- 2->create controller page under(moviescontroller.php)-> D:\xampp\htdocs\cakephp_lt\app\Controller\moviescontroller.php and paste below code
----------------------------------------------------------------------------------------------------------
<?php
class MoviesController extends AppController {
public $components = array('Session');
public function index()
{
$movies = $this->Movie->find('all');
$this->set('movies', $movies);
}
public function add()
{
if (!empty($this->data)) {
$this->Movie->create($this->data);
if ($this->Movie->save()) {
$this->Session->setFlash('The movie has been saved');
$this->redirect(array('action' => 'add'));
} else {
$this->Session->setFlash
('The movie could not be saved. Please, try again.');
}
}
}
public function delete($id = null)
{
if (!$id) {
$this->Session->setFlash('Invalid id for movie');
$this->redirect(array('action' => 'index'));
}
if ($this->Movie->delete($id)) {
$this->Session->setFlash('Movie deleted');
} else {
$this->Session->setFlash(__('Movie was not deleted',
true));
}
$this->redirect(array('action' => 'index'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash('Invalid movie');
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Movie->save($this->data)) {
$this->Session->setFlash('The movie has been saved');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('The movie could not be saved. Please, try again.');
}
}
if (empty($this->data)) {
$this->data = $this->Movie->read(null, $id);
}
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash('Invalid movie');
$this->redirect(array('action' => 'index'));
}
$this->set('movie', $this->Movie->findById($id));
}
}
?>
-------------------------------------------------------------------------------------------------------------
create view file for show ,add,edit,delete under D:\xampp\htdocs\cakephp_lt\app\View\movies\(add.ctp, edit.ctp,index.ctp,view.ctp)
------------------------------------------------------------------------------------------------------------
add.ctp
------------------------------------
<div class="movies form">
<?php
echo $this->Form->create('Movie');
echo $this->Form->inputs(array('title', 'genre', 'rating', 'format', 'length'));
echo $this->Form->end('Add');
?>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link('List of bikash store', array('action' => 'index'));?></li>
</ul>
</div>
----------------------------------
edit.ctp
--------------------------------
<div class="movies form">
<?php
echo $this->Form->create('Movie');
echo $this->Form->inputs(array('id', 'title', 'genre', 'rating', 'format', 'length'));
echo $this->Form->end('Edit');
?>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link('List Movies',
array('action' => 'index'));?></li>
</ul>
</div>
----------------------------------
index.ctp
--------------------------------
<div class="movies index">
<h2>Movies</h2>
<table cellpadding="0" cellspacing="0">
<tr>
<th>Title</th>
<th>Genre</th>
<th>Rating</th>
<th>Format</th>
<th>Length</th>
<th class="actions">Actions</th>
</tr>
<?php foreach ($movies as $movie): ?>
<tr>
<td><?php echo $movie['Movie']['title']; ?> </td>
<td><?php echo $movie['Movie']['genre']; ?> </td>
<td><?php echo $movie['Movie']['rating']; ?> </td>
<td><?php echo $movie['Movie']['format']; ?> </td>
<td><?php echo $movie['Movie']['length']; ?> </td>
<td class="actions">
<?php echo $this->Html->link('View',
array('action' => 'view', $movie['Movie']['id'])); ?>
<?php echo $this->Html->link('Edit',
array('action' => 'edit', $movie['Movie']['id'])); ?>
<?php echo $this->Html->link('Delete',
array('action' => 'delete', $movie['Movie']['id']),
null, sprintf('Are you sure you want to delete %s?', $movie['Movie']['title'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link('New Movie', array('action' => 'add')); ?></li>
</ul>
</div>
----------------------------------
view.ctp
--------------------------------
<div class="movies view">
<h2>Movie</h2>
<dl>
<dt>Title</dt>
<dd><?php echo $movie['Movie']['title']; ?></dd>
<dt>Genre</dt>
<dd><?php echo $movie['Movie']['genre']; ?></dd>
<dt>Rating</dt>
<dd><?php echo $movie['Movie']['rating']; ?></dd>
<dt>Format</dt>
<dd><?php echo $movie['Movie']['format']; ?></dd>
<dt>Length</dt>
<dd><?php echo $movie['Movie']['length']; ?></dd>
<dt>Created</dt>
<dd><?php echo $movie['Movie']['created']; ?></dd>
<dt>Modified</dt>
<dd><?php echo $movie['Movie']['modified']; ?></dd>
</dl>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li><?php echo $this->Html->link
('Edit Movie', array('action' => 'edit', $movie['Movie']['id'])); ?> </li>
<li><?php echo $this->Html->link
('Delete Movie', array('action' => 'delete', $movie['Movie']['id']),
null, sprintf('Are you sure you want to delete # %s?', $movie['Movie']['id'])); ?> </li>
<li><?php echo $this->Html->link
('List Movies', array('action' => 'index')); ?> </li>
<li><?php echo $this->Html->link
('New Movie', array('action' => 'add')); ?> </li>
</ul>
</div>
----------------------------------------------------------------------
then you can also insert, updata and delete can do but if you want to validation your form fields then you have to create e a model to validatae
-------------------------------------------------------------------------
create model uder->D:\xampp\htdocs\cakephp_lt\app\Model\(movie.php)
------------------------------------------------------------------------------
you can validate for your fields using model paste below these code
----------------------------------------------
<?php
class Movie extends AppModel {
var $name = 'movie';
var $validate =array(
'title' =>array(
'alphaNumeric' =>array(
'rule' => array('minLength',2),
'required' => true,
'message' => 'Enter should be minimum 2 only')
),
'genre' =>array(
'alphaNumeric' =>array(
'rule' => array('minLength',4),
'required' => true,
'message' => 'Enter should be minimum 4 only')
),
'rating' =>array(
'alphaNumeric' =>array(
'rule' => array('minLength',2),
'required' => true,
'message' => 'Enter should be minimum 4 only')
)
);
}
?>
i hope every one can easily understand please:)
its really help full thanks for this ...
ReplyDeleteThank for your appreciation, i always here if you have any question related cakephp or other technology you can ask by comment.
ReplyDeletethanks
hi great tutorial
DeleteThanks for comment:)
DeleteHi,
ReplyDeleteI am new in cakephp , this article is very helpful for me. I want to learn more can u help me .
Hi Asis,
ReplyDeleteif you facing any problem i`m available any time through comment.
Thanks again for help full
Thanks
ReplyDeleteits my pleasure.....: to help
ReplyDeleteit's good .....
ReplyDeletehttp://tuxradar.com/content/cakephp-tutorial-build-web-apps-faster
ReplyDeletethis link are totally this code ....
Hi Patel,
ReplyDeleteexactly you can see our post. we are just testing all those programing after it successfully execute. then we could uploaded for help to other beginner.
ya i can see you post it's good and it's really works ..
Deletehttp://tuxradar.com/content/cakephp-tutorial-build-web-apps-faster
ReplyDeletei' m just inform you .. this link are copy of your link
ok Paltel, thanks for your information. we are always resolved the problem.if you have any question you can asked by comment.
ReplyDeletethanks
thanks .
ReplyDeleteI prefer learn from examples rather then digging into docs. However docs are fruitful but you have provide me cheese.thanks again.
hello, thanks for your commenting ...............we always happy, any one helpful from our tutorial ...:)
Deletethanks
ReplyDeleteIts very helpful for me
using this post I can do many other work in cakephp .
It`s my pleasure to help...........:)
DeleteHi, How can I use a different primary key id? especially in update and insert..
ReplyDeleteThank you in adance.
Hi ,
Deleteyou mean you want to pass multiple different query string like
:$movie['Movie']['id'] and other primary key?
Nom in my table I have a different different name than id for example: PERSON_CODE
DeleteI want to create a "create new" and "edit" forms. I have declared it in the modal using
$primarykey= "PERSON_CODE"
but still no use. do you have a solution?
You need to change your primarykey fields according in model ,controller, and presentation page. could you provide your code i can assist to correction
Deletethanxs
ReplyDeleteIts very helpful for me
i have a simple html code that i would oike to ask for help.. pls if anyone here can help me and i will really appreciate your help.
ReplyDeletejust need a simple html code to make a table
that i can search , add edit and delete.. pls
if anyone can help me with a good heart
pls email me at
aaron_mendoza81@yahoo.com
or here
Hi Eiron,
ReplyDeletei really appreciate to help you , you would need to use PHP scripting language for managing these operation .if you send your HTML code to my email id "nayakr.bikash@gmail.com" i can do using PHP langunge for your functionality.
let me know anything you need..... :)
hi sir.. i sent email to you..pls help me with this little project..
Deletei want to learn php and html ..basic only pls...
Ok fine , i will let you know............:)
DeleteUndefined variable: movies [APP/Template\movies\index.ctp, line 12]
ReplyDeletehow can i resolve?
best and very simple tutorial & website
ReplyDeleteThank You!
Deletethanks a loooottttttttttttttt
ReplyDeleteThis is a clear and useful post.we can also try phpcodebuilder for creating crud with our table name and fields dynamically.http://phpcodebuilder.com/crud-generator
ReplyDeletebest and very simple tutorial & website
ReplyDeleteTechnical Action Group