前端之家收集整理的这篇文章主要介绍了
Magento开发文档(四)Magento 布局、块 、模板,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
刚入门magento的开发者容易吧布局和视图给混淆. 本文将看看Magento的Layout/Block的做法,并告诉您如何将其融入Magento的MVC的世界观。
与许多流行的MVC系统相比,Magento的执行控制器不通过数据对象到视图或在视图对象中设置属性(只有少数例外)。相反,视图组件直接引用系统模型来获得它需要显示的信息。
这样的设计决策的后果之一是,视图分成块和模板。块是PHP对象,模板是包含HTML和PHP(在这里PHP作为模板语言)“原始”的PHP文件(带.phtml扩展名)的组合。每一个块都和一个唯一的模板文件绑定。在模板文件 phtml中,“$this”就是指该模板文件对应的块对象。
一个简单的例子
看一个默认的产品模板的文件
|
@H_502_30@
app
/
design
frontend
base
/
default
template
catalog
product
list
.
phtml
|
你会看到下面的PHP模板代码。
|
<?PHP
$_productCollection
=
$this
->
getLoadedProductCollection
(
)
?>
if
(
!
count
)
)
:
?>
<
div
class
=
"note-msg"
>
echo
__
(
"There are no products matching the selection."
?>
<
/
div
>
else
?>
.
.
|
getLoadedProductCollection method方法可以在改模板的Block的class中找到。Mage_Catalog_Block_Product_List找到如图所示
@H_502_30@
File
:
code
core
Mage
Catalog
Block
Product
List
PHP
|