user1224512
user1224512

Reputation:

cakePHP 2.0.6 - validations

I am using cakePHP 2.0.6 and I am trying to add validation for fields like name, title shoudl not be blank. I placed logic inside model class.

<?php

class Post extends AppModel { public $name = 'Post';

public $validate = array(
    'name' => array(
        'required' => true
    ),
    'title' => array(
        'required' => true
    )
);

}

but somehow it is not working, Can I have some help please?

Thanks

Upvotes: 0

Views: 92

Answers (1)

AMIC MING
AMIC MING

Reputation: 6354

you need to add some more attributes like

<?php
 class Post extends AppModel {

   public $name = 'Post';

   public $validate = array(
     'name' => array(
     'rule' => 'notEmpty',
     'required' => true,
     'message'  => 'Name Should not be blank'
   ),
   'title' => array(
     'rule' => 'notEmpty',
     'required' => true,
     'message'  => 'Title Should not be blank'
   )
  );
}

Please let me know if this isn't work

Upvotes: 1

Related Questions