Joomla 1.5 - Creating SQL tables in components - joomla

Joomla 1.5 has JTable, which can be extended to act as an Active Record system (Create/Read/Update/Delete).
However, I can not find any way for this interface to create the table represented by my JTable sub-class.
Every example I have found has started with "manually create the database tables... ", then created a JTable class to work with it. I would like to be able to distribute my plugin and have it create the tables on setup, so that this is not necessary.
Any easy way to do this?

This is usually done in the install.sql of your extension (The link is related to component but I guess for plugins it's the same).

Related

Is it advisible to add new table in Joomla?

I need to know if it is advisible to add new table in default database of Joomla. Will it be preserved if I update my Joomla.
If yes, then can anybody describe the steps?
Yes, you can add custom database tables if you wish, it doesn't pose any threats. Just make sure you use Joomla coding standards when getting or adding data from the table. More information on that can be found here:
http://docs.joomla.org/J2.5:Accessing_the_database_using_JDatabase
As for updating Joomla, yes, the table will be preserved.
Hope this helps
As already said, you can add any table you like to your Joomla database. Joomla doesn't care for tables it doesn't know. And those extra tables are not modified by an update.
BUT keep two things in mind:
1. If you make backups of your database with a joomla extension (such as lazyBackup) and you want to backup your extra-tables too, then make sure to include these extra tables by choosing the appropriate options in the backup extension. By default those extra table might not be included in your backup.
2. As you can easily see in phpMyAdmin all joomla tables start with a prefix such as he3ie_. This prefix is different on every joomla installation (if you did not choose your own). It is no good idea to start your extra tables with this prefix. This might collide with joomla-tables which could be created in the future (by joomla or by an extension).
as everybody said adding tables will not be affected by Joomla upgrades unless they decide to name a new table the same as yours. A table "name" could also clash with another extension that you want to install so it would be good advise to spend some time thinking on a name that will make sure is unique to your use or component.
Of course if this is a one-off custom thing then it matters less.
If you are looking for a more in-depth tutorial try this YouTube Video: http://www.youtube.com/watch?v=twT3q7dyVpI
Joomla update doesn't disturb your custom database tables or any other data. Just create the database as you want like phpmyadmin etc & use it without any fear.

adding data directly to a magento database

I am adding regions of a country to the database in Magento so when a user selects their country a relevant list of regions will be available in a drop down menu. To do this I believe I need to add information to directory_country_region and directory_country_region_name.
The tutorial I've been looking at states that I should add them directly to the database using sql, however I remember reading that you should not place information directly into the database using raw sql when working with Magento.
My questions are:
1- to keep in line with best practices do I need to use some magento functions to add the required information to my database or can they be dropped in using raw sql?
2- if I need to use some Magento functions how do I work out which I need to use (I have heard off and noticed the lack of documentation) or is there some online reference, even if it is limited?
3- if I am not to use a sql query why is it considered bad practice to do so in Magento?
Hello, if you want to add the information just once, you can use raw sql (faster and no drawbacks), also you are right about the 2 tables (if the country is already in directory_country). If you want to make something that will be available for more Magento instalations you have to crate a new Magento module and add the sql using the installer you can read more here http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-6-magento-setup-resources
Magento wiki is a good place to start, also there are lots of blog posts.
It's considered a bad practice because Magento has its own ORM and most of the time for your new tables (entities) you only need to create models that extend magento core models and you will have access to CRUD without any development and everyone that uses your new module will understaind what's going on.
Example for a region you can use the class Mage_Directory_Model_Region or for a collection of regions Mage_Directory_Model_Resource_Region_Collection

Joomla add component to database

I'm just starting out on a component for Joomla. I can't figure out how to add an entry in the dB so I can access the component.
I looked at the dB table for components, but some of the columns seem to require some specific info.
This is NOT a finished component, but a new one I want to build.
I am using Joomla 1.7.
take care,
lee
As Jogesh_p suggested, the easy way is to create an xml file like this
http://docs.joomla.org/Components:xml_installfile
If you are just starting out with Joomla development then take a look at the Hello World tutorial.
http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!2.5_-_Part_01
Another option to create a Joomla component quickly is to use EasyCreator, which will create the basic parts of the extension that you can then build on.

Joomla module/component for table administration

My client's website runs on Joomla and they would like me to add some custom functionality to the site.
It is a quotation system, so they will just need to be able to update the values that are used to caluclate the quote. So there would only need to be 4 parts to this:
Settings page in the admin section
Database table that stores the settings
Front end form
PHP script to process the form / query the database table
If I was not using a CMS I could easily accomplish this task but my client would like this system to be integrated with Joomla. Can anyone advise how I should approach this?
You should be able to accomplish this easily with Chronoforms and Chrono Connectivity from Chrono Engine. Use the Chronoforms to create the forms that access the data and Connectivity to display and edit the data.
Forms - http://extensions.joomla.org/extensions/contacts-and-feedback/forms/1508
Connectivity - http://extensions.joomla.org/extensions/directory-a-documentation/faq/5661
Try the Joomla Component Creator it will allow you to get started writing your logic.

Magento custom attributes failing to install

I followed the tutorial at http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/installing_custom_attributes_with_your_module step by step to make my module install a couple of custom attributes, using Magento CE 1.4. I get to see the custom attributes on the product edit page, but whenever I try to save them I get an SQL error complaining that column "myattrid" does not exist. I know that:
this column is part of the flat product tables and indeed, it is not there
a lot of people give the advice to create by hand, but this bypasses the point of automatic installation
Is the tutorial I followed outdated? If so, what extra steps do I need to take?
An alternative approach is outlined in this blog post. You could try that.
I agree that you should avoid creating the attributes manually, there are many keys, indexes and relationships that Magento needs to be aware of which might be bypassed if you go straight to the database.
HTH,
JD

Resources