2014-12-05 38 views
1

從來就以下查詢:開捕致命錯誤:對象無法被轉換成字符串

ORM::for_table('producto')->where_like('nombre_producto',"%{$valor}%")->find_array(); 

我得到下面的查詢

array (size=1) 
    0 => 
    array (size=11) 
     'id' => string '1' (length=1) 
     'nombre_producto' => string 'Calabacin blanco' (length=16) 
     'nombre_latin' => null 
     'peso' => string '100.00' (length=6) 
     'descatalogado' => string '0' (length=1) 
     'dimensiones' => null 
     'descripcion' => null 
     'cantidad_stock' => string '100' (length=3) 
     'precioVenta' => string '1.00' (length=4) 
     'gama_id' => string '2' (length=1) 
     'proveedor_id' => string '1' (length=1) 

我想顯示定界符的值選擇,我做的:

$optionproducts = function($productos) 
     { 
      $data=""; 
      foreach($productos as $producto) 
      { 
       $data.="<option value='{$producto['id']}'>{$producto['nombre']}</option>"; 
      } 
      return $data; 
     }; 

我的字符串定界符是:

$cadena = <<<EOD 
    <form class='form-horizontal' method='POST' role='form' action={{ urlFor('lineorder_create',{'id':{\$productos['id']}}) }}> 
    <h2>Listado de {$str}</h2> 
    <div class='form-group'> 
     <label class='col-md-4 col-xs-4 control-label' for='selectproductname'>Nombre producto:</label> 
     <div class='col-md-5 col-xs-5'> 
      <select name='selectproductname' class='form-control'> 
       {$optionproducts} 
      </select> 
     </div> 
    </div> 

我得到的是,在第53行中的函數值不能轉換爲字符串

Catchable fatal error: Object of class Closure could not be converted to string in C:\wamp\www\viver\public\products_ajax.php on line 53 

The line 53 in my products_ajax.php is in the heredoc {$optionproducts} 

我怎麼能解決這個錯誤?由於

回答

1

出現這種情況的原因是你的實際呼應你的閉合$optionproducts,它是封閉的

對象,而不是你需要調用它像一個功能$optionproducts($parameter)

$cadena = <<<EOD 
     <form class='form-horizontal' method='POST' role='form' action={{ urlFor('lineorder_create',{'id':{\$productos['id']}}) }}> 
     <h2>Listado de {$str}</h2> 
     <div class='form-group'> 
      <label class='col-md-4 col-xs-4 control-label' for='selectproductname'>Nombre producto:</label> 
      <div class='col-md-5 col-xs-5'> 
       <select name='selectproductname' class='form-control'> 
        <!-- you need to call it --> 
        {$optionproducts($productos)} 
       </select> 
      </div> 
     </div> 
相關問題