ShaneV Posted September 22, 2009 Report Share Posted September 22, 2009 Hi, I recently upgraded my 2.3.5 to 3.0.3 :) Now for 2.3xx i made my own little script called 'Topic Top 50' It shows 50 topics with most reply's that where post in the last 30 days.. With a simple code: http://codedump.mastercode.nl/645/ Placed the file in /sources/components_public/ and access it by index.php?autocom=top50 Now i see that in IPB3 almost everything with the code is changed, how can i do something like this for IPB3? Thanks allot! Greetz Quote Link to comment Share on other sites More sharing options...
MPFF Posted September 22, 2009 Report Share Posted September 22, 2009 you would have to create a full app for this or an addon module as alot of the old code has gone shouldnt take u that long to write Quote Link to comment Share on other sites More sharing options...
ShaneV Posted October 2, 2009 Author Report Share Posted October 2, 2009 Hi thanks, I need a little help here :) I want to work with the template i added in ACP but how does the foreach function work in IPB3, this is what i have so far. The page: http://www.codedump.be/code/346/ Template: http://www.codedump.be/code/347/ Template Variables: $t50 Inspired on an invite mod for IPB3, but its not working. Thanks Quote Link to comment Share on other sites More sharing options...
MPFF Posted October 2, 2009 Report Share Posted October 2, 2009 well it wont work because your passing the variable $data from your script and using $t50 in your template you either need to edit the template var or the php var so they match Quote Link to comment Share on other sites More sharing options...
ShaneV Posted October 25, 2009 Author Report Share Posted October 25, 2009 Are there some tuts about using the foreach in ipb3 templates? Like this i simple query what i do wrong? Example select 50 emails from ipb_members $data = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'members','limit' => '50' ) ); $this->output .= $this->registry->output->getTemplate('top50')->showTop50( $data ); $this->registry->output->addContent( $this->output ); $this->registry->output->sendOutput(); Template: => template variable: $data=array() <foreach loop="$data as $k"> {$k['email']}<br /> </foreach> But i get an output like this 1 B 4 m 1 8 3 B ... Quote Link to comment Share on other sites More sharing options...
Management Michael Posted October 25, 2009 Management Report Share Posted October 25, 2009 Try this instead. <foreach loop="$data as $k => $v"> {$v['email']}<br /> </foreach> Quote Link to comment Share on other sites More sharing options...
MPFF Posted October 26, 2009 Report Share Posted October 26, 2009 why dont you just remove the php foreach and do a skin 1 much simpilar <foreach loop="data:$data as $row"> {$row['email']}<br /> </foreach> Quote Link to comment Share on other sites More sharing options...
ShaneV Posted October 26, 2009 Author Report Share Posted October 26, 2009 (edited) If i do it both ways i get the same error without a query result Warning: Invalid argument supplied for foreach() in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code on line 30 Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 91 Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 94 Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 102 Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 103 Warning: Cannot modify header information - headers already sent by (output started at /home/bsnet/public_html/Upgrader/admin/sources/classes/output/publicOutput.php(1381) : eval()'d code:30) in /home/bsnet/public_html/Upgrader/admin/sources/classes/output/formats/html/htmlOutput.php on line 107 Full page: <?php if ( ! defined( 'IN_IPB' ) ) { print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files."; exit(); } class public_top50_top50mod_top50sec extends ipsCommand { public function doExecute( ipsRegistry $registry ) { /* Load language */ $this->registry->class_localization->loadLanguageFile( array( 'public_top50' ), 'core' ); $this->registry->getClass('class_localization')->loadLanguageFile( array( 'public_top50' ) ); /* Page Title */ if( $this->page_title == "" ) { $this->page_title = $this->settings['board_name'] . " - " . $this->lang->words['title']; } $this->registry->output->setTitle( $this->page_title ); /* Navigation */ $this->registry->output->addNavigation( $this->lang->words['title'], 'app=top50&module=top50mod' ); /* App Online Check */ if( !$this->settings['bs_top50_online'] ) { $this->registry->output->showError( 'top50_offline' ); } /* Group Permissions */ if( !$this->memberData['bs_top50_groups'] ) { $this->registry->output->showError( 'top50_groupPrem' ); } /* There must be at least one forum selected */ if( !$this->settings['bs_top50_forums'] ) { $this->registry->output->showError( 'top50_noForums' ); } /* Test foreach in ipb3 template */ $data = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'members','limit' => '50' ) ); /* Skin bit */ $this->output .= $this->registry->output->getTemplate('top50')->showTop50( $data ); /* Output */ $this->registry->output->addContent( $this->output ); $this->registry->output->sendOutput(); } } Edited October 26, 2009 by ShaneV Quote Link to comment Share on other sites More sharing options...
Management Michael Posted October 27, 2009 Management Report Share Posted October 27, 2009 buildAndFetch will only return 1 result from the database. Try something like this instead. Also would be a good idea to wrap your template foreach with an is_array if statement. $this->DB->build( array( 'select' => '*', 'from' => 'members','limit' => '50' ) ); $this->DB->execute(); while( $members = $this->DB->fetch() ) { $data[] = $members; } /* Skin bit */ $this->output .= $this->registry->output->getTemplate('top50')->showTop50( $data ); Quote Link to comment Share on other sites More sharing options...
ShaneV Posted October 27, 2009 Author Report Share Posted October 27, 2009 Hi thanks Michael, can you give me an example how to use it in the templates with an is_array if statement. This is my first time with ipb3 code, only have some basic php skills. Thanks, grtz Quote Link to comment Share on other sites More sharing options...
MPFF Posted October 27, 2009 Report Share Posted October 27, 2009 Hi thanks Michael, can you give me an example how to use it in the templates with an is_array if statement. This is my first time with ipb3 code, only have some basic php skills. Thanks, grtz sorry i didnt even read the script properly as you are now using BuildAndFetch you should be able to use the <foreach> statement i provided in an earlier post but make sure your variable is $data="" Quote Link to comment Share on other sites More sharing options...
Management Michael Posted October 28, 2009 Management Report Share Posted October 28, 2009 Hi thanks Michael, can you give me an example how to use it in the templates with an is_array if statement. This is my first time with ipb3 code, only have some basic php skills. Thanks, grtz <if test="has_data:|:is_array( $your_array )"> foreach here </if> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.