Skocz do zawartości

Rekomendowane odpowiedzi

Opublikowano

Witam, tworzę aktualnie widget z SampQueryAPI, moj kod:

	public function render()
	{
		include "applications/serverviewer/sources/SampQueryAPI.php";
		$SampQuery = new SampQueryAPI('185.73.228.158', '7756');

		return $this->output(  );
	}

includuje SampQueryAPI ale IPS tego nie wykrywa.. 

Cytuj

Class 'IPS\serverviewer\widgets\SampQueryAPI' not found

Czy w IPS jakoś inaczej się includuje pliki?

  • 2 tygodnie później...
Opublikowano

Dzięki, działa. Ale mam problem z wyświetleniem tablicy, np:

Działa: {$aInformation['players']}, {$aInformation['maxplayers']}

Nie działa: {$aInformation['hostname']}, {$aInformation['mapname']}

 

print_r wyświetla

Array ( [password] => 0 [players] => 16 [maxplayers] => 50 [hostname] => � � PL � Polska Strefa Rozrywki � [PSR] � � [gamemode] => � Polski PL/DM/Stunt/Drift/4Fu [mapname] => � Polski/PL/Polish � ) 

 

Opublikowano

Trochę przerobiłem kod, teraz wygląda to tak:

	public function render()
	{
		$server = [];
		include "applications/serverviewer/sources/SampQueryAPI.php";
		$row['num'] = 0;
		foreach ( \IPS\Db::i()->select( '*', 'serverviewer_servers') as $row ) {
			$row['num']++;
			switch ($row['type']) {
				case 'samp':
					$SampQueryAPI = new \SampQueryAPI($row['ip'], $row['q_port']);
					$row['SampInformation'] = $SampQueryAPI->getInfo();
					if ($row['SampInformation']['players'] > 0 ) {
						$row['clientsvalue'] = ($row['SampInformation']['players']) / ($row['SampInformation']['maxplayers']) *100;
						$row['clients'] = number_format($row['clientsvalue'], 0);
					} else {
						$row['clients'] = number_format(0, 0);
					}
					$row['status'] = $SampQueryAPI->isOnline();
					break;
				
				default:
					# code...
					break;
			}
			$server[] = $row;
		}

		return $this->output( $server );
	}

Oraz szablon:

<ips:template parameters="$server" />
<h2 class="ipsType_sectionTitle ipsType_reset ipsType_blendLinks cForumTitle">Lista serwerów</h2>
<table class="ipsTable ipsTable_responsive ipsTable_zebra ipsBox">
	<thead>
		<tr>
			<td style="text-align: center;">#</td>
			<td style="text-align: center;">Status</td>
			<td style="text-align: center;">Gra</td>
			<td style="text-align: center;">Adres IP</td>
			<td style="text-align: center;">Nazwa serwera</td>
			<td style="text-align: center;">Mapa</td>
			<td style="text-align: center;">Graczy</td>
			<td style="text-align: center;">Dodatki</td>
		</tr>
	</thead>
	<tbody>
		{{foreach $server as $server}}
		<tr>
			<td style="text-align: center;">
				{$server['num']}
			</td>
			<td style="text-align: center;">
				{$server['status']}
			</td>
			<td style="text-align: center;">
				{$server['type']}
			</td>
			<td style="text-align: center;">
				{$server['ip']}:{$server['c_port']}
			</td>
			<td style="text-align: center;">
				{$server['SampInformation']['hostname']|raw}
			</td>
			<td style="text-align: center;">
				{$server['SampInformation']['mapname']|raw}
			</td>
			<td style="text-align: center;">
				({$server['SampInformation']['players']} / {$server['SampInformation']['maxplayers']}) {$server['clients']}%
			</td>
			<td style="text-align: center;">
				<a data-ipstooltip _title="Kilknij, aby zobaczyć informacje o serwerze" href="#" data-ipsdialog data-ipsdialog-url="#" data-ipsdialog-title="Informacje o serwerze" class="ipsButton ipsButton_primary ipsButton_verySmall"><i class="fa fa-bar-chart"></i></a>
				<a data-ipstooltip _title="Kilknij, aby połączyć się z serwerem" href="#" data-ipsdialog-title="Połącz z serwerem" class="ipsButton ipsButton_primary ipsButton_verySmall"><i class="fa fa-play-circle-o"></i></a>
			</td>
		</tr>
    </tbody>
</table><br />

Mimo tego, że include sampqueryapi nie mam w pętli to wyświetla się error

Cytuj

Whoops\Exception\ErrorException thrown with message "Cannot redeclare class SampQueryAPI"

Stacktrace:
#0 Whoops\Exception\ErrorException in /applications/serverviewer/sources/SampQueryAPI.php:16

 

Opublikowano
2 minuty temu, Macsch15 napisał:

Wyrzuć to include. IPB 4 ma autoloader.

Cytuj

Whoops\Exception\ErrorException thrown with message "Class 'SampQueryAPI' not found"

Stacktrace:
#0 Whoops\Exception\ErrorException in /applications/serverviewer/widgets/mainwidget.php:101

Dziwnie działa ten autoloader XD

Opublikowano

Dodaj do pliku SampQueryAPI na samą górę

namespace IPS\serverviewer\sources;

A następnie w pliku rozszerzenia

$SampQuery = new \IPS\serverviewer\sources\SampQueryAPI('185.73.228.158', '7756');

 

Opublikowano (edytowane)

Dzięki wielkie bo IPS już się pokazuje, tylko 

Cytuj

Whoops\Exception\ErrorException: Class IPS\serverviewer\sources\SampQueryAPI could not be loaded. Ensure it has been properly prefixed with an underscore and is in the correct namespace. (256)

 

Edytowane przez X3nO
Gość
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...

Powiadomienie o plikach cookie

Umieściliśmy na Twoim urządzeniu pliki cookie, aby pomóc Ci usprawnić przeglądanie strony. Możesz dostosować ustawienia plików cookie, w przeciwnym wypadku zakładamy, że wyrażasz na to zgodę.