FuelPHP・ユーザー管理3:ユーザーを登録可能にする

2014/07/27

FuelPHPでユーザー管理をやりたい3。ユーザー登録するフォームを用意する。

流れ

コントローラ、ビューファイルを設定して、実際に登録できるかをチェックする。

コントローラに記述

▼「fuel/app/classes/controller/sample1.php」

<?php
use \Auth;

class Controller_Sample1 extends Controller {
  public function action_add_user() {
    // viewを準備
    $view = View::forge(‘sample1/add_user’);
    
    if ($_POST) {
      //POSTデータを受け取る
      $username = Input::post(‘username’);
      $password = Input::post(‘password’);
      $email = Input::post(‘email’);
      
      // Authのインスタンス化
      $auth = Auth::instance();
      
      //ユーザー登録
      $auth->create_user($username, $password, $email);
    }
    
    // 登録フォームの表示
    return $view;
  }
}

ビューの作成:ユーザー登録画面

▼「fuel/app/views/sample1/add_user.php」

<!DOCTYPE HTML>
<html>
<head>
  <meta charset=”utf-8″>
  <title>ユーザー登録</title>
</head>
<body>
  <form name=”form1″ method=”post” action=””>
    <table width=”100%” border=”1″>
      <tr>
        <th colspan=”2″ scope=”row”>ユーザー登録</th>
      </tr>
      <tr>
        <th scope=”row”>ユーザー名</th>
        <td><label for=”username”></label>
        <input name=”username” type=”text” id=”username”></td>
      </tr>
      <tr>
        <th scope=”row”>Eメール</th>
        <td><label for=”email”></label>
        <input type=”text” name=”email” id=”email”></td>
      </tr>
      <tr>
        <th scope=”row”>パスワード</th>
        <td><label for=”password”></label>
        <input type=”password” name=”password” id=”password”></td>
      </tr>
      <tr>
        <th colspan=”2″ scope=”row”><input type=”submit” name=”button” id=”button” value=”登録”></th>
      </tr>
    </table>
  </form>
</body>
</html>

試しに登録する

「http://○○○/sample1/add_user」でアクセスして登録する。

登録できたか確認

登録したらDBのテーブルから登録されたかチェックする。

「FuelPHPでユーザー管理」の一覧

新着(ニュース関連以外)

2018-07-26
年賀状で「新春」とか書くけど・・・何故なんだろうと8月を目前にした今、疑問に思った。
2018-05-16
PHPで画像のヘッダ情報(?)の「Orientation」を元に画像回転させたい。
2018-03-05
Android Studioをインストール。エミュレータを軽くするトコまで終わらせたかったけど、挫折した。
2018-02-23
プッシュ通知について調べてた時にでてきたServiceWorker。そのServiceWorkerについてのメモ。
2017-12-13
jqueryで取得したDOM要素をオブジェクトじゃなくて、配列で受け取りたい