This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Configure::write('Cache.check', true); | |
/*ACTIVE CACHE FOR QUERIES*/ | |
Cache::config('short', array( | |
'engine' => 'File', | |
'duration'=> '+100 minutes', | |
'probability'=> 100, | |
'path' => CACHE.'data'.DS, | |
'prefix' => 'cache_short_' | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$resultset = $ModelName->find('all', array( | |
'recursive' => '1', | |
'contain' => 'Model', | |
'fields' => array( | |
'Model.field', | |
'OtherModel.field', | |
), | |
'conditions' => array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function find($type = 'first', $params = array(),$cacheParams = array()){ | |
$doQuery =true; | |
if( isset($cacheParams['cache']) && !empty($cacheParams['cache'])){ | |
$cacheConfig = null; | |
if(isset($cacheParams['cacheConfig']) && !empty($cacheParams['cacheConfig'])){ | |
$cacheConfig = $cacheParams['cacheConfig']; | |
} | |
$cacheName = $this->name.'-'.$cacheParams['cache']; | |
$data = Cache::read($cacheName,$cacheConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- /app/View/Orders/add.ctp --> | |
<?php | |
echo $this->Form->create('Order'); | |
echo $this->Form->input('company'); | |
echo $this->Form->input('email'); | |
echo $this->Form->input('Order.Region', array('multiple' => 'checkbox')); | |
echo $this->Form->end('crea'); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# /app/Controller/OrdersController.php | |
class OrdersController extends AppController { | |
public function add() { | |
if ($this->request->is(array('post', 'put')) { | |
$this->Order->create(); | |
if ($this->Order->saveAll($this->request->data, array('deep' => true)) { | |
$this->Session->setFlash('Ordine creato con successo'); | |
//$this->redirect(array('action' => 'view', $this->Order->id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# /app/Model/Order.php | |
class Order extends AppModel { | |
public $hasAndBelongsToMany = array('Region'); | |
public $validate = array( | |
'company' => array( | |
'rule' => array('notEmpty'), | |
'required' => true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#/app/Model/Region.php | |
class Region extends AppModel { | |
public $displayField = 'region'; | |
public $hasAndBelongsToMany = array('Order'); | |
public $validate = array( | |
'region' => array( | |
'rule' => array('notEmpty'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `regions` ( | |
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, | |
`region` VARCHAR(150) NOT NULL, | |
`created` DATETIME DEFAULT NULL, | |
`modified` DATETIME DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=INNODB DEFAULT CHARSET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `orders_regions` ( | |
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, | |
`order_id` INT(11) UNSIGNED NOT NULL | |
`region_id` INT(11) UNSIGNED NOT NULL | |
PRIMARY KEY (`id`) | |
) ENGINE=INNODB DEFAULT CHARSET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `orders` ( | |
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, | |
`company` VARCHAR(150) NOT NULL, | |
`email` VARCHAR(150) DEFAULT NULL, | |
`created` DATETIME DEFAULT NULL, | |
`modified` DATETIME DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=INNODB DEFAULT CHARSET=utf8; |