修改 /app/code/local/Xinson/News/etc/config.xml
<modules> <Xinson_News> <version>0.1.1</version> </Xinson_News> </modules>
数据库更新文件
/app/code/local/Xinson/News/sql/news_setup/mysql4-upgrade-0.1.0-0.1.1.php
<?php /* @var Mage_Core_Model_Resource_Setup $this */ $this->run(" ALTER TABLE `news` ADD `filename` VARCHAR (50) NOT NULL DEFAULT ‘‘ AFTER `title`; ");
修改编辑区域
/app/code/local/Xinson/News/Block/Adminhtml/News/Edit/Tab/Form.php
<?php class Xinson_News_Block_Adminhtml_News_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form { protected function _prepareForm() { $model = Mage::registry(‘news_data‘); $form = new Varien_Data_Form(); $fieldset = $form->addFieldset(‘news_form‘, array(‘legend‘=>Mage::helper(‘news‘)->__(‘News information‘))); if ($model->getNewsId()) { $fieldset->addField(‘news_id‘, ‘hidden‘, array( ‘name‘ => ‘news_id‘, )); } $fieldset->addField(‘title‘, ‘text‘, array( ‘name‘ => ‘title‘, ‘label‘ => Mage::helper(‘news‘)->__(‘News Title‘), ‘title‘ => Mage::helper(‘news‘)->__(‘News Title‘), ‘required‘ => true, )); $fieldset->addField(‘is_active‘, ‘select‘, array( ‘name‘ => ‘is_active‘, ‘label‘ => Mage::helper(‘news‘)->__(‘Status‘), ‘title‘ => Mage::helper(‘news‘)->__(‘News Status‘), ‘required‘ => true, ‘options‘ => $model->getAvailableStatuses(), )); //新加的 //小图路径 $fieldset->addType(‘image‘, Mage::getConfig()->getBlockClassName(‘news/adminhtml_news_helper_image‘)); //输入框 $fieldset->addField(‘filename‘, ‘image‘, array( ‘label‘ => Mage::helper(‘news‘)->__(‘File‘), ‘required‘ => false, ‘name‘ => ‘filename‘, )); $fieldset->addField(‘content‘, ‘editor‘, array( ‘name‘ => ‘content‘, ‘label‘ => Mage::helper(‘news‘)->__(‘Content‘), ‘title‘ => Mage::helper(‘news‘)->__(‘Content‘), ‘required‘ => true, ‘style‘ => ‘width:700px; height:300px;‘, )); $form->setValues($model->getData()); $this->setForm($form); return parent::_prepareForm(); } }
修改config配置文件(上传文件保存的目录)
<config> ...... <default> <news> <general> <image_folder>news</image_folder> <placeholder>no_image.jpg</placeholder> </general> </news> </default> </config>
加Image文件,/app/code/local/Xinson/News/Block/Adminhtml/News/Helper/Image.php
<?php class Xinson_News_Block_Adminhtml_News_Helper_Image extends Varien_Data_Form_Element_Image { protected function _getUrl() { $url = false; if ($this->getValue()) { $url = Mage::getBaseUrl(‘media‘) . trim(Mage::getStoreConfig(‘news/general/image_folder‘), ‘ /\\‘) . ‘/‘ . $this->getValue(); } return $url; } }
时间: 2024-12-19 06:01:00