login.ctp
<div class="users form"> <?php echo $this->Form->create('User'); ?> <fieldset> <legend><?php echo ('名前とパスワードを入力してください'); ?></legend> <?php echo $this->Form->input('User.username'); echo $this->Form->input('User.password'); ?> </fieldset> <?php echo $this->Form->end('ログイン'); ?> </div>
UsersController.php
public function index(){ $this->layout = 'common'; $user_info = $this->Auth->user(); $this->set('user',$user_info); } public function login(){ if($this->request->is('post')){ if($debug = $this->Auth->login()){ $this->redirect('/users/index'); }else{ $this->Session->setFlash('パスワードか名前が違います'); } } }
User.php
<?php App::uses('AppModel','Model'); App::uses('BlowfishPasswordHasher','Controller/Component/Auth'); class User extends AppModel{ public $hasMany = array( 'Todo' => array( 'className' => 'Todo', 'foreignKey' => 'user_id' ), 'Following' => array( 'className' => 'Userstouser', 'foreignKey'=>'user_id', ), 'Send' => array( 'className' => 'Comment', 'foreignKey' => 'user_id', ), 'Get' => array( 'className' => 'Comment', 'foreignKey' => 'getter_id', ), ); public $hasOne = array( 'Profile'=> array( 'className' => 'Profile', 'foreignKey'=>'user_id' )); /* public $belongsTo = array( 'Followed' => array( 'className' => 'Userstouser', 'foreignKey'=> 'followedid', ), ); */ public $validate = Array( 'username' => Array( 'required' => Array( 'rule' => Array('notEmpty'), 'message' => '名前を入力してください。' ), 'unique' => array( 'rule' => array('isUnique'), 'message' => 'その名前はすでに使われています' ) ), 'password' => Array( 'required' => Array( 'rule' => Array('notEmpty'), 'message' => 'パスワードを入力してください。' ) ) ); public function beforeSave($option = Array()) { if (isset($this->data[$this->alias]['password'])) { $hasher = new BlowfishPasswordHasher(); $this->data[$this->alias]['password'] = $hasher->hash(($this->data[$this->alias]['password'])); } return true; } }
このようにコーディングしたのですが、localhost(xampp)ではログインできてもさくらレンタルサーバーではloginアクションにはアクセスできますが、ログインには失敗してしまいます。
また、$this->Auth->allow()でindexも許可してみると普通にindexアクションにはアクセスできたので、たぶんauthのログインに失敗していると思ったのですがどうでしょうか。
さくらサーバーでは
/home/アカウント名/www/cake/app
というようにcoreもなにもかもとりあえずドキュメントルートにおいています。
少しでも原因の可能性が思いあたる方、回答お願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。