Jump to content

Creating and displaying a table?


DanielSaryn

Recommended Posts

Hello everyone,

I'm trying to get to grips with developing applications in IPS so I can help out in a Community that runs IPS.

In the process, I have found myself trying to create and display a table using the IPS Table Helper. I have ran into a bit of an issue though, here is my code:

$baseUrl = new \IPS\Http\Url('url', false);
$table = new \IPS\Helpers\Table\Db('table_name', $baseUrl);
$table->rowsTemplate = [\IPS\Theme::i()->getTemplate('tables', 'core', 'admin'), 'rows'];
$table->tableTemplate = [\IPS\Theme::i()->getTemplate('tables', 'core', 'admin'), 'table'];
$table->limit = 25;

\IPS\Output::i()->output .= $table;

I would imagine that it would be rather simple and straightforward. However, when it comes to running this code using the appropriate do method in my application, an error is thrown:

Quote

Call to undefined method IPS\Http\Url::setPage()

Extract from the Whoops Error handler:

/IPS/system/Helpers/Table/Table.php

$this->sortDirection = ( mb_strtolower( \IPS\Request::i()->sortdirection ) === 'desc' or mb_strtolower( \IPS\Request::i()->sortdirection ) === 'asc' ) ? mb_strtolower( \IPS\Request::i()->sortdirection ) : NULL;
}

/* Filter? */
if ( \IPS\Request::i()->filter )
{
$this->filter = \IPS\Request::i()->filter;
}

/* Set base URL */
$this->baseUrl = $baseUrl->setQueryString( array( 'filter' => $this->filter, 'sortby' => $this->sortBy, 'sortdirection' => $this->sortDirection ) )->setPage( $this->paginationKey, $this->page );

/* Templates */
$this->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'tables', 'core' ), 'table' );
$this->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'tables', 'core' ), 'rows' );

/* Create a unique id used by the template - can be overriden manually if desired */
$this->uniqueId    = md5( mt_rand() );
}

I have been reading the Documentation for IPS 4.4 from here: https://codingjungle.com/phpdoc/40400/

There is no mention of the existance of a method called setPage in the \IPS\Http\Url class so it's safe to say that I'm pretty confused right now.

 

Any input or ideas on how to work around this would be greatly appreciated. Cheers!

Link to comment
Share on other sites

I managed to find a solution, although it is not optimal in my eyes.

Instead of building a new \IPS\Http\Url object, I created an internal URL.

Before:

$baseUrl = new \IPS\Http\Url('url', false);

Now:

$baseUrl = \IPS\Http\Url::internal('app=myapp&module=parser&controller=parser');

 

This fixed the issue, but I still would have preferred to use the base \IPS\Http\Url object as it looks cleaner than the internal URL.

Hope this helps anyone that runs into something similar after me. :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...