How to create Joomla component step by step - 2

Lets start from site folder. Site folder and its content is using for front end development of this component and admin folder is using for backend development of this component.
Site:
1         Index.html: Create this page and Don’t write anything into it. This page is using for security purpose. No body can access site folder directly.

2       Controller.php:
This is one of the most important pages of this controller. It controls the flow of this component.
Write following code into this php page:

<?php
/**
 * Product Controller page
 * @author                         Mukesh Das

 * @license                          License GNU General Public License version 2 or later
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla controller library
jimport('joomla.application.component.controller');

/**
 * Front Component Controller
 */
class ProductController extends JController
{
}

Here I have created a controller (<COMPONENT NAME>Controller). Here component name is product and this class is extended by JController class.
3.       Product.php:
Write following code:

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');

$controller = JController::getInstance('Product');
/*
In above line, you have created an instance of class ProductController. In above line, you see only Product. It is not any mistake. Joomla automatically append controller. So, Finally its not Product. It is ProductController.
*/
$controller->execute(JRequest::getCmd('task'));
/*
In above line, if controller find any task, then controller execute and redirect to that task.
I am explaining in details below by example.
*/
$controller->redirect();

?>

I am explaining by an example, that how a controller takes action on task.
Open controller.php page again and replace  content by following code:

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');
class ProductController extends JController{
               
                function create(){
                                echo 'Welcome to create a product Task';
                }
               
                function delete(){
                                $app = JFactory::getApplication();
                                $id = JRequest::getInt('id');
                                echo 'Welcome to delete a product By Id  '.$id;
                                $app->close();
                }
}
?>

What did I do? I have created two functions create and delete into this class.
Now Its time to test this component.

Firstly zip component folder and install it from administrator.
If component installed successfully, Then you are ready to test.

Open following link on browser:
YOUR_WEBSITE_URL/index.php?option=com_product&task=create
When you open this link, then controller finds that you are requesting a task. In product.php page, you have created an instance of controller.php. If instance get that a function is available with the same name as task. For example, here task = create. It means, if instance finds a function name create into ProductController class. Then this function will be executed.
You get output like below:
Welcome to create a product Task

Next Open following link
YOUR_WEBSITE_URL/index.php?option=com_product&task=delete
Output:
Welcome to delete a product By Id 

Next Open following link
YOUR_WEBSITE_URL/index.php?option=com_product&task=delete&id=5
Output:
Welcome to delete a product By Id 5

What difference you get, when open these link?
When you open first link, you get output on running template. But for other link, you get output without any template. I mean  a single line output on full white page.

Why did you get white page when run delete task?
$app = JFactory::getApplication();
$app->close();
Here you have closed this application, that why template is disabled for this task.
If you remove above code, then you can see graphics like create task.
You can use this feature for ajax call. I will explain later.
Now again run following link
YOUR_WEBSITE_URL/index.php?option=com_product
Here you are not assigning any task, then controller searches for default view. But you have not created any view this time. So, It throws an error of page not found.
You can remove this problem by creating a function named display.
  function display(){
                                echo ‘I am without task';
                }
Now again run following link
YOUR_WEBSITE_URL/index.php?option=com_product
You will get output
I am without task.

If you run without task, then controller runs display function always.
I have explained controller.php,product.php page.
Now I move to controllers folder.
You have learnt default controller. This is time to know about subcontrollers. As you have created many task into controller.php and use it.

Similarly, you can create many sub controllers for different task.
Read More

How to create Joomla component step by step

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.

<?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 -->
<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>
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.

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">
<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>
Create a folder named site  into com_product  folder. Under site folder create few files and folders listed below:
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">
<!-- 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 admin folder under com_product, if not created.
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">
<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>
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
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.


Read More

Not Found The requested URL was not found on this server

Sometimes, when you migrate a website from other server to your local server for testing or development and try to run this on browser.

You get an error message like
Not Found
The requested URL was not found on this server
Not Found The requested URL was not found on this server


You check all configurations. Everything is OK in all configuration files of your website. But still you get same error message.

Actually i faced this issue when i run my website on newly installed wamp server. I have searched on google. After spending long time i got a solution and i want to share with you.

It's very simple. I am sharing you two methods. Check which one is working for you.

Method 1.

In apache folder, open httpd.conf file and search following line

#LoadModule rewrite_module modules/mod_rewrite.so

Remove # from the beginning of the line, after removing # line will look like this:

LoadModule rewrite_module modules/mod_rewrite.so


If above method didn't work for you then try method 2.

Method 2.

Change this

Include conf/extra/httpd-vhosts.conf
to

#Include conf/extra/httpd-vhosts.conf
and restart all services


I am sure your issue will be solved...


Read More

How to Make Home Security System Using Mobile

2 Comments
The project is about a home security system in which a cell phone is used as a device that will alert the owner of the house when an intruder enters the house.
The owner just have to turn on the system before leaving his house.When an intruder enters the house in the absence of the owner the owner receives a call from a registered number which is the phone number of the hacked mobile phone at his/her house.

Now go to step and you need to do carefully :
  • Circuit Diagram :

Cell phones have switches which when pressed short the terminals (gold plated) hence a number is seen on the screen so what i have done is put my cell phone number on speed dial on the phone i hacked and when this number is pressed for a while i get a call.
So basically what we r doing is a circuit that will short the phone terminals. when a intruder enters the house.

IC LM358 is a dual op amp.

The output of an op amp is difference of the input times the gain of the op amp. ie. it compares the 2 inputs.

NOTE: Refer datasheet for ore details about the IC.

pin 2 of IC 358 is threshold a potentiometer is connected to it so it forms a voltage divider and a particular voltage is set up at pin 2 which the op amp compares with voltage at pin 3.

To pin 3 an LDR is connected it behaves in following way.

  1. When light shines on LDR its resistance decreases hence a more positive voltage is set up at pin 3 which forces the output to be high.hence there is a potential difference at the terminals of the number on the cell phone.
  2. When the light is cut off by the door which is opened by the intruder the LDR resistance increases hence a more negative voltage is set up at pin 3 which forces output to be low (0v).

In the equivalent op amp circuit shown Avid is approximately 0v when output is low and resistance Ro is very small hence the output is shorted to the ground thus shorting the 2 terminals of the cell phone.

  • Requirement :
  1. A Cellphone having press buttons (i used an old one which i had).
  2. A 10K ohm resistor.
  3. A 10K ohm potentiometer.
  4. An LDR (Light Dependent Resistor) 10K ohm or A 2 legged IR sensor (IR sensors are better bcoz they are not affected by surrounding light).
  5. An LM358 (Dual op-Amp) IC.
  6. An Optical LASER (I used a red LASER). In case you are using IR sensors use an IR LASER.
  7. Wires.
  • Do with your old mobile :
The cell phone i used is an old nokia phone.

Remove the battery then remove the front cover then the keypad an then the transparent cover over the keys.
You will see a thin white film on the key terminals dont worry just remove this film using a forceps but remember only cut the film on a key from 0 to 9. I just pulled it out in excitement and now i have problems starting the device i have to manually start it by shorting the terminals using any metallic object.
  • Check the polarities :
Insert the battery back into the cell phone and turn it on.

I wanted to use key 3 for the speed dial so i was checking the terminals on key 3.
Put a multimeter on dc voltage measurement then touch the probes to the 2 terminals on the key then reverse the probes on the key terminals either way the multimeter will show a reading but it will show +ve DC voltage when the probes are on correct -ve ,+ve terminals.

In my case the inner one was positive and the outer one negative.

Solder a red wire to the +ve terminal and a black wire to the -ve terminal.
  • Soldering the wires :
According to the circuit diagram solder the circuit.a small dotted board is enough as there are hardly any components.

NOTE: the circuit remains same if a 2 legged IR sensor is used.
Solder the red wire from the cell phone key to the output of the op-amp IC ie. at pin 1 and the black wire to the ground.

Solder the LDR to a small piece of board and solder wires to it (LDR does not have polarity so it can be connected any way to the main board).
  • Power Supply :
Use a cell phone charger just cut the jack and solder 2 wires to it which will be connected to the main circuit board.
  1. Red one is +ve (Vcc on circuit diagram).
  2. Black one is -ve (Ground on circuit diagram).
  • Placing the Circuit :
Place the sensor and LASER on opposite sides of a door.

focus the LASER on the Sensor such that LASER falls on the sensor when door is closed and it is cut off from the sensor when door is open.

Insert any sim card into the cell phone and register its number on your cell phone as 'security' or anything you like.insert the battery and turn the cell phone on.

turn on the power supply to the circuit.
  • Calibrating the circuit :



Read More