31
phillipd
Re: Is there a limitation of doing multiple "user" templates vs "admin" templates
  • 2005/4/11 22:32

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Thanks for the info. XOOPS seems to have 5 ways to do everything. I'll try these techniques out as I get time.

Regards

Doug P



32
phillipd
Re: Is there a limitation of doing multiple "user" templates vs "admin" templates
  • 2005/4/7 17:15

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Thankyou very much. I'm still relatively new at this so verbosity in example code is good.

Best regards

Doug P



33
phillipd
Is there a limitation of doing multiple "user" templates vs "admin" templates
  • 2005/4/7 16:54

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


In my "admin" application code I can assign "template_main" to a template and as long as I do the

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

prior to assigning another tempate I can layout several forms in one page with separate template files. I.E.

$xoopsOption['template_main'] = 'template1.html';
do form stuff
$xoopsTpl->display('db:'.$xoopsOption['template_main']);

$xoopsOption['template_main'] = 'template2.html';
do form stuff
$xoopsTpl->display('db:'.$xoopsOption['template_main']);

$xoopsOption['template_main'] = 'template3.html';
do form stuff
$xoopsTpl->display('db:'.$xoopsOption['template_main']);

This doesn't work in "user" code though. How can I accomplish the same thing ,using multiple templates, in user code?

Is template_main a "special" template? Can I use other names for that XOOPS option in user code?

Has anyone done multiple templates on a single page in "user" code. Am I asking a stupid question? (I hope not).

I guess I could use one template with multiple forms in it but I like to keep them separate.

Thanks

Doug P



34
phillipd
Re: Smarty templates and xoops forms in a function (Admin)
  • 2005/4/3 18:44

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Figured it out, simpler than I thought:

//
// Creates a menu derived from the Database
//  Pulls the template, and everything required to make a menu from MySQL
//
function myMenu($which) {
    global 
$xoopsDB;
    require_once 
XOOPS_ROOT_PATH."/class/template.php";
    
$xoopsTpl = new XoopsTpl;
    require 
XOOPS_ROOT_PATH."/class/xoopsformloader.php";
    
$form = new XoopsThemeForm("""buttonmenuform""index.php");
    
//
    // Read the menu options from the db and make an array of associative arrays (idx)
    //   then shove the array into a template container for use by a template script
    //
    
$sql 'SELECT id,label,op,file,template, title
            FROM '
.$xoopsDB->prefix('bdr_buttons').'
            WHERE grp = '
.$which.'
            ORDER BY id'
;
    
$result $xoopsDB->query($sql);
    
$i 0;
    
$row = array();
    
$idx = array();
    while(list(
$id,$label,$op,$file,$template$title) = $xoopsDB->fetchRow($result)) {
        
$row['label'] = $label;
        
$row['op'] = $op;
        
$row['source'] = $file;
        
$idx[$i] = $row;
        
$i++;
        
$xoopsOption['template_main'] = $template;
        
$xoopsTpl->assign('title',$title);
    }
    
$xoopsTpl->append('idx',$idx);

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



35
phillipd
Re: Using forms in functions
  • 2005/4/3 17:42

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


OK, I got it working. I thought I needed to include all the XOOPS header stuff but I really didn't. I'm still fuzzy on that subject. All I had to do is:

function myMenu($which) {
global $xoopsDB;
require_once XOOPS_ROOT_PATH."/class/template.php";
$xoopsTpl = new XoopsTpl;
require XOOPS_ROOT_PATH."/class/xoopsformloader.php";

$form = new XoopsThemeForm("", "buttonmenuform", "index.php");
//
// Read the menu options from the db and make an array of associative arrays (idx)
// then shove the array into a template container for use by a template script
//
$sql = 'SELECT id,label,op,file,template, title
FROM '.$xoopsDB->prefix('bdr_buttons').'
WHERE grp = '.$which.'
ORDER BY id';
$result = $xoopsDB->query($sql);
$i = 0;
$row = array();
$idx = array();
while(list($id,$label,$op,$file,$template, $title) = $xoopsDB->fetchRow($result)) {
$row['label'] = $label;
$row['op'] = $op;
$row['source'] = $file;
$idx[$i] = $row;
$i++;
$xoopsOption['template_main'] = $template;
$xoopsTpl->assign('title',$title);
}
$xoopsTpl->append('idx',$idx);

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

Thanks for the ideas that led me here...

Doug P



36
phillipd
Re: Smarty templates and xoops forms in a function (Admin)
  • 2005/4/3 16:18

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


That answer wasn't much help. Do you have any sample or know of a module that does this?

Thanks

Doug P



37
phillipd
Re: Using forms in functions
  • 2005/4/3 8:26

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Great idea, I didn't think of that, thanks. I'll try it tomorrow and let you know. I just thought that PHP functions were islands unto themselves and if I were to do anything like DB stuff for example I would have to re-include/re-require the XOOPS stuff in order to access the XOOPS API stuff in the function.

Although I know you only have to add "global xoopsDB" to access MySQL functions. Have you done forms/templates in a function yourself?

Doug P



38
phillipd
Re: Using forms in functions
  • 2005/4/3 7:15

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I guess my general question is:

To make smarty and XOOPS forms work in admin script PHP function, what is the correct order of the "Include" statements for XOOPS headers (cp_header) etc. Have you ever done smarty and XOOPS forms from inside a admin PHP function?

Doug P



39
phillipd
Re: Using forms in functions
  • 2005/4/3 6:32

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Debug is on, no errors, just the "Sorry, You don't have permission to access this area" message from xoops. BTW I can make all this admin code work as long as I don't put the form code in a function. But then I have to create a separate php code file for each different form I want to display. i would rather pass a function some args and use only one function. Am I explaining myself sufficiently?

I guess my general question is:

To make smarty and XOOPS forms work in admin script PHP function, what is the correct order of the "Include" statements for XOOPS headers (cp_header) etc. HAve you ever done smarty and XOOPS forms from inside a PHP function?

Doug P



40
phillipd
Re: Using forms in functions
  • 2005/4/3 6:26

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


OK, even though I'm including XOOPS_ROOT_PATH.'/include/cp_header.php'; from a PHP function in an admin script, I don't have permssion to access it. Why is this?

I use something like this in an admin script:

function myMenu($which) {

include '../../../mainfile.php';
include XOOPS_ROOT_PATH.'/include/cp_header.php';

}

The cp_header.php line gives a permission denied when included from within the function...

I'm confused...

Thanks

Doug P




TopTop
« 1 2 3 (4) 5 6 7 ... 22 »



Login

Who's Online

189 user(s) are online (116 user(s) are browsing Support Forums)


Members: 0


Guests: 189


more...

Donat-O-Meter

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

Latest GitHub Commits