1
phillipd
Smarty in a function
  • 2004/12/2 4:17

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I've got smarty in admin scripts working, but using smarty in a function is still a problem. I think it requires:

le="color: #000000"><?php function whatever() { global $xoopsDB; require_once SMARTY_DIR.'Smarty.class.php'; $xoopsTpl = new Smarty; include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; $form = new XoopsThemeForm("", "userform", "index.php"); $form->assign($xoopsTpl); }

just like an admin script, but when doing the:

le="color: #000000"><?php $xoopsTpl->display('db:'.$xoopsOption['template_main']);

I get an obscure error:

le="color: #000000"><?php Fatal error: Call to undefined function: xoops_canupdatefromfile() in /var/www/html/xoops/html/class/smarty/plugins/resource.db.php on line 16

Nothing gets displayed...
Any idea what I'm missing???

Thanks

Doug P

2
Dave_L
Re: Smarty in a function
  • 2004/12/2 5:22

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Try moving the require_once and include_once outside of the function.

3
phillipd
Re: Smarty in a function
  • 2004/12/2 6:00

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Thats not working. Has anyone got a working example of smarty in a function? What do you need to "include" or "require" to get it working?

I seem to be in "dependency hell" here. Every time I fix a "Call to a member function on a non-object", I get another...


Thanks

Doug P

4
Mithrandir
Re: Smarty in a function

Why are you instantiating Smarty? If anyone told you to do that, he or she has severely misunderstood the XOOPS structure.

le="color: #000000"><?php require_once XOOPS_ROOT_PATH."/class/template.php"; $xoopsTpl = new XoopsTpl(); //your code

will give you a XoopsTpl object - a subclass to Smarty - which will include XOOPS-specific methods such as xoops_canupdatefromfile()

5
phillipd
Re: Smarty in a function
  • 2004/12/2 7:20

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


OH! Thanks, it's almost working now... Thats 4 or 5 times you have really helped me. Will you marry me? (Kidding...)

Doug P

6
phillipd
Re: Smarty in a function
  • 2004/12/2 7:41

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Oh shoot. It works but there are no graphics. I then try to include the "header.php" for the graphics but get the error:

Fatal error: Call to a member function on a non-object in /var/www/html/xoops/html/header.php on line 138

Which appears to be template related.

Here is code:

le="color: #000000"><?php function showinv() { global $xoopsDB,$xoopsConfig; $xoopsOption['template_main'] = 'user.html'; require_once XOOPS_ROOT_PATH.'/header.php'; require_once XOOPS_ROOT_PATH.'/class/template.php'; include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; $xoopsTpl = new XoopsTpl(); // more smarty assigns and appends }


Doug P

7
Anonymous
Re: Smarty in a function
  • 2004/12/2 8:24

  • Anonymous

  • Posts: 0

  • Since: 0


Have a look at the admin templates of debaser 0.9 BETA (click).

Here is the shortest snippet I found in this module regarding the use of smarty and templates on the admin side:

le="color: #000000"><?php function playermanager() { require_once XOOPS_ROOT_PATH.'/class/template.php'; if (!isset($xoopsTpl)) { $xoopsTpl = new XoopsTpl(); } global $xoopsDB, $genrelist; $sql = 'SELECT name FROM '.$xoopsDB->prefix('debaser_player').' ORDER BY name'; $result = $xoopsDB->query($sql); while (list($player) = $xoopsDB->fetchRow($result)) { $xoopsTpl->append('player', $player); } $nuform = new XoopsThemeForm(_AM_DEBASER_NEWPLAYER, "newplayerform", "index.php"); $formplayername = new XoopsFormText(_AM_DEBASER_NAME, "newplayername", 50, 50); $formplayercode = new XoopsFormTextArea (_AM_DEBASER_CODE, 'newplayer', '', 15, 30); $op_hidden = new XoopsFormHidden("op", "newplayer"); $submit_button = new XoopsFormButton("", "dbsubmit", _SUBMIT, "submit"); $nuform->addElement($formplayername); $nuform->addElement($formplayercode); $nuform->addElement($op_hidden); $nuform->addElement($submit_button); $xoopsTpl->assign('newplayer', $nuform->render()); $xoopsTpl->assign('adminmenu', debaseradminMenu(3, _AM_DEBASER_EDITPLAYERS)); $xoopsTpl->display( 'db:debaser_amplaymanage.html' ); }