在Laravel

时间:2018-06-19 03:16:22

标签: php

我正在尝试执行简单的注册请求,以允许用户在不传递方法参数的情况下进行注册。

我收到此错误。

  

致命错误:未捕获ArgumentCountError:参数太少   函数ElCont \ UserController :: signup(),0传递,正好为1   预计在   /Applications/MAMP/htdocs/eliapp2/controllers/UserController.php on   第17行

我正在使用此请求库

https://packagist.org/packages/illuminate/http

路线

<?php

define('DS', DIRECTORY_SEPARATOR, true);
define('BASE_PATH', __DIR__ . DS, TRUE);

include __DIR__ . '/vendor/autoload.php';

$app        = System\App::instance();
$app->request   = System\Request::instance();
$app->route = System\Route::instance($app->request);

$route      = $app->route;

$route->get('/', ['ElCont\BaseController', 'getHome']);
$route->get('/dashboard', ['ElCont\BaseController', 'getDashboard']);
$route->post('/register', ['ElCont\UserController', 'signup']);
$route->end();


?>

UserController.php

<?php

namespace ElCont;

use Eli\Db as DB;
use EliModel\User as User;
use Eli\View as View;
use Illuminate\Http\Request;


class UserController{

    private $db;
    private $connect;


    public function signup(Request $request)
    {
        $username = $request['username'];
        $password = password_hash($request['password'], PASSWORD_BCRYPT);
        $muser = new User();
        $muser->username = $username;
        $muser->password = $password;
        $muser->save();
        return $muser;
    }

注册

<?php
require_once 'paritals/header.php';
require_once 'paritals/nav.php';


?>

<div class="container">
    <div class="row">

        <div class="col-md-6 offset-md-4 p-5">

            <h1>Sign Up</h1>
            <form action="/register" method="post">
                <div class="form-group">
                    <label for="exampleInputEmail1">Username</label>
                    <input type="text" name="username" class="form-control" aria-describedby="emailHelp" placeholder="Enter email">

                  </div>
                  <div class="form-group">
                    <label for="exampleInputPassword1">Password</label>
                    <input type="password" class="form-control" name="password" placeholder="Password">
                  </div>
                  <button type="submit" name="submit" class="btn btn-primary">Submit</button>

                </form>

        </div>

    </div>
</div>



<?php require_once  'paritals/footer.php';?>

0 个答案:

没有答案