ah, ich glaube ich habs selbst gefunden:
PHP-Code:
&$this->getModel(ScreenshotuploaderModelScreenshotuploader)
könnte mir aber vielleicht jemand verraten warum es "&$this" statt "$this" heißt?
edit:
okay, habe das hier gelesen: http://docs.joomla.org/Using_multipl..._MVC_component aber es klappt trotzdem nicht. Daher hier mal mein Code:
Controller
PHP-Code:
<?php
/*
* controller
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
/**
* Component Controller
*/
class ScreenshotuploaderController extends JController
{
/**
* Method to display the view
*
* @access public
*/
function display()
{
if (JRequest::getVar('view') == "success") {
$view = &$this->getView( 'success', 'html' );
$view->setModel($this->getModel( 'Screenshotuploader' ), true );
$view->display();
} else {
parent::display();
}
}
function save()
{
//do validation
$this->setRedirect("index.php?option=com_screenshotuploader&view=success");
$this->redirect();
}
}
?>
Default View
PHP-Code:
<?php
/*
* default view
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class ScreenshotuploaderViewScreenshotuploader extends JView
{
function display()
{
$model = $this->getModel();
$usertype = $model->isAuthorizedUser();
$this->assignRef( 'usertype', $usertype );
parent::display();
}
}
?>
Template for Default View
PHP-Code:
<?php
/*
* template for default view
*/
// no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<h1>Screenshot Uploader</h1>
<ul>
<form action='index.php?option=com_screenshotuploader' method='POST' enctype='multipart/form-data'>
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">
<input type="hidden" name="task" value="save">
<label>Upload your file: </label>
<input type='file' name='uploadedfile'><p>
<label>Enter set name: </label>
<input type='text' name='setname'><p>
<label>Enter game id: </label>
<input type='text' name='gameid'><p>
<input type='submit' value='Upload'>
</form>
</ul>
<?php
if ($this->usertype === true) {
echo "This is a super user";
}
?>
Success View
PHP-Code:
<?php
/*
* success view
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class ScreenshotuploaderViewSuccess extends JView
{
function display()
{
// $this->setModel("ScreenshotuploaderModelScreenshotuploader", true, "ScreenshotuploaderModelScreenshotuploader");
$usertype = $model->isAuthorizedUser();
$this->assignRef( 'usertype', $usertype );
// parent::display();
}
}
?>
Template for Success View
PHP-Code:
<?php
/*
* template for success view
*/
// no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<h1>Screenshot Uploader</h1>
<ul>
<?php
if ($this->usertype === true) {
echo "This is a super user";
}
?>
</ul>
Model
PHP-Code:
<?php
/*
* model
*/
//No direct access
defined('_JEXEC') or die();
jimport('joomla.application.component.model');
class ScreenshotuploaderModelScreenshotuploader extends JModel {
function __construct()
{
parent::__construct();
}
function isAuthorizedUser(){
$db = $this->getDBO();
$user =& JFactory::getUser();
$usertype = $user->get('usertype');
if ($usertype === "Super Administrator") {
return true;
}
return false;
}
}
?>
Lesezeichen