1.    Go to http://www.alphaplug.com and download MVC
2.    Install in your joomla from extinction directory
3.    www\Joomla_2.5\administrator\components\com_yourname\ views\yourname
a.    there are tmpl folder exit
b.    view.html is exit
4.    open tmpl folder and edit default.php with your editor and replace with this one
<?php
/**
* @version         pricus $
* @package        pricus
* @copyright    Copyright © 2012 – All rights reserved.
* @license        GNU/GPL
* @author        bhavesh
* @author mail    bhavesh.k@pricus.com
* @website        http://google.com
*
*
* @MVC architecture generated by MVC generator tool at http://www.alphaplug.com
*/// no direct access
defined(‘_JEXEC’) or die(‘Restricted access’);

// Your custom code here
JHtml::_(‘behavior.tooltip’);
JToolBarHelper::title(   JText::_( ‘Pricus’ ), ‘generic.png’ );
JToolBarHelper::addNewX();
JToolBarHelper::editListX();
JToolBarHelper::deleteList();
?>
<form action=”<?php echo JRoute::_(‘index.php?option=com_pricus’); ?>” method=”post” name=”adminForm” id=”adminForm”>
<table>
<thead>
<tr>
<th width=”20″ ><input type=”checkbox” name=”toggle” value=”” onclick=”checkAll(<?php echo count($this->items); ?>);” />
</th>
<th>Firstname</th>
<th>Laststname</th>
<th>Mobile No</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach($this->items as $i => $item): ?>
<tr>
<td><?php echo JHtml::_(‘grid.id’, $i, $item->id); ?></td>
<td><?php echo $item->fname; ?></td>
<td><?php echo $item->lname; ?></td>
<td><?php echo $item->mno; ?></td>
<td><?php echo $item->date_added; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<td colspan=”9″><?php echo $this->pagination->getListFooter(); ?></td>
</tr>
</tfoot>
</table>
<input type=”hidden” name=”option” value=”com_pricus” />
<input type=”hidden” name=”task” value=”” />
<input type=”hidden” name=”boxchecked” value=”0″ />
<input type=”hidden” name=”view” value=”pricus” />
</form>

And replace com_pricus with your com_yourname

5.    open view.html and replace with this code
<?php
/**
* @version         pricus $
* @package        pricus
* @copyright    Copyright © 2012 – All rights reserved.
* @license        GNU/GPL
* @author        bhavesh
* @author mail    bhavesh.k@pricus.com
* @website        http://google.com
*
*
* @MVC architecture generated by MVC generator tool at http://www.alphaplug.com
*/// no direct access
defined(‘_JEXEC’) or die(‘Restricted access’);

jimport( ‘joomla.application.component.view’ );

class pricusViewPricus extends Jview
{
function display($tpl = null)
{
// Get data from the model
$items = $this->get(‘Items’);

//$model =& $this->getModel(‘firstcomponent’);
//$datas = $model->getListAll();

$pagination = $this->get(‘Pagination’);
// Check for errors.
if (count($errors = $this->get(‘Errors’)))
{
JError::raiseError(500, implode(‘<br />’, $errors));
return false;
}
// Assign data to the view
$this->items = $items;

$this->pagination = $pagination;

// Display the template

parent::display($tpl);
}

}
?>
6.    \components\com_yourname\models and oprn this yourname.php file
<?php
/**
* @version         pricus $
* @package        pricus
* @copyright    Copyright © 2012 – All rights reserved.
* @license        GNU/GPL
* @author        bhavesh
* @author mail    bhavesh.k@pricus.com
* @website        http://google.com
*
*
* @MVC architecture generated by MVC generator tool at http://www.alphaplug.com
*/// no direct access
defined(‘_JEXEC’) or die(‘Restricted access’);

jimport(‘joomla.application.component.modellist’);

class pricusModelPricus extends JModelList
{
function __construct(){
parent::__construct();
}
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select(‘id,fname,lname,mno,date_added’);
// From the hello table
$query->from(‘#__test’);
return $query;
}

function getListAll(){

$db =& JFactory::getDBO();
$query = ‘SELECT * FROM `#__test` order by fname asc’;
$db->setQuery( $query );
$data = $db->loadAssocList();

return $data;
}

function remove()
{
$db =& JFactory::getDBO();
$cid = JRequest::getVar( ‘cid’ , array() , ” , ‘array’ );
JArrayHelper::toInteger($cid);

if (count( $cid ))
{
$cids = implode( ‘,’, $cid );

$query = ‘DELETE FROM #__test’    . ‘ WHERE id IN ( ‘. $cids .’ )’;
$db->setQuery( $query );

if (!$db->query())
return false;
else
return true;

}
}

function add_data()
{
$fname = $_POST[‘fname’];
$lname = $_POST[‘lname’];
$mno = $_POST[‘mobileno’];

$db =& JFactory::getDBO();
$query = “INSERT INTO `#__test` (`fname`, `lname`, `mno`, `date_added`) VALUES (‘”.$fname.”‘, ‘”.$lname.”‘, ‘”.$mno.”‘, NOW());”;
$db->setQuery( $query );

if (!$db->query())
return false;
else
return true;

}

function update_data()
{
$fname = $_POST[‘fname’];
$lname = $_POST[‘lname’];
$mno = $_POST[‘mobileno’];
$id = $_POST[‘id’];

$db =& JFactory::getDBO();
$query = “UPDATE `#__test` set `fname` = ‘”.$fname.”‘, `lname` = ‘”.$lname.”‘, `mno` = ‘”.$mno.”‘, `date_added` = NOW() WHERE id = ‘”.$id.”‘”;

$db->setQuery( $query );

if (!$db->query())
return false;
else
return true;
}
}
?>
Nore :- class name have to change with your name

7.    And now go on controller.php

And replace with this code
<?php
/**
* @version         pricus $
* @package        pricus
* @copyright    Copyright © 2012 – All rights reserved.
* @license        GNU/GPL
* @author        bhavesh
* @author mail    bhavesh.k@pricus.com
* @website        http://google.com
*
*
* @MVC architecture generated by MVC generator tool at http://www.alphaplug.com
*/// no direct access
defined(‘_JEXEC’) or die(‘Restricted access’);

jimport(‘joomla.application.component.controller’);

class pricusController extends JController
{
/**
* Custom Constructor
*/

function __construct()
{
parent::__construct();
}
function display($cachable = false)
{

// set default view if not set
JRequest::setVar(‘view’, JRequest::getCmd(‘view’, ‘pricus’));

// call parent behavior
parent::display($cachable);
}

function remove()
{
$model =& $this->getModel(‘pricus’);
if($model->remove()){
$msg = JText::_( ‘Data Delete Sucessfully!’ );
}
else {
$msg = JText::_( ‘Error Delete Data !!’ );
}
$return = ‘index.php?option=com_pricus’;
$this->setRedirect($return,$msg);
}

function add()
{
JRequest::setVar( ‘view’, ‘pricus_add’ );
JRequest::setVar(‘hidemainmenu’, 1);
parent::display();
}
function edit()
{
JRequest::setVar( ‘view’, ‘pricus_add’ );
JRequest::setVar(‘hidemainmenu’, 1);
parent::display();
}

function add_data()
{
$model =& $this->getModel(‘pricus’);

if($model->add_data())
{
$msg = JText::_( ‘Data Saved Sucessfully!’ );
}
else
{
$msg = JText::_( ‘Error Saving Data !!’ );
}
$return = ‘index.php?option=com_pricus’;
$this->setRedirect($return,$msg);

}

function updateData()
{
$model =& $this->getModel(‘pricus’);

if($model->update_data())
{
$msg = JText::_( ‘Data Saved Sucessfully!’ );
}
else
{
$msg = JText::_( ‘Error Saving Data !!’ );
}
$return = ‘index.php?option=com_pricus’;
$this->setRedirect($return,$msg);
}

function cancel()
{
$msg = JText::_( ‘Operation Cancelled’ );
$this->setRedirect( ‘index.php?option=com_pricus’, $msg );
}
}
?>
8.    Now add new view in your component when user click on add button
a.    \www\Joomla_2.5\administrator\components\com_youname\views\addyourviewfolder
b.    Your view folder have one view.html and and one tmpl folder
c.    Open view.html and replace with this one

defined(‘_JEXEC’) or die(‘Restricted access’);jimport( ‘joomla.application.component.view’ );

class pricusViewPricus_add extends Jview
{
function _display($tpl = null){
// global $mainframe;
parent::display($tpl);

}}

d.    Open default.php in your tmpl folder in your new view
<?php/**
* @version        1.0.0 firstcomponent $
* @package        firstcomponent
* @copyright    Copyright © 2012 – All rights reserved.
* @license        GNU/GPL
* @author
* @author mail    nobody@nobody.com
*
*
* @MVC architecture generated by MVC generator tool at http://www.alphaplug.com
*/

// no direct access
defined(‘_JEXEC’) or die(‘Restricted access’);
JHtml::_(‘behavior.tooltip’);
JHtml::_(‘behavior.formvalidation’);
JHtml::_(‘behavior.keepalive’);
$getCid = JRequest::getVar(‘cid’);
$isNew  = ($getCid[0] < 1);
$text = $isNew ? JText::_( ‘New’ ) : JText::_( ‘Edit’ );

JToolBarHelper::title(   JText::_( ‘Add Data’ ).’: <small><small>[ ‘ . $text.’ ]</small></small>’ );

if ($isNew){
JToolBarHelper::save(‘add_data’);
JToolBarHelper::cancel();
}else{
JToolBarHelper::save(‘updateData’);
JToolBarHelper::cancel(‘cancel’, ‘JTOOLBAR_CLOSE’);
}

$this->assignRef(‘getCid’, $getCid);
$cid = $this->getCid;
$id = $cid[0];
$db =& JFactory::getDBO();
$query = “SELECT * FROM `#__test` WHERE `id`=’$id'”;
$db->setQuery( $query );
$res = $db->loadAssoc();

?>
<form action=”<?php echo JRoute::_( ‘index.php?option=com_pricus’ );?>” method=”post” name=”adminForm” id=”adminForm”  >
<table >
<tbody>
<tr>
<td><strong><?php echo JText::_(‘FirstName’); ?>:-</strong></td>
<td><input type=”text” name=”fname” id=”fname” class=”” value=”<?PHP  echo $res[‘fname’]; ?>” /></td>
</tr>
<tr>
<td><strong><?php echo JText::_(‘Lastname’); ?>:-</strong></td>
<td><input type=”text” name=”lname” id=”lname” class=””  value=”<?PHP  echo $res[‘lname’]; ?> “/></td>
</tr>
<tr>
<td><strong><?php echo JText::_(‘Mobile No’); ?>:-</strong></td>
<td><input type=”text” name=”mobileno” id=”mobileno” class=””  value=”<?PHP  echo $res[‘mno’]; ?>”/></td>
</tr>
</tbody>
</table>
<input type=”hidden” name=”option” value=”com_pricus” />
<?php if(($getCid)){ ?>
<input type=”hidden” value = <?php echo $id ; ?> name=”id”/>
<?php }?>
<input type=”hidden” name=”boxchecked” value=”0″ />
<input type=”hidden” name=”task” value=”” />
</form>

9.    SQL Dump

— phpMyAdmin SQL Dump
— version 3.4.10.1
http://www.phpmyadmin.net

— Host: localhost
— Generation Time: Jul 17, 2012 at 11:11 AM
— Server version: 5.5.20
— PHP Version: 5.3.10

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;
SET time_zone = “+00:00”;

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

— Database: `testjoomladb`

— ——————————————————–

— Table structure for table `tbl_test`

CREATE TABLE IF NOT EXISTS `tbl_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fname` varchar(255) NOT NULL,
`lname` varchar(255) NOT NULL,
`mno` varchar(255) NOT NULL,
`date_added` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=45 ;


— Dumping data for table `tbl_test`

INSERT INTO `tbl_test` (`id`, `fname`, `lname`, `mno`, `date_added`) VALUES
(12, ‘bhavesh’, ‘bhavesh    ‘, ‘bhavesh’, ‘2012-07-13 16:54:35’),
(27, ‘paras’, ‘patel’, ‘8974561238’, ‘2012-07-12 19:54:08’),
(29, ‘navbin’, ‘patel ‘, ‘7889456456’, ‘2012-07-13 13:52:39’),
(30, ‘php’, ‘joomla’, ‘89745613235’, ‘2012-07-12 19:54:50’),
(31, ‘magento 123’, ‘phpjoomla ‘, ‘78945612325’, ‘2012-07-12 20:14:25’),
(34, ‘santanusir’, ‘dsakdjskaj’, ‘78978465’, ‘2012-07-13 11:22:12’),
(36, ‘dsfsdf’, ‘bhavesh ‘, ‘10000’, ‘2012-07-13 17:30:41’),
(37, ‘89999’, ‘ 9999’, ‘999’, ‘2012-07-13 17:32:19’),
(38, ‘rushin’, ‘khanpara’, ‘98981922487’, ‘2012-07-13 18:56:59’),
(39, ‘gfdgdf’, ‘gfdgd’, ‘gdfg’, ‘2012-07-13 20:06:56’),
(43, ‘ganga’, ‘ganga’, ‘ganga’, ‘2012-07-17 16:38:36’),
(44, ‘ffffff’, ‘ fffff’, ‘6767676767’, ‘2012-07-17 16:38:55’);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Advertisements