Programming

마 젠토 블록 및 블록 유형 이해

procodes 2020. 8. 10. 20:57
반응형

마 젠토 블록 및 블록 유형 이해


나는 단지의 의미를 이해하고 싶다.

 <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별칭으로 클래스 이름을 기준으로, 각 단어의 첫 글자는 대문자입니다. 이 경우 htmlHtml되고 확인 된 별칭에 추가되므로 Mage_Page_Block_Html. 이는 app/code/core/Mage/Page/Block/Html.php클래스 이름이 Magento의 위치로 직접 변환되기 때문에 파일에서 찾을 수 있습니다.

블록 별칭 대신 모델 별칭을 사용 page했다면 Mage_Page_Model대신 사용됩니다. 자원 모델과 헬퍼도 마찬가지입니다. 블록, 모델 및 도우미를 포함 하려면 자체 모듈에서 구성 을 정의해야 합니다.


다음은 마 젠토 블록 유형에 대한 자세한 내용을 이해하기 위해 레이아웃에서 널리 사용되는 몇 가지 기본 제공 블록 유형입니다.

  1. core/template:이 블록은 template 속성으로 정의 된 템플릿을 렌더링  합니다. 레이아웃에 정의 된 대부분의 블록은의 유형 또는 하위 유형입니다  core/template.
  2. page/html: 이것은 core/template 루트 블록 의 하위 유형  이며 정의합니다. 다른 모든 블록은이 블록의 자식 블록입니다.
  3. page/html_head: JavaScript, CSS 등을 포함하는 요소가 포함 된 페이지의 HTML 헤드 섹션을 정의합니다.
  4. page/html_header: 사이트 로고, 상위 링크 등이 포함 된 페이지의 헤더 부분을 정의합니다.
  5. page/template_links:이 블록은 링크 목록을 만드는 데 사용됩니다. 바닥 글 및 머리글 영역에 표시되는 링크는이 블록 유형을 사용합니다.
  6. core/text_list: 같은 일부 블록  contentleftright 등 유형입니다  core/text_list. 이러한 블록이 렌더링되면 getChildHtml() 메서드 를 호출 할 필요없이 모든 자식 블록이 자동으로 렌더링됩니다 .
  7. page/html_wrapper:이 블록은 액션에 의해 설정된 HTML 태그 안에 자식 블록을 렌더링하는 래퍼 블록을 만드는 데 사용됩니다  setHtmlTagName. 기본 태그는  <div> 요소가 설정되지 않은 경우입니다.
  8. page/html_breadcrumbs:이 블록은 페이지의 이동 경로를 정의합니다.
  9. page/html_footer: 바닥 글 링크, 저작권 메시지 등이 포함 된 페이지의 바닥 글 영역을 정의합니다.
  10. core/messages:이 블록은 오류 / 성공 / 알림 메시지를 렌더링합니다.
  11. 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

반응형