2015-09-11 77 views
0

我是新的magento,請原諒我,如果我有任何問題。我爲Instagram登錄創建了一個自定義模塊,我只是想從該模塊中調用特定的模塊到另一個佈局文件。我呼籲使用Magento在另一個自定義塊內調用自定義塊

<?php echo $this->getChildHtml('media_new'); ?> 

我塊接到電話,但功能正在和形式不提交該塊在我看來頁打印。

我的自定義模塊佈局文件。 Instagram.xml

<?xml version="1.0"?> 
<layout version="0.1.0"> 
<default> 
     <reference name="content"> 
     </reference> 
</default> 
    <instagram_index_instagram_signup> 
     <reference name="head"> 
      <action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action> 
     </reference> 
     <reference name="content"> 
      <block type="core/template" name="instagram.signup" template="instagramlogin/Instagram_signup.phtml"></block> 
     </reference> 
    </instagram_index_instagram_signup> 
</layout> 

我想上面的塊調用另一個模塊佈局文件: 我的另一個模塊佈局頁:

   <marketplace_vendor_login> 
    <reference name="head"> 
      <action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action> 
    </reference> 
    <remove name="right"/> 
    <remove name="left"/> 
    <reference name="before_body_end"> 
     <block type="facebookfree/init" name="belvg_facebookfree_block"> 
      <action method="setTemplate" ifconfig="facebookfree/settings/enabled" ifvalue="1"> 
       <template>belvg/facebookfree/block.phtml</template> 
      </action> 
     </block> 
    </reference> 
    <reference name="root"> 
     <action method="setTemplate"><template>page/1column.phtml</template></action> 
    </reference> 
    <reference name="content"> 
    <block type="marketplace/vendor_login" name="customer_form_login" template="nbmpmarketplace/login.phtml" > 
     <block type="facebookfree/links_button" name="belvg_facebookfree_button" template="belvg/facebookfree/form/button.phtml" /> 
      <block type="core/template" name="instagram.signup" as="media_new" template="instagramlogin/Instagram_signup.phtml"></block> 
    </block> 
    </reference> 
</marketplace_vendor_login> 

在這裏,我呼籲我的自定義模塊,然後印在我的觀點頁面:對於Instagram的

  <?php echo $this->getChildHtml('media_new'); ?> 

我的控制器代碼:

class Blazedream_Instagram_IndexController extends Mage_Core_Controller_Front_Action 
     { 
public function instagram_signupAction() 
{ 
    if ($this->getRequest()->isPost()){ 
     if($this->getRequest()->getPost('instagram-email')){ 
      $instagram_email = $this->getRequest()->getPost('instagram-email'); 
      $customer_model = Mage::getModel('instagram/instagram'); 
      $site_customer = $customer_model->checkCustomer($instagram_email); 
      if($site_customer){ 
       $instagram_customer = Mage::getModel('instagram/instagram')->getCollection() 
                ->addFieldToFilter('customer_id', array('eq' => $site_customer)); 
       if(count($instagram_customer)==1){ 
        Mage::getSingleton('core/session')->setInstagramEmail($instagram_email); 
        $this->_redirect('instagram/index');  
       }else{ 
        Mage::getSingleton('customer/session')->addError('Email Id Already Registered.'); 
        $this->_redirect('sellerlogin');  
       } 
      }else{ 
       Mage::getSingleton('core/session')->setInstagramEmail($instagram_email); 
       $this->_redirect('instagram/index'); 
      } 
     } 
    } 
    $this->loadLayout(); 
    $this->getLayout()->getBlock('instagram.signup'); 
    $this->renderLayout(); 
} 
} 

它沒有進入這個控制器功能,那我用於instagram模塊。

我的看法頁:instagramlogin.phtml

 <div style="display: none"> 
    <style type="text/css"> 
     #cboxContent.newsletterbox { 
     <?php if($backgroundImage){?> background-image: url(<?php echo Mage::getBaseUrl('media').'/wysiwyg/magenthemes/newsletter/'.$backgroundImage;?>); 
     <?php }?> background-position: left top; 
      background-repeat: no-repeat; 
      background-color: <?php echo $backgroundColor;?>; 
     } 
    </style> 
    <div id="mt_instagram" class="block block-subscribe"> 
     <div class="row"> 
      <div class="left-newletters col-lg-8 col-md-8 col-sm-8 col-xs-8"> 
       <div class="block-title"> 
        <strong><span><?php echo $this->__('Join our Mail List Through Instagram!') ?></span></strong> 
       </div> 
       <div class="row-none"> 
        <div class="popup_message"> 
         <div class="intro"> 
          <?php echo $desc; ?> 
         </div> 
         <form action="<?php echo Mage::getBaseUrl().'instagram/index/instagram_signup'; ?>" method="post" id="instagram-validate-detail"> 
          <div class="block-content"> 
           <div class="input-box"> 
            <input name="instagram-email" type="text" id="mt-newsletter" placeholder="Enter your email id" 
              value="" class="input-text required-entry validate-email"/> 


            <div class="actions"> 
             <button type="submit" title="<?php echo $this->__('Subscribe') ?>" 
               class="button"> 
              <span><span><?php echo $this->__('Subscribe') ?></span></span></button> 
            </div> 
           </div> 
          </div> 
         </form> 
        </div> 
       </div> 

我讓我的自定義窗體also..But控制器是沒有得到所謂的和功能主義不工作,只有我得到的形式。

任何人都可以幫助我嗎?

+0

「但控制器正在調用,功能工作者不工作」 - 你在談論哪個控制器?哪些功能不起作用?您只顯示負責將代碼塊添加到佈局(工作),而不是任何* *不工作的代碼 –

+0

對不起,我編輯了問題..我只獲取表單,但表單未發佈。 – tttt

+0

塊被調用。 – tttt

回答

0

這是我第一次在stackoverflow上的答案,我會盡我所能解釋。

首先,讓我介紹一下Magento中的塊調用;任何特定類型的Block(Block文件夾中的.php文件)都有一個對應的內容/模板(模板文件夾中的.phtml)文件,用於渲染從Model(模型文件夾中的.php)中獲取的數據。

在佈局(.XML在佈局文件夾中的模塊),已經將一個塊的類型(核心/模板),因此它會調用該文件Mage_Core_Block_Template.php並訪問其所有方法。但是,如果你想創建一個自定義塊,你可以像這樣更新佈局(instagram模塊)文件。

<layout version="0.1.0"> 
    <default> 
      <reference name="content"> 
      </reference> 
    </default> 
     <instagram_index_instagram_signup> 
      <reference name="head"> 
       <action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action> 
      </reference> 
      <reference name="content"> 
       <block type="instagram/instagram" name="instagram.signup" template="instagramlogin/Instagram_signup.phtml"></block> 
      </reference> 
     </instagram_index_instagram_signup> 
    </layout> 

,開創名稱Blazedream_Instagram_Block_Instagram.php塊文件夾中的文件,然後你就可以調用自定義的方法來塊模板。 Ex.-

class Blazedream_Instagram_Block_Instagram extends Mage_Core_Block_Template 
    { 
     public function customMethod() 
     { 
     $response = array('a', 'b', 'c'); 

     $this->getResponse()->setHeader('Content-type','application/json', true); 
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); 
     return; 
     } 
    } 

更新您的控制器操作調用

$this->loadLayout(); 
    $this->renderLayout(); 

現在,添加此塊內的另一個自定義模塊,更新其佈局類似

<fname_controller_action> 
     //path controller path on which you want to add/update the block 
     <update handle="my_custom_handle" /> 
    </fname_controller_action> 

    <my_custom_handle> 
     <reference name="content"> 
      <reference name="where_you_want_to_add"> 
       <block type="instagram/instagram" name="my.custom.block" as="instagram.signup" template="template_path/instagram.phtml"/> 
      </reference> 
     </reference> 
    </my_custom_handle> 

或添加一個構造函數在塊文件Blazedream_Instagram_Block_Instagram中。PHP的像 -

public function __construct() 
    { 
     parent::__construct(); 
     $this->setTemplate('template/instagram.phtml'); 
    } 

,並呼籲任何模板文件中的塊用下面的代碼

echo $this->getLayout()->createBlock('instagram/instagram')->toHtml(); 

You might need to update your layout file in this case. 

如果你正確地做的一切,你應該能夠> customMethod()的調用$這 - 的模板文件instagram.phtml

謝謝!如果我不能正確解釋,請原諒我。