Magento Forum

   
Creating new database table from the action of an Controller
 
Drk_alien
Jr. Member
 
Total Posts:  7
Joined:  2012-10-14
 

Hy,
I want to develop an extension and i’m facing some problems. In admin side.
I need to create a new table in mageno’s database. How i do that from here (from an action ):

class Name_Example_AdminControllersHere_TestController extends Mage_Adminhtml_Controller_Action
{
    
public function addtableAction()
    
{
           
///how i create a new table here?
        
}
      
public function getFromTableAction()
    
{
           
///how i get data from the table  $data =$some-> getData();
           ///how the .phtml file will reconize the array  $data ?
        
}
}
The 2’nd problem, of course is how i get some data from the created table and how i can display this data into .phtml file ?
Consider that i’m using the same controller but another action.
And how i can get the same data directly from .phtml file ?.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rich Cleverley
Sr. Member
 
Avatar
Total Posts:  284
Joined:  2009-01-20
 

Is there a specific reason why the table is created via the controller?  Usually you would have all your DB tables created/updtaed via your modules setup files (this helps because it uses the version of the module to work out whether the table should be created etc).

You’ll then need to create a model that will interact with the table and pull data ready for display.

Have a search for creating a module with a DB table which should give you more info on how it is done.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top