質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

解決済

1回答

798閲覧

cakephp signup→activate→login→の順でredirectしたいです。

amaturePy

総合スコア131

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2019/05/25 19:09

題目の通りcakephp signup→activate→login→の順でredirectしたいです。しかし、画面はlogin画面から始まってしまいます。調べるとredirect関数を使うと機能の表示順を指定できるみたいなのですが、その正しい使用方法が分かりません。一応URLも使用してコード内に組み込んではいるのですが、うまく作動していない状態です。
だい
また「 $active = $this->User->field('active', array('username' => $this->data['User']['username']));」に対してUndefined index: User というエラーが出てしまっています。これは他にどのファイル内でUserを定義してあげれば良いのでしょうか??
cakephpにお詳しい方皆ご教授頂けないでしょうか?

<?php App::uses('CakeEmail', 'Network/Email'); class UsersController extends AppController { public function signup() { if ($this->request->is('post')) { if ($this->User->save($this->data)) { $url = 'activate/' . $this->User->id . '/' . $this->User->getActivationHash(); $url = Router::url($url, true); //sending Email $email = new CakeEmail(); $email->from(array('sender@domain.com' => 'Sender')); $email->to($this->data['Users']['email']); $email->subject('User activiation'); $email->send($url); // メール本文に本登録用リンクを記す $this->Session->setFlash('sent for activiation'); } else { $this->Session->setFlash('error'); } } } public function activate($user_id = null, $in_hash = null) { $this->User->id = $user_id; if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) { $this->User->saveField('active', 1); $this->Session->setFlash('Your user account could be activated'); } else { $this->Session->setFlash('Invalid link'); } } // ログイン public function login() { if ($this->request->is('post')) { if ($this->Auth->login()) { $this->User->id = $this->Auth->user('id'); $this->User->saveField('logins', $this->Auth->user('logins') + 1); //通算ログイン回数 $this->User->saveField('lastlogin', date('Y-m-d H:i:s')); //最終ログイン日時 return $this->redirect($this->Auth->redirect()); } else { $active = $this->User->field('active', array('username' => $this->data['User']['username'])); if ($active === 0) { $this->Session->setFlash('Plesdr activate your account'); } else { $this->Session->setFlash('Your username or password is wrong'); } } } } public function logout() { $this->Session->setFlash('Loggedout'); return $this->redirect($this->Auth->logout()); } public function dashboard() { } public function beforeFilter() { parent::beforeFilter(); $this->Auth->allow(array('signup', 'activate', 'login')); } public function password() { $id = $this->Auth->user('id'); $this->User->id = $id; if (!$this->User->exists()) { throw new NotFoundException('Invalid user'); } if ($this->request->is('post') || $this->request->is('put')) { debug($this->request->data); if ($this->User->save($this->request->data)) { $this->Session->setFlash('your passworf is updated'); $this->redirect(array('action' => 'dashboard')); } else { $this->Session->setFlash('Your password could not be updated'); } } $this->request->data = $this->User->read(null, $id); } } ?> コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

Routes.phpに以下のように設定。

Router::connect('/', array('controller' => 'Pages', 'action' => 'home')); Router::connect('/signup', array('controller' => 'Users', 'action' => 'signup')); Router::connect('/login', array('controller' => 'Users', 'action' => 'login')); Router::connect('/profile', array('controller' => 'Users', 'action' => 'profile')); Router::connect('/search', array('controller' => 'Follows', 'action' => 'search')); Router::connect('/logout', array('controller' => 'Users', 'action' => 'logout')); コード

投稿2019/06/07 01:25

amaturePy

総合スコア131

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問