This site uses cookies from Google to deliver its services, to personalize ads and to analyze traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. Learn More

Cakephp Making A Small Application

Cakephp Making A Small Application Web-development (jquery) Cakephp Making A Small Application

CakePHP Making a small application
CakePHP Making a small application

Create Database Table

CREATETABLE`categories` (
`id` INTEGER(11) NOTNULLAUTO_INCREMENT,
`name` VARCHAR(255) NOTNULL,
PRIMARYKEY(`id`)
) ENGINE=MyISAM
Create Model app\models\category.php


<?php class Category extends AppModel { var $name = 'Category'; } ?> 
Create Controller app\controllers\categories_controller.php
<?php class CategoriesController extends AppController { var $name = 'Categories'; function index() { $this->set('categories', $this->Category->find('all')); } function add() { if (!empty($this->data)) { if ($this->Category->save($this->data)) { $this->Session->setFlash('Your category has been saved.'); $this->redirect(array('action' => 'index')); } } } } ?> 
Create View index app\views\categories\index.ctp
<!-- File: /app/views/categories/index.ctp --> <?php echo $html->link('Add Category',array('controller' => 'categories', 'action' => 'add')); ?> <h1>Categories</h1> <table> <tr> <th>Id</th> <th>Title</th> </tr> <?php foreach ($categories as $category): ?> <tr> <td><?php echo $category['Category']['id']; ?></td> <td> <?php echo $html->link($category['Category']['name'], array('controller' => 'categories', 'action' => 'view', $category['Category']['id'])); ?> </td> </tr> <?php endforeach; ?> </table> 
Create View add app\views\categories\add.ctp
<!-- File: /app/views/categories/add.ctp --> <h1>Add Category</h1> <?php echo $form->create('Category'); echo $form->input('name'); echo $form->end('Save Post'); ?> 

0 Response to "Cakephp Making A Small Application"

Posting Komentar

Contact

Nama

Email *

Pesan *