Reputation: 193
I´ve the following query:
ORM::for_table('producto')->where_like('nombre_producto',"%{$valor}%")->find_array();
I get the following query
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)
I want to show a heredoc the value of a select, I do:
$optionproducts = function($productos)
{
$data="";
foreach($productos as $producto)
{
$data.="<option value='{$producto['id']}'>{$producto['nombre']}</option>";
}
return $data;
};
My string heredoc is:
$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>
The error I get is, in the line 53 the value in the function cannot be converted to string
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}
How I could solved this? Thanks
Upvotes: 1
Views: 978
Reputation: 1764
The reason this is happening is that your actually echoing your closure $optionproducts
and it's an
object of closure, instead you need to call it like a function $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>
Upvotes: 1