我無法顯示數據。CakePHP模型顯示全部數據null
我的模型(APP /型號/ Product.php)
class Product extends AppModel {
public $name = 'Product';
}
我的控制器(應用程序/控制器/ ProductsController.php):
class ProductsController extends AppController {
public $helpers = array('Html','Form','Session');
public $components = array('Session');
public $name = 'Products';
public function ver($id = null) {
$this->Product->id_producto = $id;
debug($this->Product->id_producto); //Show id with value Ex. 12,34,...
$this->set('products', $this->Product->read());
}
}
我的視圖(app /視圖/版本.ctp):
<?php debug($product['Product']['nombre']); ?> // Show 'null'
<h2><?php echo $product['Product']['nombre']?></h2></td></tr>
<strong>Descripción:</strong> <?php echo $product['Product']['descripcion']?> <br/>
<small>Fecha de registro: <?php echo $product['Product']['fecha_reg']?></small> <br/>
<small>Última modificación: <?php echo $product['Product']['Fecha_mod']?></small>
檢出http://book.cakephp.org/2.0/en/models/retrieving-your-data.html和http://stackoverflow.com/questions/21819451/fetching-and-displaying-data-with -cakephp-2 -x解決方案正如@nedstark所說,你應該使用'find' – cornelb