了解Magento模块的体系结构


Understanding the Architecture of Magento module

我使用PHP Core和自定义MVC工作了一年半,直到转到magento办公桌。

起初我觉得这很难,但后来我掌握了主题集成和维护之前完成的模块。现在我开始创建模块,对体系结构感到非常困惑。

坦率地说,每次当我写一个新代码时,它都能很好地工作,但后来删掉了浪费太多时间的前辈,因为它不完全符合Magento的编码风格。

举个例子,当我需要检查一些东西并更新数据库时,我写道,

<?php 
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = "SELECT ststus FROM table WHERE Id='".$id."'";
$select_query = $readConnection->fetchOne($query);
$update_value= $select_query[0];
if($update_value=='2')
{
$writeConnection = $resource->getConnection('core_write');
$query = "UPDATE table SET field_name='C' WHERE Id='".$id."'";
$writeConnection->query($query);
}
?>

这后来改为简单的

foreach ($dealroomIds as $dealroomId) {
                $manufacturers = Mage::getSingleton('module/module')
                    ->load($dealroomId)
                    ->setStatus($this->getRequest()->getParam('status')); //getting status 
                    if($this->getRequest()->getParam('status')=='2'){
                    $manufacturers->setRunningStatus('C'); // setting new status
                    }
                $manufacturers->setIsMassupdate(true)
                    ->save();
                Mage::getSingleton('dealroom/deals')->UpdateDealProducts($dealroomId); // Update
                    }

上面给出的只是一个例子,仅此而已。

为了了解更多关于编码风格和标准的信息,我认为有必要了解更多关于的信息

  • 控制器
  • 型号
  • Helper
  • 数据

我搜索了一下,但无论我读到什么,理解什么,都离基本的还很远。如果有人简单而基本地指出这些的连接和功能,对我会很有帮助。

你检查过了吗?艾伦·斯托姆的8篇文章涵盖了马根托的大部分内容。

http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-1-introduction-to-magento

如果你觉得很难理解,恐怕你需要首先加强OOP和MVC概念。