2
我編程方式加載塊內Magento管理控制器這樣定義的Magento模板路徑
`$block = $this->getLayout()->createBlock('core/text')->setText('<script type="text/javascript" ></script>');`
現在,而不是的setText,我想用setTemplate方法。我在這個目錄設計/ adminhtml/default/default/product/productcrop.phtml中創建了一個模板文件。
我該如何加載它,即setTemplate方法中的參數是什麼?
我試過這樣: - > setTemplate('adminhtml/product_productcrop.phtml')。但它似乎並沒有工作。
整個控制器代碼:
<?php
class Homeliv_Leadsadmin_Adminhtml_ProductController extends Mage_Adminhtml_Controller_Action {
public function indexAction() {
$this->loadLayout()->_setActiveMenu('leadsadmin/product');
$this->_addContent($this->getLayout()->createBlock('leadsadmin/adminhtml_product'));
$this->renderLayout();
}
public function editAction() {
$product_id = $this->getRequest()->getParam('id');
$full_product = Mage::getModel('catalog/product')->load($product_id);
$productMediaConfig = Mage::getModel('catalog/product_media_config');
//$baseImageUrl = $productMediaConfig->getMediaUrl($full_product->getImage());
//$thumbImageUrl = $productMediaConfig->getMediaUrl($full_product->getThumbnail());
$smallImage = $productMediaConfig->getMediaUrl($full_product->getSmallImage());
$this->loadLayout();
//$this->_title($this->__("Product"));
/* $block = $this->getLayout()->createBlock('core/text')->setText('<script type="text/javascript" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'media/leadsadmin/product_crop.js'.'"></script>');
$this->_addJs($block);
$this->_addLeft($this->getLayout()
->createBlock('core/text')
->setText('<h1>Image</h1><img src="'.$smallImage.'"/>'));
$block = $this->getLayout()
->createBlock('core/text')
->setText('<h1>Main Block</h1>');
$this->_addContent($block);*/
$block = $this->getLayout()->createBlock('core/template')-> setTemplate('product/productcrop.phtml')->toHtml();
$this->_addContent($block);
//$this->getLayout()->createBlock('leadsadmin/adminhtml_product')->setTemplate('product/productcrop.phtml')->toHtml();
//$this->getLayout()->createBlock('core/text')->setText('<div>ssxsxsx</div>');
$this->renderLayout();
//var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
//die();
//$this->loadLayout()->_setActiveMenu('leadsadmin/product');
//$this->_addContent($this->getLayout()->createBlock('leadsadmin/adminhtml_product'));
//$this->renderLayout();
}
}
我用這個來添加塊:$ this - > _ addContent($ block);它會拋出錯誤:可恢復錯誤:傳遞給Mage_Adminhtml_Controller_Action :: _ addContent()的參數1必須是Mage_Core_Block_Abstract的一個實例 – androider
你能解釋你想達到什麼,所以我可以幫忙。 –
我在問題中添加了控制器代碼。我只是想以編程方式加載我的phtml文件 – androider