1
cyree
xoops classes
  • 2012/4/23 10:37

  • cyree

  • Just popping in

  • Posts: 2

  • Since: 2012/3/26


Hi everyone.I am using xoops classes for the 1st time and it seems like I am not getting it right. I am creating a simple program to insert data into a table called capture_information. This is my code:


//for index.php
<?php

require('../../mainfile.php');

global 
$xoopsOption;

$xoopsOption['template_main']= 'main.html';

require(
XOOPS_ROOT_PATH.'/header.php');

//////

$op '';

if(isset(
$_POST['save'])){

$op 'save';

}



if(isset(
$_POST['delete'])){

$op 'delete';

}

 

switch(
$op){



case 
'delete':


echo 
'why u wana delete?';



case 
'save':

 



$record_handler =& xoops_getModuleHandler('records','record');

$record_id $_POST['record_id'];

        if(
$record_id == 0){

            
//

            
$recordObj $record_handler->create();

        }

        else{

            
//

        
$recordObj $record_handler->get($record_id);

}

{

        
$recordobj->setVar("name",$_POST['name']);

        
$recordobj->setVar("email"$_POST['email']);

        
$recordobj->setVar("telephone"$_POST['telephone']);

        
$recordobj->setVar("address"$_POST['address']);

        
$recordobj->setVar("areacode"$_POST['areacode']);

        
$recordobj->setVar("time"time()); 

        
$recordobj->setVar("user_id"$GLOBALS['xoopsUser']->getVar("uid"));

}



if(!(
$record_handler->insert($recordObj)))

{

            
redirect_header(XOOPS_URL,2,'Error saving record');}

break;

}

require(
XOOPS_ROOT_PATH.'/footer.php');

?>


//for the class called record under a module called record

<?php
if (!defined("XOOPS_ROOT_PATH")) {
    die(
"XOOPS root path not defined");
}

class 
RecordRecord extends XoopsObject {

    function 
RecordRecord() {
        
$this->__construct();
    }

    function 
__construct() {
                
$this->initVar("record_id"XOBJ_DTYPE_INTnullfalse);
                
$this->initVar('name'XOBJ_DTYPE_TXTBOXnullfalse);
                
$this->initVar('email'XOBJ_DTYPE_TXTBOXnullfalse);
                
$this->initVar("telephone",  XOBJ_DTYPE_TXTBOXnullfalse255);
                
$this->initVar('address'XOBJ_DTYPE_TXTBOXnullfalse);
                
$this->initVar("areacode"XOBJ_DTYPE_TXTBOX0false);
                
$this->initVar("time"XOBJ_DTYPE_INT0false);
                
$this->initVar("user_id"XOBJ_DTYPE_INTnullfalse15);
    }    
}

class 
RecordRecordsHandler extends XoopsPersistableObjectHandler {

var 
$recordList;


    function 
RecordRecordsHandler(&$db
{
        
$this->__construct($db);
    }

    function 
__construct(&$db) {
        
parent::__construct($db'capture_information''RecordRecord''record_id');
}
?>

when i click the save button it shows me a blank page.plz help

2
zyspec
Re: xoops classes
  • 2012/4/23 17:07

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


cyree,

Please seehttps://xoops.org/modules/newbb/viewtopic.php?topic_id=75051&forum=28&post_id=345955#forumpost345955 for an example. Your code above has some of the same issues as the code in that post.

Make sure you put your classes in the right folder/file too. In some places you use 'records' for your class name and in others it's 'record'. That will need to be corrected too...

3
cyree
Re: xoops classes
  • 2012/4/24 14:20

  • cyree

  • Just popping in

  • Posts: 2

  • Since: 2012/3/26


Thanx,I managed to fix those errors. The problem was with calling the functions from class in index.

Login

Who's Online

182 user(s) are online (103 user(s) are browsing Support Forums)


Members: 0


Guests: 182


more...

Donat-O-Meter

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

Latest GitHub Commits