마 젠토 블록 및 블록 유형 이해
나는 단지의 의미를 이해하고 싶다.
<block type="page/html" name="root" output="toHtml" template="example/view.phtml">
Google에서 많은 참조를 받고 그것에 대해 많은 것을 이해했지만 여전히 type="page/html"
내 사용자 정의 모듈에 대한 유형을 형성하는 방법을 이해할 수 없습니다 .
설명 해주십시오
type="A/B"
이 A와 B의 출처를 알려주세요.
는 A
모듈의입니다 별칭 . 이 경우 page
는 약자입니다 Mage_Page_Block
( app/code/core/Mage/Page/etc/config.xml
보려는 경우에 정의 됨 ).
(가) B
별칭으로 클래스 이름을 기준으로, 각 단어의 첫 글자는 대문자입니다. 이 경우 html
가 Html
되고 확인 된 별칭에 추가되므로 Mage_Page_Block_Html
. 이는 app/code/core/Mage/Page/Block/Html.php
클래스 이름이 Magento의 위치로 직접 변환되기 때문에 파일에서 찾을 수 있습니다.
블록 별칭 대신 모델 별칭을 사용 page
했다면 Mage_Page_Model
대신 사용됩니다. 자원 모델과 헬퍼도 마찬가지입니다. 블록, 모델 및 도우미를 포함 하려면 자체 모듈에서 구성 을 정의해야 합니다.
다음은 마 젠토 블록 유형에 대한 자세한 내용을 이해하기 위해 레이아웃에서 널리 사용되는 몇 가지 기본 제공 블록 유형입니다.
core/template
:이 블록은template
속성으로 정의 된 템플릿을 렌더링 합니다. 레이아웃에 정의 된 대부분의 블록은의 유형 또는 하위 유형입니다core/template
.page/html
: 이것은core/template
루트 블록 의 하위 유형 이며 정의합니다. 다른 모든 블록은이 블록의 자식 블록입니다.page/html_head
: JavaScript, CSS 등을 포함하는 요소가 포함 된 페이지의 HTML 헤드 섹션을 정의합니다.page/html_header
: 사이트 로고, 상위 링크 등이 포함 된 페이지의 헤더 부분을 정의합니다.page/template_links
:이 블록은 링크 목록을 만드는 데 사용됩니다. 바닥 글 및 머리글 영역에 표시되는 링크는이 블록 유형을 사용합니다.core/text_list
: 같은 일부 블록content
,left
,right
등 유형입니다core/text_list
. 이러한 블록이 렌더링되면getChildHtml()
메서드 를 호출 할 필요없이 모든 자식 블록이 자동으로 렌더링됩니다 .page/html_wrapper
:이 블록은 액션에 의해 설정된 HTML 태그 안에 자식 블록을 렌더링하는 래퍼 블록을 만드는 데 사용됩니다setHtmlTagName
. 기본 태그는<div>
요소가 설정되지 않은 경우입니다.page/html_breadcrumbs
:이 블록은 페이지의 이동 경로를 정의합니다.page/html_footer
: 바닥 글 링크, 저작권 메시지 등이 포함 된 페이지의 바닥 글 영역을 정의합니다.core/messages
:이 블록은 오류 / 성공 / 알림 메시지를 렌더링합니다.page/switch
:이 블록은 언어 또는 상점 전환기에 사용할 수 있습니다.
이것은 일반적으로 사용되는 블록 유형의 목록입니다. 고급 테마 구현에 사용되는 다른 많은 블록 유형이 있습니다.
<block type="page/html" name="root" output="toHtml" template="example/view.phtml">
page는 etc/config.xml
파일에 정의 된 FrontendName입니다. html은 블록 클래스 이름입니다.
자세한 내용은:
이 줄 type(type="page/html")
에서 귀하 template(template="example/view.phtml">)
와 관련된 블록 클래스 이름을 정의 하고 이름은 각 블록에 대해 고유합니다.
먼저 폴더 구조 참조
app> local> namespace> modulename> etc> config.xml
우리는 설정 FrontendName = 'mymodule'
app> local> namespace> modulename> 블록 > hello.php
hello.php에서 함수를 만들었습니다.
class namespace_modulename_Block_Data extends Mage_Core_Block_Template
{
public function mydata()
{
$data = "Block is called";
return $data;
}
}
이제 레이아웃 xml 페이지로 이동하십시오.
<block type="mymodule/data" name="xyz" template="example/view.phtml">
여기 mydata는 프런트 엔드 이름입니다.
이제 템플릿의
template / example / view.phtml 페이지
여기서 mydata () 함수를 직접 호출 할 수 있습니다.
처럼
<div>
<?php echo $this->mydata(); ?>
</div>
이제 "Block is called"브라우저에서 출력을 얻을 수 있습니다.
i don't know about "B" type, but "A" refer to your module name tag in config.xml example in config.xml:
<A><!-- script --></A>
No, you're not wrong. But the "<!-- script -->"
may be confusing. Let's clarify: as the above answers stated, this is an alias, which consisted of two parts, the first part ("A") itself is the alias you define to your module's classes in your module's config.xml
, the second is a path relative to the node's value. These together ("A" + capitalized "B") will be translated to a class name, using the first part (the "A" node's value) exactly as you define it (watch for upper/lowercase if you don't want hours of suffering) and the second part is capitalized after each underscore. So, start with the A/B example with a block and this config:
<config>
...
<global>
<blocks>
<A>Vendor_Module_Block</A>
</blocks>
</global>
...
</config>
In runtime A/B
would resolved by the Magento config to Vendor_Module_Block_B
which would then included by the autoload from the following path: public/app/local/Vendor/Module/Block/B.php
. To get a better understanding I advise you to take a look at the Mage_Core_Model_Config::getGroupedClassName()
, Mage_Core_Model_Config::getModelInstance()
and Varien_Autoload::autoload()
.
I don't know about "B" type, but "A" refer to your module name tag in config.xml
An example in the config.xml file:
<A><!-- script --></A>
nb: i hope i'm not wrong..
참고URL : https://stackoverflow.com/questions/6633307/understanding-magento-block-and-block-type
'Programming' 카테고리의 다른 글
div의 종횡비를 유지하지만 CSS에서 화면 너비와 높이를 채우시겠습니까? (0) | 2020.08.10 |
---|---|
현재 날짜 / 시간이 설정된 날짜 / 시간을 지난 지 어떻게 확인할 수 있습니까? (0) | 2020.08.10 |
VSTS 2010 SGEN : 오류 : 파일 또는 어셈블리를로드 할 수 없습니다 (HRESULT에서 예외 : 0x80131515). (0) | 2020.08.10 |
C #에서 마우스 위치 가져 오기 (0) | 2020.08.10 |
Eclipse 3.7을 4.2 (Juno)로 업그레이드하는 가장 쉬운 방법 (0) | 2020.08.10 |