何度も投稿すみません。みなさんお疲れ様です。
現在僕は何度もisUniqueがちゃんと聞く方法はないか調べています。
新規のユーザー登録でバリデーションをつかっているのですが、alphaNumericとbetweenは効くくせに
isUniqueはびくともしません。いろいろ試しましたが効きません。憎いです。
現在のAdminUser.phpとAppModel.phpはこんな感じになってます。
どなたか本当にご助言をお願いします。
AdminUser.php
php
1<?php 2App::uses('AuthComponent', 'Controller/Component'); 3 4class AdminUser extends AppModel { 5 6 var $name = 'AdminUser'; 7 8 var $validate = array( 9 'username' => array( 10 'unique' => array( 11 'rule' => array('isUnique'), 12 'message' => '既に使用されている名前です' 13 ), 14 'alphaNumeric' => array( 15 'rule' => array('alphaNumeric'), 16 'message' => '名前は半角英数字にしてください' 17 ), 18 'between2and32' => array( 19 'rule' => array('between', 2, 32), 20 'message' => '名前は2文字以上32文字以内にしてください' 21 ) 22 ), 23 'password' => array( 24 'between2and32' => array( 25 'rule' => array('between', 8, 32), 26 'message' => 'パスワードは8文字以上32文字以内にしてください' 27 ) 28 ) 29 ); 30 31 //パスワードをハッシュ化して保存するために下記を追加 32 public function beforeSave($options = array()) { 33 $this->data['AdminUser']['password'] = AuthComponent::password($this->data['AdminUser']['password']); 34 return true; 35 } 36} 37
AppModel.php
php
1<?php 2/** 3 * Application model for CakePHP. 4 * 5 * This file is application-wide model file. You can put all 6 * application-wide model-related methods here. 7 * 8 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) 9 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) 10 * 11 * Licensed under The MIT License 12 * For full copyright and license information, please see the LICENSE.txt 13 * Redistributions of files must retain the above copyright notice. 14 * 15 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) 16 * @link http://cakephp.org CakePHP(tm) Project 17 * @package app.Model 18 * @since CakePHP(tm) v 0.2.9 19 * @license http://www.opensource.org/licenses/mit-license.php MIT License 20 */ 21 22App::uses('Model', 'Model'); 23 24/** 25 * Application model for Cake. 26 * 27 * Add your application-wide methods in the class below, your models 28 * will inherit them. 29 * 30 * @package app.Model 31 */ 32class AppModel extends Model { 33 function __construct($id = false, $table = null, $ds = null) { 34 $cake_env = Configure::read('cake_env'); 35 if (empty($cake_env)) { 36 $this->useDbConfig = 'default'; 37 } else { 38 $this->useDbConfig = $cake_env; 39 } 40 parent::__construct($id, $table, $ds); 41 } 42 43 public function alphaNumeric($check) { 44 $value = array_values($check); 45 $value = $value[0]; 46 return preg_match('/^[a-zA-Z0-9]+$/', $value); 47 } 48 49} 50
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/08/04 10:58 編集
2015/08/04 11:03
2015/08/04 11:04
2015/08/17 01:24 編集