Modify Grid Block
Add the _preparemassaction () function in/app/code/local/xinson/news/block/adminhtml/news/grid.php
<?phpclass xinson_news_block_adminhtml_news_grid extends mage_adminhtml_block_widget_grid{ //... protected function _ Preparemassaction () { $this Setmassactionidfield (' news_id '); $this->getmassactionblock () ->setformfieldname (' News '); $this->getmassactionblock ()->additem (' delete ', array ( ' label ' => mage::helper (' News ')->__ (' Delete '), ' url ' => $ This->geturl (' */*/massdelete '), ' Confirm ' => mage:: Helper (' News ')->__ (' Are you sure? ') ); $statuses = mage::getsingleton (' news/news ') Getstatusesoptionsarray (); array_unshift ($statuses, array (' label ' = ', ' value ' = ') '); $this->getmassactionblock () AddItem (' Status ', array ( ' label ') => mage::helper (' News ')->__ (' Change status '), ' url ' => $this->geturl (' */*/massstatus ', array (' _current ' = >true)), ' additionAl ' => array ( ' visibility ' => array ( ' name ' => ' status ', ' type ' => ' SELECT ', ' class ' => ' Required-entry ', ' label ' => mage::helper (' News ')->__ (' Status '), ' values ' => $statuses ) ); ( )) return $this; }}
Use the Getstatusesoptionsarray () function, which we added in/app/code/local/xinson/news/model/news.php
<?phpclass xinson_news_model_news extends mage_core_model_abstract{ / /... public function getstatusesoptionsarray () { return array ( array ( ' label ' => mage::helper (' News ')->__ (' Enabled '), ' value ' = > self::STATUS_ENABLED ), array ( ' label ' => mage::helper (' News ')->_ _ (' Disabled '), ' value ' => self::STATUS_DISABLED ) ); }}
Refresh background We will observe that a Bulk selection toolbar appears at the top of the table, and in the Action selection box we can select Delete and change status, and when you select the status, the Status selection box will appear to the right of the selection box. You can select enabled and disabled, and a selection box appears to the left of each news record.
Modify the background controller
In the above code, we used $this->geturl (' */*/massdelete ') and $this->geturl (' */*/massstatus ', Array (' _current ' =>true)) As a commit address for bulk deletion and modification, we now need to add the Massdelete () and Massstatus () methods to the background controller.
Modify/app/code/local/xinson/news/controllers/adminhtml/newscontroller.php
<?phpclass xinson_news_adminhtml_newscontroller extends mage_adminhtml_controller_action{ //... public function massdeleteaction () { $newsIds = $this->getrequest () GetParam (' News '); $newsModel = mage::getmodel (' News/news '); if (!is_array ($newsIds)) { mage::getsingleton (' adminhtml/session ')->addError ( mage::helper (' Adminhtml ')->__ (' Please select item (s) ') ); } else { try { foreach ($newsIds as $newsId) { $new = $ Newsmodel->load ($newsId); $new->delete (); } mage::getsingleton (' adminhtml/session ')->addsuccess ( mage:: Helper (' adminhtml ')->__ ( ' Total of %d record (s) were successfully deleted ' , count ($NEWSIDS) ) ); } catch (exception $e) { mage::getsingleton (' adminhtml/session ')->addError ($e GetMessage ()); } } $this->_redirect (' */*/index ' ); &nbsP;} public function massstatusaction () { $newsIds = $this->getrequest () GetParam (' News '); $newsModel = mage:: Getsingleton (' news/news '); if (!is_array ($newsIds)) { mage::getsingleton (' adminhtml/session ') ->adderror ( $this->__ (' Please select item (s) '); } else { try { foreach ($newsIds as $newsId) &NBSP;{&NBSP;&NBSP;&NBsp; $newsModel->load ($newsId) ->setisactive ($ This->getrequest ()->getparam (' status ')) ->setismassupdate (True) ->save (); } $this->_getsession () &nbsP; ->addsuccess ( $this->__ (' Total of %d record (s) were successfully updated ', count ($newsIds)) ); } catch (exception $e) { $this->_getsession ()->adderror ($e->getmessage ()); } } $this->_redirect (' */*/index '); }}
Magento News Module Development (III.)