I haven't got so much skill, but I tried to make a Game Serverstatus Page but i didn't found something to assign any variable to the template :o
isn't this right? : WCF::getTPL()->assign('test', 'My Test Text');
Sorry
I haven't got so much skill, but I tried to make a Game Serverstatus Page but i didn't found something to assign any variable to the template :o
isn't this right? : WCF::getTPL()->assign('test', 'My Test Text');
Sorry
ok thanks for your fast reply, and then i get them how? (in the template) with {$item1} and {$item2} ?
Right
Add a @ before the dollar sign to get it as HTML -> {@$item1}
ah okay thanks unfortunately i have to go off for today, will try it tomorrow
I tested but it doesn't work. ...don't know what im doing wrong.
if I understood it, then in the class i generate the wanted content and in the template i can make the output.
I tried this:
<?php
// wcf imports
require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
/**
* Minecraft ServerStatus
*
* @author Sorry
* @copyright fightcraft.de
* @package no
* @license ask admin@fightcraft.de
*/
class ServerStatusPage extends AbstractPage {
// system
public $templateName = 'serverstatus';
function __construct() {
parent::__construct();
//$error = 'error';
//$item1 = 'item1';
//$item2 = 'item2';
$item1 = 'test';
$item2 = 'test';
WCF::getTPL()->assign(array(
'item1' => $item1,
'item2' => $item2
));
}
}
Display More
and this:
<?php
// wcf imports
require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
/**
* Minecraft ServerStatus
*
* @author Sorry
* @copyright fightcraft.de
* @package no
* @license ask admin@fightcraft.de
*/
class ServerStatusPage extends AbstractPage {
// system
public $templateName = 'serverstatus';
//$error = 'error';
//$item1 = 'item1';
//$item2 = 'item2';
$item1 = 'test';
$item2 = 'test';
WCF::getTPL()->assign(array(
'item1' => $item1,
'item2' => $item2
));
}
Display More
both does not work...
but in the first code i get this error: PHP notice in file C:\xampp\htdocs\wbb\wcf\templates\compiled\48_0_1_serverstatus.php (47): Undefined index: item1, in the second i get this: Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in C:\xampp\htdocs\wbb\lib\page\ServerStatusPage.class.php on line 23
so the first one seem to be better....
You don't have to use the constructor anymore, because you extend from the AbstractPage, which already has a constructor.
You class could look like this:
<?php
// wcf imports
require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
/**
* Minecraft ServerStatus
*
* @author Sorry
* @copyright fightcraft.de
* @package no
* @license ask admin@fightcraft.de
*/
class ServerStatusPage extends AbstractPage {
// system
public $templateName = 'serverstatus';
/**
* @see Page::readData()
*/
public function readData() {
$item1 = 'test';
$item2 = 'test';
parent::readData();
}
/**
* @see Page::assignVariables()
*/
public function assignVariables() {
WCF::getTPL()->assign(array(
'item1' => $item1,
'item2' => $item2
));
parent::assignVariables();
}
}
?>
Display More
okay thank you... and where can i look up which functions names (example: public function readData()) i have to use?
AbstractPage or AbstractForm, depends on which class you extend from
there shouldn't be any user input. so I think AbstractPage should be right.
i tried what you wrote but then i get this error:
error message: PHP notice in file C:\xampp\htdocs\wbb\lib\page\ServerStatusPage.class.php (32): Undefined variable: item1
again PHP notice in file C:\xampp\htdocs\wbb\lib\page\ServerStatusPage.class.php (32): Undefined variable: item1
Won't work. The problem is: Variables defined within ServerStatusPage::readData() aren't available within ServerStatusPage::assignVariables(). Either you have to use class variables or define the variables within ServerStatusPage::assignVariables() itself.
By the way: The problem with the version with your code within the constructor was: Your methoed calls the parent method before its own stuff is done. So the parent constructor method calls alle the class methods and tries to display the template. I recommed some learing of OOP, because this stuff is pretty common within WCF.
I realised that with OOP too but it's seems to be much more complicated...
I realised that with OOP too but it's seems to be much more complicated...
It is not. If you're familiar with PHP you might know about variable scope, which means that you cannot access a variable defined outside a function unless you import it with "global" or pass it as argument. Try the example below, it works and shows you how to carry variables across different functions.
<?php
// wcf imports
require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
/**
* Minecraft ServerStatus
*
* @author Sorry
* @copyright fightcraft.de
* @package no
* @license ask admin@fightcraft.de
*/
class ServerStatusPage extends AbstractPage {
// system
public $templateName = 'serverstatus';
public $item1 = '';
public $item2 = '';
/**
* @see Page::readData()
*/
public function readData() {
parent::readData();
$this->item1 = 'test1';
$this->item2 = 'test2';
}
/**
* @see Page::assignVariables()
*/
public function assignVariables() {
parent::assignVariables();
WCF::getTPL()->assign(array(
'item1' => $this->item1,
'item2' => $this->item2
));
}
}
?>
Display More
It is not. If you're familiar with PHP you might know about variable scope, which means that you cannot access a variable defined outside a function unless you import it with "global" or pass it as argument. Try the example below, it works and shows you how to carry variables across different functions.
i knew that but i was a little bit confused...
thank you for your example. it works, i think a can work with it
it works very well now now i've only to improve the design.
and i've to try foreach in the template within an array ... i'll hope it works
if i want to do something like this:
where do I have to place the funtion isArray? Or isn't that possible?
edit: or something like:
{if $infovalue|is_array{*}don't know if that exists{*}}{foreach from=infovalue item=value}{$value}<br/>{/foreach}{/if}
now i found another solution, i rewrote a small part of the php script and it works like i want now