0

I have a custom module. I am using this module to upload images through admin. I have 6 more form fields in my module. I am currently using one table to store values of these form fields. However as like in magento, i am planning to store image values in another table. My table structure is given below.

Table : Banner

        Fields :  banner_id( primary_key , int(11) ) 

                  banner_name( varchar (250) )

                  banner_count( small_int (6) )

                  status( small_int (6) )  

                  store_id( varchar (250) )   

Table : banner_images

        Fields : bi_id( primary_key , int (11) ) 

                 banner_id( int (11) ) //this should be the 'banner_id' of banner which holds this imge

                 bi_name( varchar (255) ) //stores image_name

My current edit file look like this:

<?php
class Karaokeshop_Banner_Block_Adminhtml_Banner_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {
        parent::__construct();
        $this->_objectId = 'id';
        $this->_blockGroup = 'banner';
        $this->_controller = 'adminhtml_banner';
        $this->_updateButton('save', 'label', Mage::helper('banner')->__('Save Banner'));
        $this->_updateButton('delete', 'label', Mage::helper('banner')->__('Delete Banner'));


    }

    public function getHeaderText()
    {
        if( Mage::registry('banner_data') && Mage::registry('banner_data')->getId() ) 
        {
            return Mage::helper('banner')->__("Edit Banner");
        } 
        else 
        {
            return Mage::helper('banner')->__('Add Banner');
        }
    }
}

My sql file look like this :

 ?php
      $installer = $this;
      $installer->startSetup();
      $installer->run("
          DROP TABLE IF EXISTS {$this->getTable('banner')};
              CREATE TABLE {$this->getTable('banner')} (
                  `banner_id` int(11) unsigned NOT NULL auto_increment,
                  `banner_name` varchar(255) NOT NULL default '',
                  `banner_count` smallint(6) NOT NULL default '0',
                  `status` smallint(6) NOT NULL default '0',
                  `store_id` varchar(255) NOT NULL default '',
                  `img` varchar(255) NOT NULL default '',
                   PRIMARY KEY (`banner_id`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
          ");
     $installer->endSetup();

How can I achieve this? Please provide links, if there is any tutorials for this. Thanks in advance.

1

1 Answer 1

1

Follow the steps below.

  1. Create a directory under media or just inside your project folder. ( a place where you can access)
  2. Save your images inside that directory.
  3. In the database create a table which save the following attributes

banner_id, path, banner_name, etc

Make sure when you loading images get the path from database table and load it.

7
  • Thanks for reply.I have a directory in media folder. I can save image in that folder also. But i dont know how to store the image details in my second table Jan 2, 2014 at 3:52
  • Store the image path and other relevant details. Use controller action and models to do this
    – Sukeshini
    Jan 2, 2014 at 4:04
  • that is what i am asking for. I configured my module with the first table only. How can configure my second table with my module and how can i does changes to my saveAction() according to it? Jan 2, 2014 at 4:10
  • can we chat about this? Jan 2, 2014 at 4:15
  • Try these links as well. xhtmlandcsshelp.blogspot.com/2011/04/…
    – Sukeshini
    Jan 2, 2014 at 4:50

Your Answer

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

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