vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   passing arguements to function (https://vborg.vbsupport.ru/showthread.php?t=76080)

Oreamnos 02-10-2005 02:00 PM

passing arguements to function
 
I have a simple function in my includes/functions.php file. it requires 2 arguements (userid, forumid).

I am trying to make a template conditional that uses this function

where do the userid and forumid get passed to this function?

any help with this would be great because i am super noob to templates

thanks
eric

Andreas 02-10-2005 02:19 PM

Without a few exceptions (like can_moderate() or in_array()) you can't use functions in Templates!

Oreamnos 02-10-2005 02:23 PM

thanks

I realize you are quite limited in what you can do in the template conditionals.

But how do the arguements get passed to say, the following function, found in /inludes/functions.php?
PHP Code:

// ###################### Start queryphrase #######################
function fetch_phrase($phrasename$phrasetypeid$strreplace ''$doquotes true$alllanguages false$languageid = -1)



Andreas 02-10-2005 03:22 PM

PHP Code:

$phrase fetch_phrase('someerror'PHRASETYPEID_ERROR); 

for Example, if this is what you wanted to know ...

Marco van Herwaarden 02-10-2005 06:47 PM

Just to make things a bit clear. You are now talking about a php-script, not about a template.

Oreamnos 02-10-2005 11:21 PM

Thanks but I am still lost. Let me be more specific.

I have this function (which I didn't write) which is in my inludes/function.php. what it is supposed to do is check if the user has started a thread in forum number 10.
PHP Code:


// ###################### Check if user posted Introductory thread #######################
function posted_in_forum($userid,$forumid 10) {
    global 
$DB_site;
    
$posted $DB_site->query_first("SELECT threadid FROM ".TABLE_PREFIX."thread WHERE postuserid='$userid' AND forumid='$forumid' LIMIT 0,1");
    if (
$posted['threadid'])
        return 
true;
    else
        return 
false;    


First, is the function correct and if so, what should my template conditional look like? right now it looks like this <if condition="$posted_in_forum"> but i have a strong feeling that's wrong :rolleyes:

Can someone help me with this? Thanks!
Eric

Andreas 02-11-2005 12:17 AM

1) The function does what it is supposed to do
2) You can't use this function in Template conditionals

Oreamnos 02-11-2005 12:19 AM

I realize i cant use it in a template conditional. But can i use the result of this function in a template conditional?

Andreas 02-11-2005 12:22 AM

Yes.
Calll it in a PHP file like

PHP Code:

$hasposted posted_in_forum($userid$forumid

and then use

HTML Code:

<if condition="$hasposted">
stuff here
</if>

(There is a way to make custom functions work in Template conditionals, but as this can be dangerous I won't recommend it)

Oreamnos 02-11-2005 12:39 AM

i think we are getting closer.

I put this in my functions.php file:
PHP Code:

// ###################### Check if user posted Introductory thread #######################
function posted_in_forum($userid,$forumid) {
    global 
$DB_site$bbuserinfo;
    
$posted $DB_site->query_first("SELECT threadid FROM ".TABLE_PREFIX."thread WHERE postuserid='$userid' AND forumid='$forumid' LIMIT 0,1");
    if (
$posted['threadid'])
        return 
true;
    else
        return 
false;    
}


$hasposted posted_in_forum($bbuserinfo['userid'], 10); 

and this is my template conditonal:
HTML Code:

<if condition="$hasposted">
<tr>
<td class="vbmenu_option" align="left">Not Posted</td>
</tr>
<else />
<tr>
<td class="vbmenu_option" align="left">Posted</td>
</tr>
</if>

But still no luck... is it ok to have this $hasposted = posted_in_forum($bbuserinfo['userid'], 10); in my functions.php file? or should it go somewhere else?


All times are GMT. The time now is 12:16 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01560 seconds
  • Memory Usage 1,743KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_html_printable
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete