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

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

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

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

Q&A

解決済

1回答

236閲覧

cakephpでの関数の起動順序

amaturePy

総合スコア131

CakePHP

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

0グッド

0クリップ

投稿2019/05/25 13:44

cakephpに関して質問させて下さい。
cakephpでユーザーの登録フォーム→確認メールの送信→本当登録→ログインという流れで動かしたいのですが、

Error: Cannot declare class UsersController, because the name is already in use
File: /Applications/MAMP/htdocs/cakephp/app/Model/AppModel.php
Line: 38
というエラーが消えずに止まっています。
これは AppModel.phpとどのファイルの関数の名前が被っているからエラーが出ているのでしょうか??
また、
38行目の該当箇所が以下のコードなのですが、自分のコードで大変恐縮なのですが、こちらのコードの意味なども
お教え頂けると幸いです。
初めてcakeを使うは良いものの、途中で混乱してしまいました。

class UsersController extends AppController { public $helpers = array('Html', 'Form'); public function index() { $this->set('Posts', $this->Post->find('all')); } } コード

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

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

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

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

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

guest

回答1

0

自己解決

<?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); } } ?> コード

投稿2019/05/25 18:54

amaturePy

総合スコア131

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問