Recent Post

All Pages

Like Us On Facebook

About

Gallery

Thứ Bảy, 23 tháng 8, 2014

Model - Tổng quan về Model class trong Mgento



Tất cả model kế thừa Varien-Object từ Zend Framework
$model -> getData() ; // array
$model ->getWhat => $setWhat
$model->setMethod1->setMethod2

Lấy Data từ Model:

- Tổng quát:
$collections = Mage::getModel('catalog/product') // khởi tạo model Mage_Catalog_Model_Product
->getCollection() // lấy tất cả dữ liệu trong model
->addAttributeToSelect(array('name', 'price')) // lọc dữ liệu theo thuộc tính Attribute (cột)
->addAttributeToFilter('price', array('eq' => 10.00)) // lọc dữ liệu theo giá trị thuộc tính (row)
->load(); // nạp data cần lấy



Giai thích: The below code, in this case is a product collection, we call addAttributeToSelect() to select only “name” and “price” attributes for all products. Then we call addAttributeToFilter() to filter so only products with the price of 10.00 will be selected from the database. Again, even though catalog/product is using EAV model, it’s ok to use addFieldToFilter() if you want to.
Đọc thêm => các cách Filter dữ liệu addAttributeToFilter

- Ví dụ cụ thể 1:
$collections = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect(array('name', 'price'))
->addAttributeToFilter(
array(
'attribute' => 'name',
'eq' => 'Somename',
),
array(
'attribute' => 'price',
'eq' => 10.00,
),
));
->load();

Email Newsletter



Smiley :)
:D
:)
:[
;)
:D
:O
(6)
(A)
:'(
:|
:o)
8)
(K)
(M)

Không có nhận xét nào:

Đăng nhận xét

Biểu mẫu liên hệ

Tên

Email *

Thông báo *