편집 불가능한 Magento CMS 페이지를 작성하는 방법


16

Magento를 새로 설치하면에서 편집 할 수있는 몇 가지 기본 CMS 페이지가 제공됩니다 CMS > Pages. 그러나, 그것은 또한 "비 편집"CMS 페이지의 부부와 함께 제공 Orders and Returns하고 Contact Us작성 및 편집 양식 : 그들에 양식 및 하이라이트 젠토 CE의 단점과 페이지입니다 둘 다 ....

본인의 양식으로 기본 문의처를 재정의했지만 다른 양식을 추가하고 싶습니다. 나중에 더 많은 양식을 추가해야 할 수도 있습니다. 지금까지 한 것처럼 기존 기능과 페이지를 재정의하기 위해 Magento 모듈을 만드는 데 다소 익숙합니다.

Magento에서 양식 페이지를 만들 수있는 모듈에서 작업을 시작했지만 기본 양식과 같이 CMS 관리에 표시되지 않아야합니다. 프로그래밍 방식으로 CMS 페이지를 만드는 데 대한 답변을 찾았지만 Magento에 추가했습니다 CMS > Pages.

Magento 모듈에서만 편집 할 수있는 CMS 페이지를 작성하는 방법


알아 둘만 한! 이 게시물을 이미 게시 한 이후 교차 게시하는 것이 좋습니까?
andyjv

"플래그"링크를 클릭하고 모드를 변경하도록 요청합니다. 일반적으로 말하면 교차 게시는 눈살을 찌푸립니다.
John Conde

CMS 페이지에서 사용자 정의 연락처 양식을 찾으려면 magento.stackexchange.com/questions/79602/… 또는보다 자세한 stackoverflow.com/q/1066127/664108
Fabian Schmengler

답변:


21

실제로 '문의하기'및 '주문 및 반품'은 CMS 페이지가 아닙니다. 실제로 별도의 모듈에서 페이지입니다. CMS 페이지보다 '로그인'또는 '등록'페이지와 비슷합니다. 이와 같은 페이지를 만들려면 컨트롤러, 하나의 블록 및 하나의 템플릿으로 간단한 모듈을 만들 수 있습니다. 확장명 Easylife_Customform을 호출합니다. 이를 위해 다음 파일이 필요합니다.
app/etc/modules/Easylife_Customform.xml-모듈 선언 파일

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Customform>
            <active>true</active>
            <codePool>local</codePool>
        </Easylife_Customform>
    </modules>
</config>

app/code/local/Easylife/Customform/etc/config.xml -구성 파일

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Customform>
            <version>0.0.1</version>
        </Easylife_Customform>
    </modules>
    <global>
        <blocks>
            <customform><!-- block alias -->
                <class>Easylife_Customform_Block</class>
            </customform>
        </blocks>
        <helpers>
            <customform><!-- helper alias -->
                <class>Easylife_Customform_Helper</class>
            </customform>
        </helpers>
    </global>
    <frontend>
        <routers>
            <customform>
                <use>standard</use>
                <args>
                    <module>Easylife_Customform</module>
                    <frontName>customform</frontName><!-- url key for module -->
                </args>
            </customform>
        </routers>
        <layout>
            <updates>
                <easylife_customform>
                    <file>easylife_customform.xml</file><!-- frontend layout file -->
                </easylife_customform>
            </updates>
        </layout>
        <translate>
            <modules>
                <Easylife_Customform>
                    <files>
                        <default>Easylife_Customform.csv</default><!-- translation file (not mandatory) -->
                    </files>
                </Easylife_Customform>
            </modules>
        </translate>
    </frontend>
</config>

app/design/frontend/base/default/layout/easylife_customform.xml -프론트 엔드 레이아웃 파일

<?xml version="1.0"?>
<layout>
    <customform_index_index translate="label" module="customform">
        <label>Custom form</label>
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-right.phtml</template></action><!-- can be different -->
        </reference>        
        <reference name="content">
            <block type="core/template" name="customform" template="easylife_customform/form.phtml" /><!-- content of page -->
        </reference>
    </customform_index_index>
</layout>

app/code/local/Easylife/Customform/Helper/Data.php -기본 모듈 헬퍼

<?php
class Easylife_Customform_Helper_Data extends Mage_Core_Helper_Abstract{
}

app/design/frontend/base/default/template/easylife_customform/form.phtml -양식의 실제 HTML-필요한 모양으로 만듭니다.

<form action="<?php echo $this->getUrl('customform/index/send')?>">
    <input type="text" name="name" />
    <input type="submit" />
</form>

app/code/local/Easylife/Customform/controllers/IndexController.php -모듈 컨트롤러

<?php 
class Easylife_Customform_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){ //this will display the form
        $this->loadLayout();
        $this->_initLayoutMessages('core/session'); //this will allow flash messages
        $this->renderLayout();
    }
    public function sendAction(){ //handles the form submit
        $post = $this->getRequest()->getPost();
        //do something with the posted data
        Mage::getSingleton('core/session')->addSuccess($this->__('Your message was sent'));//add success message.
        $this->_redirect('*/*');//will redirect to form page
    }
}

이거 야. 캐시를 mysite.com/customform
지우면 코드를 올바르게 작성하고 무언가를 놓치지 않기를 바랍니다.


2
당신은 정말이 답변에 여분의 마일을 갔다. +1
philwinkle

@ philwinkle : 좋은가요 나쁜가요? :)
Marius

정말 좋은 가이드 마리우스, 감사합니다! 페이지 제목을 설정하려고하는데 레이아웃 XML의 <label>이 무시되고 <reference name="head"> <action method="setTitle" translate="title"><title>Subscribe to our Newsletter</title></action> </reference> 작동하지 않습니다.
loeffel

@loeffel. 제목을 대체하는 다른 것이있을 수 있습니다. 이론적으로 코드가 작동합니다.
Marius

@Marius 이것은 매우 편리하지만 어떻게 오류 메시지를 추가 할 수 있습니까? 나는 추가를 시도 Mage::getSingleton('core/session')->addError("Error");했지만 운이 없다. 성공 메시지 만 표시됩니다. 어떤 도움?
Aamir Siddique
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.