0
여기 ContactsController.phpCakePHP의 2 유효성 검사 오류 메시지가 표시되지 않습니다
App::uses('AppController', 'Controller');
App::uses('Validation', 'Utility');
class ContactsController extends AppController {
public $helpers = array('Form', 'Html', 'Session', 'Js', 'Time');
public $uses = array('Contacts');
/**
* This controller does not use a model
*
* @var array
*/
//public $uses = array();
//public $uses = array('Contact');
//use Cake\Validation\Validator;
/**
* Displays a view
*
* @return void
* @throws NotFoundException When the view file could not be found
* or MissingViewException in debug mode.
*/
public function index() {
$this->Contacts->set($this->request->data);
if($this->request->is('post')) {
//if ($this->Contact->validation()) {
if ($this->Contacts->validates()) {
// return
$this->Contacts->save();
$this->redirect('/contacts/confirm');
} else {
CakeLog::write('debug', 'ErrorCheck');
// $errors = $this->Contacts->validationErrors;
//$this->Session->setflash($this->Contacts->validationErrors);
//$this->redirect('/contacts');
//CakeLog::write('debug', $errors['ContactsAddress'][0]);
// Debugger::dump($errors);
}
}
}
보기 파일 index.ctp Contacts.php
<?php
App::uses('AppModel', 'Model');
App::uses('Validation', 'Utility');
/**
* Base Application model
*
* @package Croogo
* @link http://www.croogo.org
*/
//$validate = new Validator();
// 'alphaNumeric' => array(
// 'required' => true,
// 'allowEmpty' => false,
class Contacts extends AppModel {
var $name = 'Contacts';
var $useTable = false;
var $validate = array(
'ContactsAddress' => array(
'rule' => 'notEmpty',
'required' => true,
'message' => 'The address is required'),
'ContactsEmail' => array(
'rule' => array('email', true),
'required' => true,
'message' => 'A valid email is required'
),
'ContactsPhone' => array(
'rule' => array('phone', null, 'us'),
'message' => 'A valid phone numbe is required'
)
);
//}
}
내 모델 입니다
<!--Navigation Background Part Starts -->
<div id="navigation-bg">
<!--Navigation Part Starts -->
<div id="navigation">
<ul class="mainMenu">
<li><a href="/" title="Home">Home</a></li>
<li><a href="about" title="About">About</a></li>
<li class="noBg"><a href="contact" class="selectMenu" title="Contact">Contact</a></li>
</ul>
<a href="contact" class="signup" title="APPOINTMENT"></a>
<br class="spacer" />
</div>
<!--Navigation Part Ends -->
</div>
<div id="ourCompany-bg">
<div class="requestForm">
<p class="formHeader">Meeting Location</p>
<?php echo $this->Form->create(false); ?>
<!--, array('url' => false)-->
<!-- array('action' => 'confirm'))); ?> -->
<?php //echo $this->Form->create(false, array('url' => array('action' => 'index'))); ?>
<?php $today = date('d')+1; ?>
<?php $formmonth = date('m'); ?>
<?php echo $this->Form->input('name', array(
'label' => array('text' => 'Name: '))); ?>
<span class="errorMessage"> <?php //echo $this->validationErrors['Contacts']['ContactsAddress'][0];?></span>
<?php echo $this->Form->input('address', array(
'label' => array('text' => 'Address of meeting: '))); ?>
<?php CakeLog::write('debug', $this->validationErrors['Contacts']['ContactsAddress'][0]); ?>
당신이 볼 수 있듯이 나는 많은 다른 것들을 시도해 왔습니다. 나는 아무런 진전없이 2 주 동안 이것을 알아 내려고 노력해왔다.
나는 누군가가 내 delimma 서식 -의 첫 번째 속성으로 모델 이름을 가진> 생성되는 가장 중요한 요인