【问题标题】:serialization of 'closure not allowed' Error“不允许关闭”错误的序列化
【发布时间】:2015-09-27 13:50:01
【问题描述】:

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

{{ 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,

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

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

【问题讨论】:

    标签: laravel laravel-4


    【解决方案1】:

    除非您发布的代码中存在拼写错误,否则您发布的相关问题的公认解决方案确实与您有关。

    在您的退货单上,您有-&gt;withError($validator),这应该是-&gt;withErrors($validator)(您缺少“s”)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-21
      • 2017-02-14
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 2020-04-06
      相关资源
      最近更新 更多