Skocz do zawartości
Hosting webh.pl - 20%

Funkcja output() widgetu żąda dużo pamięci (?)

Rekomendowane odpowiedzi

Opublikowano

Witam, w nowym widgecie dodałem 

public function render()
{
	return $this->output( );
}

i problem mam taki, że nie wyświetla mi się błąd o np. niestworzonym pliku czy braku headerów a image.thumb.png.e8c5209948b8148bc02a4d1d9372e80f.png

dodam, że widget się wyświetla gdy zwracam tekst

return "test";

 

Opublikowano

Co ma Ci się wyświetlić? Jak nic tam nie ma?

 

// Use $this->output( $foo, $bar ); to return a string generated by the template set in init() or manually added via $widget->template( $callback ); // Note you MUST route output through $this->output() rather than calling \IPS\Theme::i()->getTemplate() because of the way widgets are cached

Opublikowano

W init() masz podać ścieżkę.

$this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', 'core', 'front' ), $this->key ) );


Albo w render()

 

return \IPS\Theme::i()->getTemplate( 'widgets', 'core', 'front' );

 

Opublikowano
$data = [
	'test'		=> 1,
	'test2'		=> 2,
	'test3'		=> 3,
	'test4'		=> 4,
];
		
return \count($data) ? $this->output($data): "";

 

Opublikowano
  • Autor
<?php
/**
 * @brief		servers Widget
 * @author		<a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
 * @copyright	(c) Invision Power Services, Inc.
 * @license		https://www.invisioncommunity.com/legal/standards/
 * @package		Invision Community
 * @subpackage	servers
 * @since		10 Sep 2020
 */

namespace IPS\servers\widgets;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * servers Widget
 */
class _servers extends \IPS\Widget
{
	/**
	 * @brief	Widget Key
	 */
	public $key = 'servers';
	
	/**
	 * @brief	App
	 */
	public $app = 'servers';
		
	/**
	 * @brief	Plugin
	 */
	public $plugin = '';
	
	/**
	 * Initialise this widget
	 *
	 * @return void
	 */ 
	public function init()
	{
		// Use this to perform any set up and to assign a template that is not in the following format:
		$this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' ), $this->key ) );
		// If you are creating a plugin, uncomment this line:
		// $this->template( array( \IPS\Theme::i()->getTemplate( 'plugins', 'core', 'global' ), $this->key ) );
		// And then create your template at located at plugins/<your plugin>/dev/html/servers.phtml
		
		
		parent::init();
	}
	
	/**
	 * Specify widget configuration
	 *
	 * @param	null|\IPS\Helpers\Form	$form	Form object
	 * @return	null|\IPS\Helpers\Form
	 */
	public function configuration( &$form=null )
	{
 		$form = parent::configuration( $form );

 		// $form->add( new \IPS\Helpers\Form\XXXX( .... ) );
 		return $form;
 	} 
 	
 	 /**
 	 * Ran before saving widget configuration
 	 *
 	 * @param	array	$values	Values from form
 	 * @return	array
 	 */
 	public function preConfig( $values )
 	{
 		return $values;
 	}

	/**
	 * Render a widget
	 *
	 * @return	string
	 */
	public function render()
	{
		$data = [
			'test'		=> 1,
			'test2'		=> 2,
			'test3'		=> 3,
			'test4'		=> 4,
		];
				
		return \count($data) ? $this->output($data): "";
		
		//return $this->output(  );
		//return 'test';
		// Use $this->output( $foo, $bar ); to return a string generated by the template set in init() or manually added via $widget->template( $callback );
		// Note you MUST route output through $this->output() rather than calling \IPS\Theme::i()->getTemplate() because of the way widgets are cached
	}
}

 

czysty kod z dev center

Edytowane przez X3nO

Opublikowano
public function init()
	{
		// Use this to perform any set up and to assign a template that is not in the following format:
		// $this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' ), $this->key ) );
		// If you are creating a plugin, uncomment this line:
		// $this->template( array( \IPS\Theme::i()->getTemplate( 'plugins', 'core', 'global' ), $this->key ) );
		// And then create your template at located at plugins/<your plugin>/dev/html/servers.phtml
		
		
		parent::init();
	}

masz wyłączone :kappa:

Opublikowano
  • Autor

Dodam, że jak dodam jakikolwiek kod w render to wyrzuca ten blad, chciałem zrobić prostą pętle foreach

foreach(\IPS\Db::i()->select('*', 'clients_data') as $row)
{
	$data .= $row['points'];
}

 

Opublikowano

Dziwne, spróbuj stworzyć nowy widget, tylko żeby miał inną nazwę. Miałem podobną sytuację przy tworzeniu frontu, class'y miałem podobne, lub niezgodne z ich nazwami.

Opublikowano

W php stosunkowo łatwo o memory leak

 

Moja sugestia - usuń templatke z init i zrób tak w render:

 

	$data = [
			'test'		=> 1,
			'test2'		=> 2,
			'test3'		=> 3,
			'test4'		=> 4,
		];
				
		if(is_countable($data)
           return \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' )->$this->key($data));

 

Oczywiście mam nadzieje że masz templatke "servers" gdzieś tam w dev>widgets>front

 

Edytowane przez Bluur

Opublikowano
  • Manager
9 godzin temu, Bluur napisał:

Oczywiście mam nadzieje że masz templatke "servers" gdzieś tam w dev>widgets>front

Też to teraz sprawdzałem. Brak tego, wywala błąd oczywiście, ale ścieżka ma być inna.

dev -> html -> front -> widgets -> servers.phtml

 

Masz tak?

intermedia - profesjonalne rozwiązania Invision Power Board, IC5

Opublikowano
  • Autor

Loaded Configuration File:         /usr/local/php73/lib/php.ini

https://pastebin.com/ebzvWUK6

 

Godzinę temu, DawPi napisał:

Też to teraz sprawdzałem. Brak tego, wywala błąd oczywiście, ale ścieżka ma być inna.

dev -> html -> front -> widgets -> servers.phtml

 

Masz tak?

Tak, mam tak

Opublikowano

@X3no jeszcze podaj config serwera www i php-fpm (zapewne z tego korzystasz), bo w php.ini nic konkretnego się nie dowiemy

Opublikowano
  • Autor

Mam tylko core, forums - czyste instalacja i dev tools

7 godzin temu, DawPi napisał:

I tylko tą apkę masz na forum czy coś więcej? Może się coś gryzie. Sam kod na pewno jest OK. 

 

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Ostatnio przeglądający 0

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

Konto

Nawigacja

Szukaj

Szukaj

Skonfiguruj powiadomienia push w przeglądarce

Chrome (Android)
  1. Stuknij ikonę kłódki obok paska adresu.
  2. Stuknij Uprawnienia → Powiadomienia.
  3. Dostosuj swoje ustawienie.
Chrome (Komputer)
  1. Kliknij ikonę kłódki na pasku adresu.
  2. Wybierz Ustawienia witryny.
  3. Znajdź Powiadomienia i dostosuj swoje ustawienie.