Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:14:13+00:00 2026-05-30T11:14:13+00:00

I have a requirement to implement audit logging functionality in a zend project. The

  • 0

I have a requirement to implement audit logging functionality in a zend project. The models are created using zend db and the update function is as follows.

public function updateGroup($data,$id)
{       
    $row = $this->find($id)->current();
    // set the row data
    $row->name                  = $data['name'];
    $row->description           = $data['description'];

    $row->updatedBy         = $data['updatedBy'];
    $row->updatedOn         = date('Y-m-d H:i:s'); 

    $id = $row->save();
    return $id;
}

I have to create a table with the auditlog information which includes the current userid. I have tried many methods and nothing is a good solution. What is the best practice for a good audit logging functionality for zend?

I just want to log only the modified data. and the log table schema is like

id, 
table, 
column,
rowId
oldvalue,
newvalue,
updatedon,
updatedbyuser 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:14:14+00:00Added an answer on May 30, 2026 at 11:14 am

    use Zend_Log_Writer_Db :

    Zend_Log_Writer_Db writes log information to a database table using
    Zend_Db. The constructor of Zend_Log_Writer_Db receives a
    Zend_Db_Adapter instance, a table name, and a mapping of database
    columns to event data items

    for example :

    $columnMapping = array('name' => 'name', 
                           'desc' => 'desc', 
                           'updatedBy' => 'userid', 
                           'updatedOn' => 'date');
    $writer = new Zend_Log_Writer_Db($db, 'auditlog_table', $columnMapping);
    
    $logger = new Zend_Log($writer);
    
    
    $logger->setEventItem('name', $data['name']);
    $logger->setEventItem('desc', $data['name']);
    $logger->setEventItem('updatedBy',$data['updatedBy']);
    $logger->setEventItem('updatedOn',date('Y-m-d H:i:s'));
    

    EDIT : to log only the modified data :

    public function logUpdate(array $values)
    { 
        $columnMapping = array('id' => 'id', 
                               'table' => 'table', 
                               'column' => 'column',
                               'rowId' => 'rowId',
                               'oldvalue' => 'oldvalue',
                               'newvalue' => 'newvalue',
                               'updatedon' => 'updatedon',
                               'updatedbyuser' => 'updatedbyuser');
    
        $writer = new Zend_Log_Writer_Db($db, 'auditlog_table', $columnMapping);
    
        $logger = new Zend_Log($writer);
    
    
        $logger->setEventItem('id', $values['id']);
        $logger->setEventItem('table', $values['table']);
        $logger->setEventItem('column', $values['column']);
        $logger->setEventItem('rowId', $values['rowId']);
        $logger->setEventItem('oldvalue', $values['oldValue']);
        $logger->setEventItem('newValue', $values['newValue']);
        $logger->setEventItem('updatedon', $values['updatedon']);
        $logger->setEventItem('updatedbyuser', $values['updatedbyuser']);
    } 
    

    and in updateGroup :

    public function updateGroup($data,$id)
    {       
        $row = $this->find($id)->current();
    
        $values = array('table' => $this->name);
        $values = array('updatedon' => $data['updatedBy']);
        $values = array('updatedbyuser' => date('Y-m-d H:i:s'));
       //go through all data to log the modified columns
        foreach($data as $key => $value){
          //check if modified log the modification
          if($row->$key != $value){
            $values = array('column' => $key);
            $values = array('oldValue' => $row->$key);
            $values = array('newValue' => $value);
            logUpdate($values);
          }
        }
    
        // set the row data
        $row->name                  = $data['name'];
        $row->description           = $data['description'];
    
        $row->updatedBy         = $data['updatedBy'];
        $row->updatedOn         = date('Y-m-d H:i:s'); 
    
        $id = $row->save();
    
    
        return $id;
    }
    

    Note that its better to implement logging for all your application and seperate logging from update , see this answer for that .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a requirement to increase the functionality of a grid we are using
I have a requirement to implement a web application using MVC 3, which works
On my current project we're using Spring 3 MVC and have a requirement to
I have a requirement to implement a functionality to draw edge of a object
I have a requirement to implement a toolbar similar to microsoft word 2007 using
I have a requirement to implement an Unsaved Changes prompt in an ASP .Net
I have a requirement to implement contact database. This contact database is special in
In our project we have requirement that, after receiving sms message from third party
We have a requirement in project to store all the revisions(Change History) for the
I have a requirement to implement some kind of dictionary object. Something like MyDict<K,V1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.