Skip to content

Instantly share code, notes, and snippets.

View cakephp-tutorial's full-sized avatar

CakePHP Italia Tutorial cakephp-tutorial

View GitHub Profile
<?php
#/app/controller/BooksController.php
class BooksController extends AppController {
public function index()
{
$this->Book->recursive = 1;
$books = $this->Book->find('all');
$this->set('authors', $authors);
}
<?php
#/app/controller/AuthorsController.php
class AuthorsController extends AppController {
public function index()
{
$this->Author->recursive = 1;
$authors = $this->Author->find('all');
$this->set('authors', $authors);
}
<?php
#/app/controller/AuthorsController.php
class AuthorsController extends AppController{
public $scaffold; //attiviamo lo scaffold per poter procedere al CRUD di cakephp
}
#/app/controller/BooksController.php
class BooksController extends AppController{
public $scaffold; //attiviamo lo scaffold per poter procedere al CRUD di cakephp
}
<?php
# /app/Model/Contact.php
class Contact extends AppModel {
public $displayField = 'fullname';
public $virtualFields = array(
'fullname' => 'CONCAT(Contact.name, " ", Contact.surname)',
'withCompany' => 'CONCAT(Contact.name, " ", Contact.surname, " - ", Contact.company',
'bySurname' => 'CONCAT(Contact.surname, " ", Contact.name)',
'createdIta' => 'DATE_FORMAT(Contact.created,"%d/%m/%Y")'
);
<?php
# /app/Model/Contact.php
class Contact extends AppModel {
public $displayField = 'fullname';
public $virtualFields = array(
'fullname' => 'CONCAT(Contact.name, " ", Contact.surname)',
'withCompany' => 'CONCAT(Contact.name, " ", Contact.surname, " - ", Contact.company',
'bySurname' => 'CONCAT(Contact.surname, " ", Contact.name)',
);
public function getUserInfos($id) {
<?php
# /app/Model/Contact.php
class Contact extends AppModel {
public $displayField = 'fullname';
public $virtualFields = array(
'fullname' => 'CONCAT(Contact.name, " ", Contact.surname)',
'withCompany' => 'CONCAT(Contact.name, " ", Contact.surname, " - ", Contact.company',
'bySurname' => 'CONCAT(Contact.surname, " ", Contact.name)',
);
}
<?php
# /app/Model/Contact.php
class Contact extends AppModel {
public $displayField = 'fullname';
public $virtualFields = array(
'fullname' => 'CONCAT(Contact.name, " ", Contact.surname)'
);
}
CREATE TABLE `contacts` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(150) DEFAULT NULL,
`surname` varchar(150) DEFAULT NULL,
`company` varchar(200) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
<?php
# app/Model/AppModel.php
class AppModel extends Model {
public function save($data = null, $validate = true, $fieldList = array()) {
$this->set($data);
// se esiste il campo modified verrà rimosso dall'array
if (isset($this->data[$this->alias]['modified'])) {
unset($this->data[$this->alias]['modified']);
}
return parent::save($this->data, $validate, $fieldList);
CREATE TABLE `contacts` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(150) NOT NULL,
`surname` VARCHAR(150) DEFAULT NULL,
`company` VARCHAR(200) DEFAULT NULL,
`created` DATETIME DEFAULT NULL,
`modified` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;