Một điều tôi thích khi sử dụng $installermà tôi thực sự muốn thêm là nó giúp dễ dàng thay thế nó bằng một thứ khác hoặc chạy nó bên ngoài phạm vi lớp.
1. Thay thế nó:
$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */
// Do basic stuff
$installer = Mage::getSingleton('eav/entity_setup', 'eav_setup');
/* @var $installer Mage_Eav_Model_Entity_Setup */
/// Do stuff with attributes
2. Phạm vi bên ngoài:
$ php -a
php> allow_once 'app / Mage.php';
php> Pháp sư :: init ();
php> yêu cầu 'app / code / local / Vendor / Module / data / pursormodule_setup / data-nâng cấp-0.1.1-0.1.2.php';
Nâng cấp làm việc!
Kết xuất dữ liệu gỡ lỗi: mảng (4) {
'id' =>
int (123)
'foo' =>
chuỗi (3) "thanh"
}
Tất nhiên với data-upgrade-0.1.1-0.1.2.phpviệc có:
//$installer = $this;
$installer = Mage::getResourceSingleton('core/setup', 'vendormodule_setup');
/* @var $installer Mage_Core_Model_Resource_Setup */
// Do lots of stuff ...
echo "Upgrade worked!\n";
echo "Debug data dump: ";
var_dump($debug);
Vì vậy, điều này ngăn chặn Fatal error: Using $this when not in object context