Вы находитесь на странице: 1из 14

Joomla 1.

5 MVC Component
Version 1.0.0

Presented By,
DMSundaram
Revolution Team, Adodis

1. Model View Controller ( MVC )


 Model
- Encapsulates your application data, application flow and business
logic.
 View
- Extracts data from the model and format it for the presentation.
 Controller
- Direct application flow and receive input and translates it for the
Model and View.
Request

Controller

Model

View

Response

2. Installable File Structure ( ccVMFriends component)


ccvmfriends.xml
admin/
index.html
admin.ccvmfriends.php
config.xml
en-GB.com_ccvmfriends.ini
install.ccvmfriends.php
uninstall.ccvmfriends.php
install.mysql.sql
uninstall.mysql.sql
controllers/
index.html
codes.php
reports.php
savings.php
templates.php
models/
index.html
codes.php
reports.php
savings.php
templates.php
tables/
index.html
codes.php
savings.php
templates.php
views/
index.html
codes/
index.html
view.html.php
tmpl/
index.html
default.php
form.php
reports/
index.html
view.html.php
tmpl/
index.html
default.php

savings/
index.html
view.html.php
tmpl/
index.html
default.php
form.php
remainder.php
templates/
index.html
view.html.php
tmpl/
index.html
default.php
form.php
users/
index.html
view.html.php
tmpl/
index.html
default.php
form.php
site/
index.html
ccvmfriends.php
ccvmfriendscron.php
controller.php
en-GB.com_ccvmfriends.ini
assets/
index.html
ccstyle.css
images/
index.html
loading.gif
models/
index.html
ccvmfriends.php
views/
index.html
ccvmfriends/
index.html
view.html.php
tmpl/
index.html
default.php
discount.php

invitation.php
3. ccvmfriends.xml
<?xml version="1.0" encoding="utf-8"?>
 This is the xml version , it will come with all component xml file
<!DOCTYPE install SYSTEM "http://dev.joomla.org/xml/1.5/component-install.dtd">
 This is common for all component xml file.
<install type="component" version="1.5.0">
 Intimate this component for which version ( 1.0 or

1.5)

<name>ccVMFriends</name>
 This is the component name, this will come in the admin menu item, if we
access the component , joomla will find the com_ccvmfrinds/ folder.
<author>Chill Creations</author>
<creationDate>July 30, 2008</creationDate>
<authorEmail>extensions@chillcreations.com</authorEmail>
<authorUrl>http://www.extensions.chillcreations.com</authorUrl>
<version>1.0.0</version>
 Theses all are author related details and version of this component.
<!-- The description is optional and defaults to the name -->
<description>Virtuemart Friends Component for advanced discount management,
developed by Chill Creations.</description>
 This is the description about the component, it will display after the
installation success.
<languages folder="site">
<language tag="en-GB">en-GB.com_ccvmfriends.ini</language>
</languages>
 This is the language file for site ( front end), all language we should add
with this tag, in this example only English(Brittan) language file added
<installfile>install.ccvmfriends.php</installfile>
 This file will execute, when the time of install.

<uninstallfile>uninstall.ccvmfriends.php</uninstallfile>
 This file will execute, when the time of uninstall.

<!-- Site Main File Copy Section -->


<files folder="site">
<filename>ccvmfriends.php</filename>
<filename>ccvmfriendscron.php</filename>
<filename>controller.php</filename>
<filename>index.html</filename>
<filename>models/ccvmfriends.php</filename>
<filename>models/index.html</filename>
<filename>views/index.html</filename>
<filename>views/ccvmfriends/index.html</filename>

<filename>views/ccvmfriends/view.html.php</filename>
<filename>views/ccvmfriends/tmpl/default.php</filename>
<filename>views/ccvmfriends/tmpl/discount.php</filename>
<filename>views/ccvmfriends/tmpl/index.html</filename>
<filename>views/ccvmfriends/tmpl/invitation.php</filename>
<folder>assets/</folder>
</files>
 These files will store in front end, we have include all the files with in the
<filename> tag.
<administration>
<!-- Administration Menu Section -->
<menu>ccVMFriends</menu>
<languages folder="admin">
<language tag="en-GB">en-GB.com_ccvmfriends.ini</language>
</languages>
<!-- Administration Main File Copy Section -->
<files folder="admin">
<filename>admin.ccvmfriends.php</filename>
<filename>config.xml</filename>
<filename>index.html</filename>
<filename>install.ccvmfriends.php</filename>
<filename>install.mysql.sql</filename>
<filename>uninstall.ccvmfriends.php</filename>
<filename>uninstall.mysql.sql</filename>
<filename>controllers/codes.php</filename>
<filename>controllers/index.html</filename>
<filename>controllers/reports.php</filename>
<filename>controllers/savings.php</filename>
<filename>controllers/templates.php</filename>
<filename>models/codes.php</filename>
<filename>models/index.html</filename>
<filename>models/reports.php</filename>
<filename>models/savings.php</filename>
<filename>models/templates.php</filename>
<filename>tables/codes.php</filename>
<filename>tables/index.html</filename>
<filename>tables/savings.php</filename>
<filename>tables/templates.php</filename>
<filename>views/index.html</filename>
<filename>views/codes/index.html</filename>
<filename>views/codes/view.html.php</filename>
<filename>views/codes/tmpl/default.php</filename>
<filename>views/codes/tmpl/form.php</filename>
<filename>views/codes/tmpl/index.html</filename>
<filename>views/reports/index.html</filename>
<filename>views/reports/view.html.php</filename>

<filename>views/reports/tmpl/default.php</filename>
<filename>views/reports/tmpl/index.html</filename>
<filename>views/savings/index.html</filename>
<filename>views/savings/view.html.php</filename>
<filename>views/savings/tmpl/default.php</filename>
<filename>views/savings/tmpl/form.php</filename>
<filename>views/savings/tmpl/index.html</filename>
<filename>views/savings/tmpl/remainder.php</filename>
<filename>views/templates/index.html</filename>
<filename>views/templates/view.html.php</filename>
<filename>views/templates/tmpl/default.php</filename>
<filename>views/templates/tmpl/form.php</filename>
<filename>views/templates/tmpl/index.html</filename>
<filename>views/users/index.html</filename>
<filename>views/users/view.html.php</filename>
<filename>views/users/tmpl/default.php</filename>
<filename>views/users/tmpl/index.html</filename>
</files>
</administration>
 This is same for above, but it will store in the admin side
<install>
<sql>
<file charset="utf8" driver="mysql">install.mysql.sql</file>
</sql>
</install>
 This is the sql query file, will execute on the time of install. whatever the
tables needed for this component, we have to the query for that. But the table name
should be #__ for table prefix. Charset=utf means it will support for all
languaes.
<uninstall>
<sql>
<file charset="utf8" driver="mysql">uninstall.mysql.sql</file>
</sql>
</uninstall>
 This is the sql query file, will execute on the time of un install. whatever
the tables created when the installation time , we can delete that tables from this
file.
</install>

3. admin.ccvmfriends.php
defined('_JEXEC') or die('Restricted access');
 Every php file should have these lines in the beginning of the file, this is used for
security purpose
$controllerName = JRequest::getCmd( 'c', 'savings' );
 Get the controller name , if there is no controller name specified in the url, set to
default, here default controller is savings
JSubMenuHelper::addEntry(JText::_('CC_SAVINGS'),
'index.php?option=com_ccvmfriends', true);
JSubMenuHelper::addEntry(JText::_('CC_CODES'),
'index.php?option=com_ccvmfriends&c=codes');
JSubMenuHelper::addEntry(JText::_('CC_REPORT'),
'index.php?option=com_ccvmfriends&c=reports');
JSubMenuHelper::addEntry(JText::_('CC_TEMPLATES'),
'index.php?option=com_ccvmfriends&c=templates');
 This is used for display controller menu in the top of the component.

require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
$controllerName = 'ccVMFriendsController'.$controllerName;
 This line will include the controller file. In this case it will include the file
administrator/components/com_ccvmfriends/controllers/savings.php
$controller = new $controllerName();
 This line will create the object for the controller . In this case it will create the
object
$controller = new ccVMFriendsControllersavings();
$controller->execute( JRequest::getCmd('task') );
 this is used for get task value
$controller->redirect();
 This is used for set the controller.

4. controllers/savings.php
jimport('joomla.application.component.controller');
 This line will include the controller class file from the Joomla frame work
class ccVMFriendsControllersavings extends JController
{
}
 this is the savings controller class file extends from the base class JController
In this class name ccVMFriends means the component name, Controller is common
for all and savings means the current controller name.
For next codes controller it will be like
class ccVMFriendsControllercodes extends JController
{
}
function __construct( $config = array() )
{
parent::__construct( $config );
 This is the constructor for this class. Common for all controller class
$this->registerTask( 'unpublish',
'publish' );
$this->registerTask( 'add',
'edit' );
$this->registerTask( 'new',
'edit' );
$this->registerTask( 'apply', 'save' );
 this lines is for call the function for the mentioned task,
if the task is unpublish, it will call the publish function
if the task is add, it will call the edit function
}
function display()
{
 This function will execute , if the task is not assigned
JRequest::setVar( 'view', 'savings');
 This is used to intimate which view should call for display the output
parent::display();
 This will call the view files for output
}
JRequest::setVar( 'layout', 'form' );
 This is used to indimate which layout should call for output.

JRequest::setVar('hidemainmenu', 1);
 This line used to hide the all menus in the edit form, the below image show the
example , the menu will not be clickable.

$msg = JText::_( 'CC_MSG_CANCELED' );


$this->setRedirect( 'index.php?option=com_ccvmfriends&c=savings', $msg );
 This is used for redirect the page , with the message.
$model = $this->getModel('savings');
 This line is used for create object for savings model.
$model->store();
 This store function is written in the model file.

5. models/savings.php
jimport('joomla.application.component.model');
 This line will include the model class file from the Joomla frame work
class ccVMFriendsModelsavings extends JModel
{
}
 this is the savings model class file extends from the base class JModel
In this class name ccVMFriends means the component name, Model is common for
all and savings means the current model name.
For next codes model it will be like
class ccVMFriendsModelcodes extends JModel
{
}
 All database related code will come in the model file

5. tables/savings.php
class Tablesavings extends JTable
{
 This is the table class for savings controller, it is extends from JTable class.
Here Table is common for all table class and savings is the controller name.

var $id = null;


var $userid = null;
var $savings_total = null;
var $savings_percent = null;
var $discount_total = null;
var $discount_percent = null;
var $friends = null;
var $remainder=null;
var $max_invitation = null;
var $state=null;
 All fields in the savings table should initiate here.
function Tablesavings(& $db) {
parent::__construct('#__ccvmf_savings', 'id', $db);
}
 This is the constructor for table class, which intimate id is the primary and auto
increment value.
}

6. views/savings/view.html.php
jimport( 'joomla.application.component.view' );
 This line will include the view class file from the Joomla frame work
class ccVMFriendsViewsavings extends JView
{
}
 this is the savings view class file extends from the base class JView
In this class name ccVMFriends means the component name, View is common for
all and savings means the current view name.
For next codes view will be like
class ccVMFriendsViewcodes extends JView
{
}
 This is used to get the all the information for providing to output, and it will
decide which layout should display.
JToolBarHelper::title( JText::_( 'CC_VMFRIENDS' ) . ' - ' .
JText::_( 'CC_SAVINGS' ), 'generic.png' );
JToolBarHelper::custom('publish', 'publish', '',
JText::_( 'CC_ENABLED' ), true);
JToolBarHelper::custom('unpublish', 'unpublish', '',
JText::_( 'CC_DISABLED' ), true);
JToolBarHelper::editListX();
JToolBarHelper::preferences('com_ccvmfriends', '500');
JToolBarHelper::custom('update', 'apply', '',
JText::_( 'CC_UPDATE_NOW' ), false);
JToolBarHelper::help( 'screen.savings' );
 This will display the toolbar and title of the componet for the particular page.
E.g., below

$context = 'com_ccvmfriends.s.userid.list.';
$filter_order
= $mainframe->getUserStateFromRequest( $context.'filter_order',
'filter_order',
's.id', 'cmd' );
$filter_order_Dir
= $mainframe->getUserStateFromRequest(
$context.'filter_order_Dir', 'filter_order_Dir', '',
'word' );
$filter_state
= $mainframe->getUserStateFromRequest( $context.'filter_state',
'filter_state',
'',
'word' );
$search
= $mainframe->getUserStateFromRequest( $context.'search',
'search',
'',
'string' );
 These lines are used for get the filter the result and get the order to display the
result.

$limit

= $mainframe->getUserStateFromRequest(
'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest(
$context.'limitstart', 'limitstart', 0, 'int' );
 These lines are used to get the limit and limit start of the result

jimport('joomla.html.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
 These lines are used for display the pagination of the result

7. views/savings/tmpl/default.php
 If the layout is not defined , it will call the default file for output
echo JHTML::_('grid.sort', JText::_( 'CC_CLIENT' ), 'u.name', @$this->lists['order_Dir'],
@$this->lists['order'] );
 this line is used for display the title of the result, it will be clickable for sorting the
order by the title. The below example show the title bar

echo $this->pageNav->getListFooter();
 This line is used for display the footer pagination and for select the limit of the
result. Example is below

8. Predefined Joomla Functions and Variables


 defined('_JEXEC') or die('Restricted access');
 Every php file should have this line in the beginning for the file.


getVar($name , $default, $hash, $type, $mask);

 This is used for the get the value from GET or POST method
Here
$name => variable name
$default => default value, If the vraible is not set
$hash => GET, POST, COOKIE, FILE
$type => int, String, array, float
$mask => JREQUEST_NOTRIM, JREQUEST_ALLOWHTML,
JREQUEST_ALLOWRAW


JHTML::script('mootools.js', JURI::base() .'/media/system/js/');

 Include the javascript file in the header




JHTML::stylesheet('ccstyle.css', JURI::base() .
'/components/com_ccvmfriends/assets/');

 Include the css file in the header




DS
 Directory Separator

JURI:root()
 http://localhost/joomla/

JPATH_ROOT
 D:\Program Files\Apache Group\Apache2\htdocs\projects\joomla\

JPATH_BASE
 D:\Program Files\Apache
Group\Apache2\htdocs\projects\joomla\administraor\

JPATH_SITE
 D:\Program Files\Apache Group\Apache2\htdocs\projects\joomla\

JPATH_ADMINISTRATOR
 D:\Program Files\Apache
Group\Apache2\htdocs\projects\joomla\administraor\

JPATH_COMPONENT
 D:\Program Files\Apache
Group\Apache2\htdocs\projects\joomla\components\com_ccvmfriends\

JURI::base()
 http://localhost/joomla/administrator/

$mainframe->getCfg(mailfrom);
 used to get the value of the configuration

$db-> & JFACTORY::getDBO();


 create object for database fro execute query

$query = SELECT * FROM #__users;


$db->setquery($query);
$rows = $db->loadObjectList();
 This is used for get more than one records.

$query = SELECT * FROM #__users WHER id=62 ;


$db->setquery($query);
$row = $db->loadObject();
 This is used for get only one record.

$query = SELECT count(*) FROM #__users ;


$db->setquery($query);
$row = $db->loadResult();
 This is used for get only one value.

$user = & JFACTORY::getUser();


 Create the object for user class for get the user information

$user->id;
$user->get(id);
$user->email;
 Get the User id , email,.

Вам также может понравиться