Di Magento 2, $thisvariabel tidak lagi merujuk ke objek blok template. Ini merujuk ke kelas templat
Magento\Framework\View\TemplateEngine\Php
Namun, kelas templat ini memiliki __callmetode passthrough
#File: vendor/magento/framework/View/TemplateEngine/Php.php
public function __call($method, $args)
{
return call_user_func_array([$this->_currentBlock, $method], $args);
}
Yang memastikan setiap panggilan metode berhasil masuk ke blok sebenarnya. Ini juga menjelaskan mengapa Anda tidak dapat memanggil metode yang dilindungi dari phtmltemplate.
Selain itu, setiap templat (saya pikir?) Memiliki variabel bernama $blockpopulated, yang juga merujuk ke objek induk blok. Anda dapat melihat ini digunakan dalam template daftar Magento
#File: vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
//...
$_productCollection = $block->getLoadedProductCollection();
di mana $blockvariabel digunakan, tetapi tidak pernah didefinisikan secara eksplisit.
Selain perbedaan yang disebutkan di atas, apakah ada perbedaan antara menggunakan satu teknik di atas yang lain? yaitu Melakukan keduanya $blockdan $this->currentBlockmerujuk ke objek yang sama?