Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
inkredible Posted February 21, 2017 Posted February 21, 2017 Hello, I want to create a list from a given MySQL table, but I am facing an exception and I am not sure what the reason is. Quote Whoops\Exception\ErrorException thrown with message "Class name must be a valid object or a string" Stacktrace: #0 Whoops\Exception\ErrorException in [removed]/public_html/devforum/system/Theme/Theme.php:4124 1. This is the code inside of my controller which is supposed to load the template: protected function _sessions() { /* Create the table */ $table = new \IPS\Helpers\Table\Db( 'chat_log_archive', \IPS\Http\Url::internal( 'app=botuserpanel&module=userpanel&controller=userpanel&area=sessions' )); $include[] = 'log_user'; $include[] = 'log_message'; $include[] = 'log_time'; $table->include = $include; $table->mainColumn = 'log_user'; /* Custom parser for unix timestamp */ $parser[ 'log_time' ] = function( $val ) { if( !$val ) { return "Unknown"; } else { return \IPS\DateTime::ts( $val ); } }; $table->parsers = $parser; return \IPS\Theme::i()->getTemplate( 'panel', 'botuserpanel', 'front' )->panelSessions($table); } 2. This is a part of my "panelSessions" template: <ips:template parameters="$table" /> {$table|raw} What I have noticed: When I use empty tables instead of "chat_log_archive" the exception doesn't happen, and the output is a formatted HTML string which says "There's nothing here yet" Am I doing something wrong here? Can someone point me into the right direction? Can someone explain what the BaseURL for the Table\Db constructor is good for. The documentation only says it's the baseUrl of the page the list table is on (but why is it even required?)
newbie LAC Posted February 21, 2017 Posted February 21, 2017 Hello, For front area you should set up $table->rowsTemplate $table->rowsTemplate = array( \IPS\Theme::i()->getTemplate('group', 'app', 'location'), 'templateName' );
inkredible Posted February 21, 2017 Author Posted February 21, 2017 6 hours ago, newbie LAC said: Hello, For front area you should set up $table->rowsTemplate $table->rowsTemplate = array( \IPS\Theme::i()->getTemplate('group', 'app', 'location'), 'templateName' ); Hi, I have added this right after specifying the mainColumn $table->rowsTemplate = array( \IPS\Theme::i()->getTemplate('tables', 'core', 'front'), 'rows'); but I still face the exact same problem.
newbie LAC Posted February 21, 2017 Posted February 21, 2017 34 minutes ago, inkredible said: $table->rowsTemplate = array( \IPS\Theme::i()->getTemplate('tables', 'core', 'front'), 'rows'); Why this? This you can use for \IPS\Helpers\Table\Content because in the template (applications/core/dev/html/front/tables/rows) $rows is an array of objects In your case $rows is an array of db rows
inkredible Posted February 21, 2017 Author Posted February 21, 2017 2 minutes ago, newbie LAC said: Why this? This you can use for \IPS\Helpers\Table\Content because in the template (applications/core/dev/html/front/tables/rows) $rows is an array of objects In your case $rows is an array of db rows I was confused about your initial answer and I wanted to show at least the code which I have tried. Could you elloborate your initial answer? What does it mean to use a "rowsTemplate"? Unfortunately I can't find any documentation about using tables, nor did I find a piece in the IPS suite which makes use of Table\db. Do I need to apply my template, because right now I expect the html code for a generated table which will be passed with $table (see 2. in my initial thead). Thanks for the help
GriefCode Posted February 21, 2017 Posted February 21, 2017 You need to define a custom rowTemplate in order that your table can be displayed. It is not attached on the table at the front module. As example:https://github.com/Grief-Code/IPS-Stats/blob/master/modules/front/stats/recentGames.php#L106 Then simply define a template for your needs:https://github.com/Grief-Code/IPS-Stats/blob/master/dev/html/front/tables/toplist.phtml Actually my whole table row is only this part:https://github.com/Grief-Code/IPS-Stats/blob/master/dev/html/front/tables/toplist.phtml#L76-L115 The error does not happen on an empty table as there are no rows. Regards
inkredible Posted February 21, 2017 Author Posted February 21, 2017 33 minutes ago, GriefCode said: You need to define a custom rowTemplate in order that your table can be displayed. It is not attached on the table at the front module. As example:https://github.com/Grief-Code/IPS-Stats/blob/master/modules/front/stats/recentGames.php#L106 Then simply define a template for your needs:https://github.com/Grief-Code/IPS-Stats/blob/master/dev/html/front/tables/toplist.phtml Actually my whole table row is only this part:https://github.com/Grief-Code/IPS-Stats/blob/master/dev/html/front/tables/toplist.phtml#L76-L115 The error does not happen on an empty table as there are no rows. Regards Uh thanks, I will dig into your provided source code. Is there a reason that IPS doesn't provide some kind of default template as they apparently do for the admin area?
inkredible Posted February 21, 2017 Author Posted February 21, 2017 For example I saw in Babble that kind of table which absolutely suits my needs: All he did loading the Table, specifying the includes, adding custom parsers and outputting the $table like this (he didn't use an own template as far as I can see): \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
GriefCode Posted February 21, 2017 Posted February 21, 2017 1 hour ago, inkredible said: For example I saw in Babble that kind of table which absolutely suits my needs: All he did loading the Table, specifying the includes, adding custom parsers and outputting the $table like this (he didn't use an own template as far as I can see): \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table ); The admin module has a default template. You can find in my admin modules also some tables. Why they only serve it for admin modules, i do not know. May some of the IPS Staff can answere you that question, but i assume it has something to do with my next chapter. You could directly use the admin template actually, but mostly i want to modify the front as I think a simple list is just boring As exmaple, no front table has actually the same template as the admin module uses, but multiply admin tables share the same template. The forum list itself is also just another row template.
teraßyte Posted February 21, 2017 Posted February 21, 2017 1 hour ago, inkredible said: For example I saw in Babble that kind of table which absolutely suits my needs: All he did loading the Table, specifying the includes, adding custom parsers and outputting the $table like this (he didn't use an own template as far as I can see): \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table ); Unlike the front end the ACP doesn't require a custom rows template. Also for further assistance with development use the other forum next time, this one is only to ask IPS to implement changes in the code not for support: https://invisionpower.com/forums/forum/238-development-assistance/ EDIT: looks like I missed GriefCode's post. I hate that answers are sorted by votes and not date... >.<
inkredible Posted February 21, 2017 Author Posted February 21, 2017 2 hours ago, teraßyte said: Unlike the front end the ACP doesn't require a custom rows template. Also for further assistance with development use the other forum next time, this one is only to ask IPS to implement changes in the code not for support: https://invisionpower.com/forums/forum/238-development-assistance/ EDIT: looks like I missed GriefCode's post. I hate that answers are sorted by votes and not date... >.< I am still hoping that there is an easy way to visualize my $table as easy as admin controllers allow it. Maybe one of the IPS staff members know it otherwise I would like to suggest to implement it, unless there is a good reason that it hasn't been implemented for front controllers. As far as I see it offers pagination, filters, a quicksearch function and so on. It would take a lot effort to create such templates on my own :(.
HeadStand Posted February 22, 2017 Posted February 22, 2017 1 hour ago, inkredible said: I am still hoping that there is an easy way to visualize my $table as easy as admin controllers allow it. Maybe one of the IPS staff members know it otherwise I would like to suggest to implement it, unless there is a good reason that it hasn't been implemented for front controllers. As far as I see it offers pagination, filters, a quicksearch function and so on. It would take a lot effort to create such templates on my own :(. All of these things are available in the front end as well, if you just define your table correctly. (Except quickSearch, that might be the only one.) But pagination and filters are definitely there. The primary difference between the default admin rows template (the rows, not the table) and the front rows template is that the front end is expecting an object, while the admin is expecting an array of data. Creating your own rows template is really quite simple, though. The only thing you are doing there is displaying the row data - you don't need to worry about things like filters and paging, as that's one level up (on the table template).
BomAle Posted February 28, 2017 Posted February 28, 2017 quicksearch is disabled by front javascript table module. but you could mixin into it and able... not tried yet
bfarber Posted March 1, 2017 Posted March 1, 2017 16 hours ago, BomAle said: quicksearch is disabled by front javascript table module. but you could mixin into it and able... not tried yet I have added a mixin for this, it works.
GriefCode Posted March 1, 2017 Posted March 1, 2017 48 minutes ago, bfarber said: I have added a mixin for this, it works. Could you provide the code? I would really like to use it for one of my applications too, but I'm not to sure how to work exactly on mixins within the controller context.
bfarber Posted March 3, 2017 Posted March 3, 2017 Essentially I had a plugin, and within the dev/js/ folder I added a new javascript file with this template ;( function($, _, undefined){ "use strict"; ips.controller.mixin('acpTable', 'core.global.core.table', true, function () { //... }); }(jQuery, _)); I added my mixin code, some of which was copy and pasted from the general Suite release. The plugin js is loaded on every page, so the pages I added my tables to benefited from this (i.e. having search available).
Recommended Posts
Archived
This topic is now archived and is closed to further replies.