Check if template exists? [HELP]
#1
Hey everyone,

I'm writing a script for someone. Nothing too fancy. But what I'd like to know is if there is a function to check if a template exists in MyBB, and if not, a few pointers to writing a function to do this, as in:
function("templatename");
with a boolean result regarding the template's existance.

Thanks in advance,
michaelh
My Site - My Forum - MyBB
[Image: madmike360.png]
Reply
#2
Just query the database?

return $db->fetch_array($db->simple_select('templates', 'tid', 'title="mytemplate" AND sid>0'));

Not sure if the above is what you want - you'll have to play around a bit with that.
Reply
#3
(2008-10-19, 10:59 PM)ZiNgA BuRgA Wrote: Just query the database?

return $db->fetch_array($db->simple_select('templates', 'tid', 'title="mytemplate" AND sid>0'));

Not sure if the above is what you want - you'll have to play around a bit with that.

Using that gives me the following:
Quote:Fatal error: Call to a member function fetch_array() on a non-object
My Site - My Forum - MyBB
[Image: madmike360.png]
Reply
#4
Have you included MyBB's core?

<?
define('IN_MYBB', 1);
chdir('./forums');
require './inc/init.php';

// do your stuff here
$db->whatever
Reply
#5
Being an actual page, I included the global.php file. Do I still need to call init if I've done this?
My Site - My Forum - MyBB
[Image: madmike360.png]
Reply
#6
Yes as init.php instantiates $db object. Wink
Reply
#7
global.php includes init for you.

If you've included that $db code sample in a function, don't forget to add the line:
global $db;
since it's stored in the global scope.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)