Error:
Fatal error: Call to a member function setData() on boolean in C:\xampp\htdocs\magento-1-testing\app\code\core\Mage\Adminhtml\Block\Widget\Form\Container.php on line 141 I have create a custom module to add an additional section to upload an image for the CSM page but it is not working, its even not showing the input on the CMS page admin section.
<?xml version="1.0"?> <config> <modules> <Flexishore_Cms> <active>true</active> <codePool>local</codePool> </Flexishore_Cms> </modules> </config> Config.xml
<?xml version="1.0"?> <config> <modules> <Flexishore_Cms> <version>0.1.0</version> </Flexishore_Cms> </modules> <global> <models> <flexishore_cms> <class>Flexishore_Cms_Model</class> </flexishore_cms> </models> <blocks> <flexishore_cms> <class>Flexishore_Cms_Block</class> </flexishore_cms> <adminhtml> <rewrite> <cms_page_edit_form>Flexishore_Cms_Block_Adminhtml_Cms_Page_Edit_Form</cms_page_edit_form> </rewrite> </adminhtml> </blocks> <resources> <flexishore_cms_setup> <setup> <module>Flexishore_Cms</module> <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </flexishore_cms_setup> <flexishore_cms_write> <connection> <use>core_write</use> </connection> </flexishore_cms_write> <flexishore_cms_read> <connection> <use>core_read</use> </connection> </flexishore_cms_read> </resources> </global> <adminhtml> <events> <cms_page_prepare_save> <observers> <flexishore_cms_save_page> <type>singleton</type> <class>flexishore_cms/observer_cms</class> <method>savePage</method> </flexishore_cms_save_page> </observers> </cms_page_prepare_save> <adminhtml_cms_page_edit_tab_main_prepare_form> <observers> <flexishore_cms_prepare_form> <type>singleton</type> <class>flexishore_cms/observer_cms</class> <method>prepareForm</method> </flexishore_cms_prepare_form> </observers> </adminhtml_cms_page_edit_tab_main_prepare_form> </events> </adminhtml> My Observer.php
class Flexishore_Cms_Model_Observer{ public function prepareForm(Varien_Event_Observer $observer) { $form = $observer->getEvent()->getForm(); $fieldset = $form->addFieldset( 'image_fieldset', array( 'legend' => 'Image', 'class' => 'fieldset-wide' ) ); $fieldset->addField('background', 'image', array( 'name' => 'background', 'label' => 'Background image', 'title' => 'Background image' )); } public function savePage(Varien_Event_Observer $observer) { $model = $observer->getEvent()->getPage(); $request = $observer->getEvent()->getRequest(); if (isset($_FILES['background']['name']) && $_FILES['background']['name'] != '') { $uploader = new Varien_File_Uploader('background'); $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); // Set media as the upload dir $media_path = Mage::getBaseDir('media') . DS . 'background' . DS; // Set thumbnail name $file_name = 'cms_'; // Upload the image $uploader->save($media_path, $file_name . $_FILES['background']['name']); $data['background'] = 'background' . DS . $file_name . $_FILES['background']['name']; // Set thumbnail name $data['background'] = $data['background']; $model->setBackground($data['background']); } else { $data = $request->getPost(); if($data['background']['delete'] == 1) { $data['background'] = ''; $model->setBackground($data['background']); } else { unset($data['background']); $model->setBackground(implode($request->getPost('background'))); } } } } } Block Code is like this:
class Flexishore_Cms_Block_Adminhtml_Cms_Page_Edit_Form extends Mage_Adminhtml_Block_Widget_Form { protected function _prepareForm() { $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data')); $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); } } And Sql file in sql folder: mysql-install-0.1.0.php
$installer = $this; $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->startSetup(); $installer->run(' ALTER TABLE `cms_page` ADD `background` VARCHAR( 255 ) NULL; '); $installer->endSetup();