2014-09-10 91 views
1

我刚刚下载并使用最新的Laravel 4.2启动了一个新项目。当试图提交表单我得到以下错误:BadMethodCallException方法[店]不存在Laravel:BadMethodCallException方法[store]不存在

这里是我的文件:控制器 - 管理员/ AdminController

<?php 
    namespace admin; 

    use Illuminate\Support\Facades\View; 
    use App\Services\Validators\ArticleValidator; 
    use Input, Notification, Redirect, Sentry, Str; 

    class AdminController extends \BaseController { 

     public function index() { 

      if (Input::has('Login')) { 

       $rules = array(
        'email' => 'required', 
        'password' => 'required|min:3', 
        'email' => 'required|email|unique:users' 
      ); 

       $validator = Validator::make(Input::all(), $rules); 

       if ($validator->fails()) { 
        return Redirect::to('admin\AdminController')->withErrors($validator); 

       } else { 

        // redirect 
        Session::flash('message', 'Successfully created user!'); 
        return Redirect::to('admin\AdminController'); 
       } 
      } 
      $data['title'] = ADMIN; 
      return View::make('admin.index', $data); 
     } 
    } 

查看网页 - 管理员/ index.blade。 PHP

<div class="container"> 
     {{ Form::open(array('url' => ADMIN,'id' => 'login')) }} 

      <div id="icdev-login-wrap"> 


      <div class="raw align-center logoadmin">{{ HTML::image('images/logo.png') }}</div> 
      <div id="icdev-login"> 
      <h3>Welcome, Please Login</h3> 




       <div class="mar2_bttm input-group-lg"><input type="text" class="form-control loginput" placeholder="Email" name="email"></div> 

       <div class="mar2_bttm input-group-lg"><input type="password" class="form-control loginput" placeholder="Password" name="password"></div> 
       <div ><input type="submit" class="btn btn-default btn-lg btn-block cus-log-in" value="Login" /></div> 
       <div class="row align-center forgotfix"> 

        <input type="hidden" name="Login" value="1"> 
       </div> 
       </div> 
       <div> 

       </div> 
      </div> 
      {{ Form::close() }} 
      </div> 
+1

您正在将数据发布到不存在的函数store。要么创建函数,要么改变你的路由,以寻找POST请求应该去的地方。 – Dan 2014-09-10 13:41:20

回答

2

错误消息告诉你的问题是什么:所谓store()的方法不存在。将它添加到你的控制器:

<?php 
namespace admin; 

use Illuminate\Support\Facades\View; 
use App\Services\Validators\ArticleValidator; 
use Input, Notification, Redirect, Sentry, Str; 

class AdminController extends \BaseController { 

    public function index() 
    { 
     // leave code as is 
    } 

    public function store() 
    { 
     // this is your NEW store method 
     // put logic here to save the record to the database 
    } 

} 

几个要点:

  • 使用骆驼外壳的名字空间(即namespace admin应该namespace Admin
  • 阅读Laravel文档资源控制器:http://laravel.com/docs/controllers#resource-controllers
  • 您也可以使用Artisan命令自动生成资源控制器。运行$ php artisan make:controller ItemController,用控制器的名称替换ItemController,即ArticleControllerUserController
+0

它的工作......谢谢..但验证不工作,它显示验证未找到。在哪里我把验证,在索引方法或存储方法? – Meera 2014-09-10 16:51:20

+0

正如你命名空间你的控制器,如果你使用'验证器'它会看你的'管理'命名空间,但显然它不会找到它。你需要像'Input','Redirect','Str'等一样导入'Validator'。 – 2014-09-10 17:11:24