cyree cyree
  • Just popping in
  • Just popping in
  • Joined: 2012/3/26 5:30
  • From Sandton South Africa
  • Group: Registered Users
  • Posts: 2
  • Posted on: 2012/4/23 6:37
xoops classes #1
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
zyspec zyspec
  • Module Developer
  • Module Developer
  • Joined: 2004/9/21 9:28
  • From USA
  • Group: Registered Users
  • Posts: 980
  • Posted on: 2012/4/23 13:07
Re: xoops classes #2
cyree,

Please see http://xoops.org/modules/newbb/viewto ... 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...
cyree cyree
  • Just popping in
  • Just popping in
  • Joined: 2012/3/26 5:30
  • From Sandton South Africa
  • Group: Registered Users
  • Posts: 2
  • Posted on: 2012/4/24 10:20
Re: xoops classes #3
Thanx,I managed to fix those errors. The problem was with calling the functions from class in index.
How to effectively post a question in the Xoops forums? - Read here...
Design by: XOOPS UI/UX Team