代码之家  ›  专栏  ›  技术社区  ›  Alexander Solonik

“不允许关闭”的序列化错误

  •  0
  • Alexander Solonik  · 技术社区  · 10 年前

    以下是我的产品视图中的代码:

    {{ Form::open(array('url'=>'admin/products/create' , 'files'=>true)) }}
              <p>
                {{ Form::label('category_id' , 'Category') }}
                {{ Form::select('category_id' , $categories) }}
              </p>
              <p>
                {{ Form::label('title') }}
                {{ Form::text('title') }}
              </p>
              <p>
                {{ Form::label('description') }}
                {{ Form::textarea('description') }}
              </p>
              <p>
                {{ Form::label('height') }}
                {{ Form::text('height' , null , array('class'=>'form-price')) }}
              </p>
              <p>
                  {{ Form::label('width') }}
                  {{ Form::text('width' , null , array('class'=>'form-price')) }}
                <!--{{ Form::label('image' , 'Choose an image') }}
                {{ Form::file('image') }}-->
              </p>
               <p>
                    {{ Form::label('length') }}
                    {{ Form::text('length' , null , array('class'=>'form-price')) }}
               </p>
                <p>
                    {{ Form::label('color') }}
                    {{ Form::text('color' , null , array('class'=>'form-price')) }}
                </p>
                <p>
                    {{ Form::label('material') }}
                    {{ Form::text('material' , null , array('class'=>'form-price')) }}
                </p>
              {{ Form::submit('Create Product' , array('class'=>'secondary-cart-btn')) }}
              {{ Form::close() }}
    

    下面是我的产品控制器的代码:

    <?php
    
    /**
     *
     */
    class ProductsController extends BaseController {
    
      public function __construct() {
        $this->beforeFilter('csrf' , array('on'=>'post'));
      }
    
      public function getIndex() {
    
    
        /* NOTE :: the categories array is being
        created so that the products index page
        can have access to all the availability
        categories */
    
         $categories = array();
    
         foreach (Category::all() as $category) {
            $categories[$category->id] = $category->name;
         }
    
          return View::make('products.index')
            ->with('products' , Product::all())
            ->with('categories' , $categories);
    
      }
    
      public function postCreate() {
    
        $validator = Validator::make(Input::all() , Product::$rules);
    
        if($validator->passes()) {
          $product = new Product;
    
          $product->category_id = Input::get('category_id');
          $product->title = Input::get('title');
          $product->description = Input::get('description');
          $product->height = Input::get('height');
          $product->width = Input::get('width');
          $product->length = Input::get('length');
          $product->color = Input::get('color');
          $product->material = Input::get('material');
    
    
          /* code for saving the image */
         /* $image = Input::file('image');
          $filename = date('Y-m-d-H-i-s')."-".$image->getClientOriginalName();
          $path = public_path('img/products/' .$filename);
          Image::make($image->getRealPath())->resize(468, 249)->save($path);
          $product->image = 'img/products/'.$filename; */
          /*end of code for saving the image */
    
          $product->save();
    
          return Redirect::to('admin/products/index')
             ->with('message' , 'Product created');
        }
    
        return Redirect::to('admin/products/index')
          ->with('message' , 'something went wrong')
          ->withError($validator)
          ->withInput();
      }
    
      public function postDestroy() {
    
          $product = Product::find(Input::get('id'));
          if ($product) {
            $product->delete();
            return Redirect::to('admin/products/index')
            ->with('message' , 'product has been deleted');
          }
    
          return Redirect::to('admin/products/index')
            ->with('message' , 'something went wrong , Please try again');
      }
    }
    ?>
    

    现在,当我填写表单中的值并单击提交时,我会收到如下错误:

    Error image

    “closure not allowed”的序列化,在谷歌上搜索一下我发现了以下有用的线程:

    Related thread ,

    接受的解决方案不适用于我,我在第二个答案中尝试了解决方案,但仍然存在相同的错误。

    我仍然不明白这个错误的原因是什么,或者我做错了什么?有人能解释一下吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   patricus    10 年前

    除非你发布的代码中有错别字,否则你发布的相关问题的公认解决方案与你有关。

    在你的报税表上,你有 ->withError($validator) ,这应该是 ->withErrors($validator) (你错过了“s”)。