Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- App::uses('AppModel', 'Model');
- /**
- * Guestbook Model
- *
- * @property Comments $comments
- */
- class Guestbook extends AppModel {
- /**
- * Display field
- *
- * @var string
- */
- public $displayField = 'name';
- /**
- * Validation rules
- *
- * @var array
- */
- public $validate = array(
- 'name' => array(
- 'notempty' => array(
- 'rule' => array('notempty'),
- 'message' => 'Veuillez saisir votre nom',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- 'slug' => array(
- ),
- 'content' => array(
- 'notempty' => array(
- 'rule' => array('notempty'),
- 'message' => 'Vous devez saisir un message',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- 'email' => array(
- 'email' => array(
- 'rule' => array('email'),
- 'message' => 'Veuillez saisir un email valide',
- 'allowEmpty' => true,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- 'created' => array(
- 'datetime' => array(
- 'rule' => array('datetime'),
- //'message' => 'Your custom message here',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- 'online' => array(
- 'boolean' => array(
- 'rule' => array('boolean'),
- //'message' => 'Your custom message here',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- 'clientip' => array(
- 'ip' => array(
- 'rule' => array('ip'),
- //'message' => 'Your custom message here',
- 'allowEmpty' => true,
- 'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- ),
- );
- //The Associations below have been created with all possible keys, those that are not needed can be removed
- /**
- * hasMany associations
- *
- * @var array
- */
- public $hasMany = array(
- 'Comments' => array(
- 'className' => 'Comments',
- 'foreignKey' => 'guestbook_id',
- 'dependent' => false,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'exclusive' => '',
- 'finderQuery' => '',
- 'counterQuery' => ''
- )
- );
- public function afterFind($data,$primary = bool){
- foreach($data as $k=>$d){
- if(isset($d['Guestbook']['slug']) && isset($d['Guestbook']['id'])){
- $d['Guestbook']['link'] = array(
- 'controller' => 'guestbooks',
- 'action' => 'show',
- 'id' => $d['Guestbook']['id'],
- 'slug' => $d['Guestbook']['slug']
- );
- }
- $data[$k] = $d;
- }
- return $data;
- }
- public function beforeSave($options = array()){
- if(empty($this->data['Guestbook']['slug']) && !empty($this->data['Guestbook']['name']))
- $this->data['Guestbook']['slug'] = strtolower(Inflector::slug($this->data['Guestbook']['name'],'-'));
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment