I am developing a module in magento. I added a new Tab in CMS >> Page core module through my custom module. I want to save new tab data in separate table which one created by custom module. My problem is that I don't know how can I save new tab data in my new table when core page's save/edit functionality works?

Thanks in advance.

1 Answer 1


EDIT: The entire answer updated, to accommodate new cms page creation.

Ok, you can solve this in multiple ways, rewrites are one (rewriting controller and models of the cms system (yuk)) or just using observers/events. I prefer observer events, as it makes for higher compatibility with other 3rd party modules.

As per my previous answer, the flaw was that I suggested using only the 'cms_page_prepare_save' event, but as you had found that does not work for new pages. Why? Because the page model has not saved yet, thus no page id.

However, this event is the only event available that also passes the request data, so it must be used.

The solution: Use two events. The first stays as 'cms_page_prepare_save', which allows you to get the request data, and the second will be an event on the model save after 'cms_page_save_after'.

Thus the process will be:

  1. Observe the 'cms_page_prepare_save' event
  2. Grab the request data and extract your tabs data.
  3. Set that against the page model that was also passed (this is temp storage so you can use it later)
  4. Listen to the cms page model save after event. 'cms_page_save_after'
  5. Grab your data out of the page model, as well as the page id and use it.

So here goes:

In the observer event 'cms_page_prepare_save' you will have code like this:

public function cms_page_prepare_save(Varien_Event_Observer $observer) {
        $requestParams = $observer->getRequest()->getParams(); 
        $page = $observer->getPage();
        $page->setData('request_params',$requestParams); // save the request data to the page model. This will not intevere with normal model functionality as it will be ignored by anything else.
        return $this;

Next you have another observer on 'cms_page_prepare_save' event with this code:

public function cms_page_save_after(Varien_Event_Observer $observer) { 
        $page = $observer->getObject();
        $requestParams = $page->getRequestParams();
        // do what you need to do with your tab data, which is now in $requestParams
        return $this;

Ideally in the cms_page_prepare_save observer code you'd only store your tabs information, not the entire request params, as that could be a lot of data. You could also use this event to filter/sanetise/check your data, before the models get saved.

Hope this adjusted answer helps.

  • thanks for you kind response, but I want to save all data after save, because I want to store page_id in custom table when I create new page. How can I do this? Aug 14, 2013 at 9:52
  • You can get all the info you need via the event. I updated the answer with an example of how to get the information out in the observer. Using google, you will find a lot of help on how to create an observer for an event. If you do not come right (via google) on how to do the observer, please do ask, and I will help you further.
    – ProxiBlue
    Aug 14, 2013 at 12:18
  • it's works only when I am edit the page, but not working when i am going to add new cms page. Aug 14, 2013 at 21:08
  • I updated the answer to accommodate new page creation.
    – ProxiBlue
    Aug 15, 2013 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.