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:

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:

$xoopsTpl->display('db:'.$xoopsOption['template_main']);

I get an obscure error:

Fatal errorCall 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.

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:

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:


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:

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"5050);
    
$formplayercode = new XoopsFormTextArea (_AM_DEBASER_CODE'newplayer'''1530);
    
$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' );
    }

Login

Who's Online

358 user(s) are online (250 user(s) are browsing Support Forums)


Members: 0


Guests: 358


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits