1
zite83
function updateAll()
  • 2010/11/14 1:17

  • zite83

  • Just popping in

  • Posts: 41

  • Since: 2004/10/5


I have most of the functions located in object.php figured out. I've been playing around with trying to update a single row in my database through extending the XoopsPersitableObjectHandler. I have been able to update one field at a time, but was wondering is there a function I'm missing that would update all fields in a row, or am I reading how to use the updateall function?


Example of how I insert a new row
$article_handler xoops_getModuleHandler('NewsArticles''MyNews');

//Build object
$article->art_cat_id =  $_POST['art_cat_id']; 
$article->art_title =  $_POST['art_title'];
$article->art_text =  $_POST['art_text'];
$article->art_submitter =  $uid
$article->art_submit_date =  $_POST['art_submit_date']; 

//Create data and insert.
$article_data $article_handler->create();
$article_data->setVars($article);
$article_handler->createArticles($article_data);


// Part of my class that extends XoopsPersitableObjectHandler

/*
* create
*/        

function createArticles($data)
{
     
$this->insert($data);        
}


Is there a function that I can use with XoopsPersitableObjectHandler that does the same thing but updates a rows fields instead? So that I can place all my data from a form into an object and then push that object through my class system?


2
trabis
Re: function updateAll()
  • 2010/11/14 12:58

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


The insert method will do an insert or update depending on the object you are passing.
I don't think you need to extend XoopsPersitableObjectHandler.


//get article if exisists
$article = $article_handler->get($_POST['art_id']);

//if article does not exists, create one
if (!is_object($article)) {
$article = $article_handler->create();
}
//set vars
$article->setVars($_POST);

//insert if new
//update if not new and if dirty
$article_handler->insert($article);

3
zite83
Re: function updateAll()
  • 2010/11/14 19:33

  • zite83

  • Just popping in

  • Posts: 41

  • Since: 2004/10/5


*Face Palm*

Thanks trabis, I spent so much time looking at others modules trying to figure out how they do an update but couldn't figure it out. I had it all along, I just needed to add the unique auto id into my object before I inserted it and then it would of updated.... I came up with just a basic queryF statement but don't like to use those. Wow Xoops classes can save so much work once you know how to use them!

Login

Who's Online

166 user(s) are online (105 user(s) are browsing Support Forums)


Members: 0


Guests: 166


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