I just can't understand the principle of loading views in a component.
For now I just want to load a different empty view when I click on the
Add new button of the default view.
Here's my very simple code:
my files:
admin.mycomponent.php
controller.php
views/mycomponent/view.html.php
views/mycomponent/tmpl/default.php
views/myview/view.html.php
views/myview/tmpl/default.php
admin.mycomponent.php
Code: Select all
<?php
defined('_JEXEC') or die('Restricted Access');
require_once(JPATH_COMPONENT.DS.'controller.php');
if($controller = JRequest::getWord('controller'))
{
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if(file_exists($path))
require_once $path;
else
$controller = '';
}
$classname = 'MyComponentController'.$controller;
$controller = new $classname();
$controller->execute(JRequest::getWord('task'));
$controller->redirect();
Code: Select all
<?php
defined('_JEXEC') or die('Restricted Access');
jimport('joomla.application.component.controller');
class MyComponentController extends JController
{
function display()
{
$view =& $this->getView( 'mycomponent', 'html' );
$view->display();
}
function add()
{
$view =& $this->getView( JRequest::getVar( 'view', 'myview' ), 'html' );
$view->add();
}
}
Code: Select all
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class MyComponentViewMyComponent extends JView
{
function display($tpl = null)
{
JToolBarHelper::title(JText::_('My Component'), 'generic.png');
JToolBarHelper::deleteList();
JToolBarHelper::editListX();
JToolBarHelper::addNewX();
parent::display($tpl);
}
}
Code: Select all
<?php
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<h1>My Component</h1>
Code: Select all
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class MyDmsViewMyView extends JView
{
function display($tpl = null)
{
JToolBarHelper::title( JText::_('"My Component - New"'), 'generic.png');
JToolBarHelper::save();
JToolBarHelper::apply();
JToolBarHelper::cancel();
parent::display($tpl);
}
}
Code: Select all
<?php
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<h1>My View</h1>
I click on the New button.
I probably missed something but I don't know what.
Can someone help me ?
Thanks for advance