If you are new in Joomla and want to learn to develop a joomla componet.
You are on right place. I am trying to explain all steps with simple and easy example.
Scenerio:
Create a component to show product with image, product name and price on front end and can be managed from backend (Add a new product, Edit an existing product, Delete product)
Let’s start.
Step 1:
a) Create a folder anywhere in your pc and named it like com_product. Here prefix com indicates that it’s a package of a component.
b) Create a xml file under com_product folder named product.xml (com_product/product.xml) and paste following code into this xml file.
Explanation of this xml file:
Look at <extension type="component" version="2.5.0" method="upgrade">
If you see this line carefully, you can see that here type = “component”. It means this package is a component and developing this component for joomla version 2.5.
After that few lines are providing informations about author and component.
Location of this sql file: com_product/admin/sql/install.mysql.utf8.sql
Following is sql query need to write under install.mysql.utf8.sql file
DROP TABLE IF EXISTS `#__product`;
CREATE TABLE `#__ product ` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`prod_name` varchar(100) NOT NULL,
`prod_image` varchar(100) NOT NULL,
`prod_cost` varchar(100) NOT NULL,
`category` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
<install> node indicating that, when you install component then above mysql query runs and creates a table.
Similarly when you uninstall the component, mysql query under com_product/admin/ sql/uninstall.mysql.utf8.sql runs and drop the created table.
Put following query into uninstall.mysql.utf8.sql file
DROP TABLE IF EXISTS `#__product`;
Files: index.html, product.php, controller.php
Folders: views, models, controllers, images
Don’t care of content into these files and folders. You can keep blank all pages and empty all folders at this point.
Similarly
Create few files and folders according to above xml section.
Files: index.html ,product.php,controller.php
Folders: tables,models,views,controllers,sql
Files: en-GB.com_product.ini, en-GB.com_product.sys.ini
You are on right place. I am trying to explain all steps with simple and easy example.
Scenerio:
Create a component to show product with image, product name and price on front end and can be managed from backend (Add a new product, Edit an existing product, Delete product)
Let’s start.
Step 1:
a) Create a folder anywhere in your pc and named it like com_product. Here prefix com indicates that it’s a package of a component.
b) Create a xml file under com_product folder named product.xml (com_product/product.xml) and paste following code into this xml file.
<?xml version="1.0" encoding="utf-8"?><extension type="component" version="2.5.0" method="upgrade">
<name>My Product</name> <!-- The following elements are optional and free of formatting constraints --> <creationDate>April 2014</creationDate> <author>Mukesh Das</author> <authorEmail>mukeshdas1985@gmail.com</authorEmail> <authorUrl>http://www.dasnic.com</authorUrl> <copyright>Copyright Info</copyright> <license>License Info</license> <!-- The version string is recorded in the components table --> <version>0.0.1</version> <!-- The description is optional and defaults to the name --> <description>My Product Description You can write here description of you componet ...</description> <install> <!-- Runs on install --> <sql> <file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file> </sql> </install> <uninstall> <!-- Runs on uninstall --> <sql> <file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file> </sql> </uninstall> <update> <!-- Runs on update; New in 2.5 --> <schemas> <schemapath type="mysql">sql/updates/mysql</schemapath> </schemas> </update>
<!-- Site Main File Copy Section --> <files folder="site"> <filename>index.html</filename> <filename>product.php</filename> <filename>controller.php</filename> <folder>views</folder> <folder>models</folder> <folder>controllers</folder> <folder>images</folder> </files>
<administration> <!-- Administration Menu Section --> <menu>Das Product!</menu> <!-- Administration Main File Copy Section --> <files folder="admin"> <!-- Admin Main File Copy Section --> <filename>index.html</filename> <filename>product.php</filename> <filename>controller.php</filename> <folder>tables</folder> <folder>models</folder> <folder>views</folder> <folder>controllers</folder> <!-- SQL files section --> <folder>sql</folder> </files> <languages folder="admin"> <language tag="en-GB">language/en-GB/en-GB.com_product.ini</language> <language tag="en-GB">language/en-GB/en-GB.com_product.sys.ini</language> </languages> </administration>
</extension>
Explanation of this xml file:
Look at <extension type="component" version="2.5.0" method="upgrade">
If you see this line carefully, you can see that here type = “component”. It means this package is a component and developing this component for joomla version 2.5.
After that few lines are providing informations about author and component.
<install> <!-- Runs on install -->In product component, I need a database table to store data of product. So, write a mysql query to create a table into install.mysql.utf8.sql file.
<sql>
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
</sql>
</install>
<uninstall> <!-- Runs on uninstall -->
<sql>
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
</sql>
</uninstall>
Location of this sql file: com_product/admin/sql/install.mysql.utf8.sql
Following is sql query need to write under install.mysql.utf8.sql file
DROP TABLE IF EXISTS `#__product`;
CREATE TABLE `#__ product ` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`prod_name` varchar(100) NOT NULL,
`prod_image` varchar(100) NOT NULL,
`prod_cost` varchar(100) NOT NULL,
`category` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
<install> node indicating that, when you install component then above mysql query runs and creates a table.
Similarly when you uninstall the component, mysql query under com_product/admin/ sql/uninstall.mysql.utf8.sql runs and drop the created table.
Put following query into uninstall.mysql.utf8.sql file
DROP TABLE IF EXISTS `#__product`;
<files folder="site">Create a folder named site into com_product folder. Under site folder create few files and folders listed below:
<filename>index.html</filename>
<filename>product.php</filename>
<filename>controller.php</filename>
<folder>views</folder>
<folder>models</folder>
<folder>controllers</folder>
<folder>images</folder>
</files>
Files: index.html, product.php, controller.php
Folders: views, models, controllers, images
Don’t care of content into these files and folders. You can keep blank all pages and empty all folders at this point.
Similarly
<files folder="admin">Create admin folder under com_product, if not created.
<!-- Admin Main File Copy Section -->
<filename>index.html</filename>
<filename>product.php</filename>
<filename>controller.php</filename>
<folder>tables</folder>
<folder>models</folder>
<folder>views</folder>
<folder>controllers</folder>
<!-- SQL files section -->
<folder>sql</folder>
</files>
Create few files and folders according to above xml section.
Files: index.html ,product.php,controller.php
Folders: tables,models,views,controllers,sql
<languages folder="admin">Create again a folder “language” under admin folder (com_product/admin/language/) . Create a folder “en-GB” under language folder and create two files under en-GB folder
<language tag="en-GB">language/en-GB/en-GB.com_product.ini</language>
<language tag="en-GB">language/en-GB/en-GB.com_product.sys.ini</language>
</languages>
Files: en-GB.com_product.ini, en-GB.com_product.sys.ini
<menu>Das Product!</menu>This create a menu for this component into administrator of joomla.
I have explained everything under product.xml file.
I will explain about
all files and folders in next post.