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.
-
Take a look at these excellencemagentoblog.com/magento-part6-series-models, excellencemagentoblog.com/…, excellencemagentoblog.com/magento-blogs/…Evgeni Ivanov– Evgeni Ivanov2014年02月02日 06:28:57 +00:00Commented Feb 2, 2014 at 6:28
1 Answer 1
Follow the steps below.
- Create a directory under media or just inside your project folder. ( a place where you can access)
- Save your images inside that directory.
- 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.
-
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 tableRajeev K Tomy– Rajeev K Tomy2014年01月02日 03:52:56 +00:00Commented Jan 2, 2014 at 3:52
-
Store the
image pathand other relevant details. Use controller action and models to do thisSukeshini– Sukeshini2014年01月02日 04:04:17 +00:00Commented 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?Rajeev K Tomy– Rajeev K Tomy2014年01月02日 04:10:14 +00:00Commented Jan 2, 2014 at 4:10
-
can we chat about this?Rajeev K Tomy– Rajeev K Tomy2014年01月02日 04:15:14 +00:00Commented Jan 2, 2014 at 4:15
-
Try these links as well. xhtmlandcsshelp.blogspot.com/2011/04/…Sukeshini– Sukeshini2014年01月02日 04:50:21 +00:00Commented Jan 2, 2014 at 4:50
Explore related questions
See similar questions with these tags.