[EXTENSION] AuditTrail

Would it be possible for you to post your main.php config file here, or pm it to me if you are uncomfortable posting it to everyone?

This is my Main.php


<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

        'name'=>'My Web Application',


        // preloading 'log' component

        'preload'=>array('log'),


        // autoloading model and component classes

        'import'=>array(

                'application.modules.auditTrail.models.AuditTrail',

                'application.modules.auditTrail.AuditTrailModule',

                'application.models.*',

                'application.components.*',

        ),


        'modules'=>array(

        

                'auditTrail'=>array(),

                // uncomment the following to enable the Gii tool

                

                'gii'=>array(

                        'class'=>'system.gii.GiiModule',

                        'password'=>'roopesh',

                        // If removed, Gii defaults to localhost only. Edit carefully to taste.

                        'ipFilters'=>array('127.0.0.1','::1'),

                ),

                

        ),


        // application components

        'components'=>array(

                'user'=>array(

                        // enable cookie-based authentication

                        'allowAutoLogin'=>true,

                ),

                // uncomment the following to enable URLs in path-format

                /*

                'urlManager'=>array(

                        'urlFormat'=>'path',

                        'rules'=>array(

                                '<controller:\w+>/<id:\d+>'=>'<controller>/view',

                                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

                                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

                        ),

                ),

                */

                /*'db'=>array(

                        'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

                ),

                */

                // uncomment the following to use a MySQL database

                

                'db'=>array(

                        'connectionString' => 'mysql:host=localhost;dbname=edusoft',

                        'emulatePrepare' => true,

                        'username' => 'root',

                        'password' => '',

                        'charset' => 'utf8',

                ),

                

                'errorHandler'=>array(

                        // use 'site/error' action to display errors

            'errorAction'=>'site/error',

        ),

                'log'=>array(

                        'class'=>'CLogRouter',

                        'routes'=>array(

                                array(

                                        'class'=>'CFileLogRoute',

                                        'levels'=>'error, warning',

                                ),

                                // uncomment the following to show log messages on web pages

                                /*

                                array(

                                        'class'=>'CWebLogRoute',

                                ),

                                */

                        ),

                ),

        ),


        // application-level parameters that can be accessed

        // using Yii::app()->params['paramName']

        'params'=>array(

                // this is used in contact page

                'adminEmail'=>'webmaster@example.com',

        ),

);

Somehow I missed this excellent addition until just now! Thank you very much for posting this. I will include this in the next release unless you ask me not to. Thank you again.

That looks right. Would it be possible for you to turn on all logging to file (not just error and warning), then send me the log file so I can see what is going on? This is a curious case!

Can you please let me know how do i do that?

Sure thing. In your runtime directory (yourapp/protected/runtime) there will be an application.log file. You have your config file set up to log errors to it. The section that does this in your config file looks like this




		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

			),

		),



In that log section, change the "levels" value to look like this:




		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning, trace, info, notice',

				),

		),



then delete yourapp/protected/runtime/application.log file so we have a new log. Now make some updates/deletes/inserts on your test app. Once you run a few updates or inserts or what have you that you expect to log to audit_trail, then you should have a new file located at yourapp/protected/runtime/application.log.

Please post the contents of this file (if you don’t mind), or please pm the contents to me if you wish them to remain confidential and I hope I can see what is going on from the log!

My Log file:


2011/02/12 01:38:19 [trace] [system.CModule] Loading "log" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "request" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "urlManager" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.web.filters.CFilterChain] Running filter PoorController.filteraccessControl()

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "user" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "session" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "db" application component

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (64)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.CDbConnection] Opening DB connection

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (64)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `poor`

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (64)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `poor`

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (64)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.ar.CActiveRecord] Poor.insert()

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (72)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Executing SQL: INSERT INTO `poor` (`Last_Name`, `First_Name`, `Sex`, `Comment`) VALUES (:yp0, :yp1, :yp2, :yp3)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (72)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `tbl_audit_trail`

in C:\wamp\www\roopesh\protected\modules\auditTrail\behaviors\LoggableBehavior.php (51)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (72)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `tbl_audit_trail`

in C:\wamp\www\roopesh\protected\modules\auditTrail\behaviors\LoggableBehavior.php (51)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (72)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "coreMessages" application component

in C:\wamp\www\roopesh\protected\modules\auditTrail\behaviors\LoggableBehavior.php (61)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (72)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "log" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "request" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "urlManager" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.web.filters.CFilterChain] Running filter PoorController.filteraccessControl()

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "user" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "session" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "db" application component

in C:\wamp\www\roopesh\protected\models\Poor.php (21)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (158)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (54)

2011/02/12 01:38:19 [trace] [system.db.CDbConnection] Opening DB connection

in C:\wamp\www\roopesh\protected\models\Poor.php (21)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (158)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (54)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `poor`

in C:\wamp\www\roopesh\protected\models\Poor.php (21)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (158)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (54)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `poor`

in C:\wamp\www\roopesh\protected\models\Poor.php (21)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (158)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (54)

2011/02/12 01:38:19 [trace] [system.db.ar.CActiveRecord] Poor.findByPk()

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (158)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (54)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `poor` `t` WHERE `t`.`id`=1 LIMIT 1

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (158)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (54)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "widgetFactory" application component

in C:\wamp\www\roopesh\protected\views\poor\view.php (27)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (55)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "coreMessages" application component

in C:\wamp\www\roopesh\protected\views\poor\view.php (27)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (55)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "assetManager" application component

in C:\wamp\www\roopesh\protected\views\poor\view.php (27)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (55)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "clientScript" application component

in C:\wamp\www\roopesh\protected\views\poor\view.php (27)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (55)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:19 [trace] [system.CModule] Loading "format" application component

in C:\wamp\www\roopesh\protected\views\poor\view.php (27)

in C:\wamp\www\roopesh\protected\controllers\PoorController.php (55)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "log" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "request" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "urlManager" application component

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.base.CModule] Loading "auditTrail" module

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "db" application component

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (10)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.db.CDbConnection] Opening DB connection

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (10)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `tbl_audit_trail`

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (10)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `tbl_audit_trail`

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (10)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "clientScript" application component

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (12)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "widgetFactory" application component

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\_search.php (6)

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (37)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

2011/02/12 01:38:52 [trace] [system.db.ar.CActiveRecord] AuditTrail.count()

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (60)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.db.CDbCommand] Querying SQL: SELECT COUNT(*) FROM `tbl_audit_trail` `t`

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (60)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.db.ar.CActiveRecord] AuditTrail.findAll()

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (60)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `tbl_audit_trail` `t` LIMIT 10

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (60)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "assetManager" application component

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (60)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "coreMessages" application component

in C:\wamp\www\roopesh\protected\modules\auditTrail\views\admin\admin.php (60)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

in C:\wamp\www\roopesh\index.php (13)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "user" application component

in C:\wamp\www\roopesh\protected\views\layouts\main.php (34)

in C:\wamp\www\roopesh\protected\views\layouts\column1.php (7)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)

2011/02/12 01:38:52 [trace] [system.CModule] Loading "session" application component

in C:\wamp\www\roopesh\protected\views\layouts\main.php (34)

in C:\wamp\www\roopesh\protected\views\layouts\column1.php (7)

in C:\wamp\www\roopesh\protected\modules\auditTrail\controllers\AdminController.php (17)



I don’t see where you used your Audittest class to insert or update anything. I do see a table called poor. Also, the trace on the call looks a little weird. Can you post the code for the model that corresponds to the tablename of ‘poor’ please? Sorry to keep asking for stuff, but I am trying to trace through this to get it figured out! Also, I do have a hunch. What I expect to see in a stack trace on the database call to get the audit trail table structure is

index file -> controller file -> model file -> behavior file

what I see in your log file stack trace is

index file -> controller file -> behavior file

Is it possible that you have added the behavior to your controller instead of to your model for the table poor?

Sorry My Bad… I actually deleted the table and tried to recreated in poor table (i should have specified that)

This is my poor model file

and sorry for the trouble


<?php


/**

 * This is the model class for table "poor".

 *

 * The followings are the available columns in table 'poor':

 * @property integer $id

 * @property string $Last_Name

 * @property string $First_Name

 * @property string $Sex

 * @property string $Comment

 */

class Poor extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return Poor the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}

	/**

	 * @Calls Behaviors for an audit trail

	 */

	

	

	public function behaviors()

	{

    return array(

        'LoggableBehavior'=>

            'application.modules.auditTrail.behaviors.LoggableBehavior',

		);

	}

	

	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'poor';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('Last_Name, First_Name, Sex, Comment', 'required'),

			array('Last_Name, First_Name', 'length', 'max'=>10),

			array('Sex', 'length', 'max'=>5),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, Last_Name, First_Name, Sex, Comment', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'Last_Name' => 'Last Name',

			'First_Name' => 'First Name',

			'Sex' => 'Sex',

			'Comment' => 'Comment',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('Last_Name',$this->Last_Name,true);

		$criteria->compare('First_Name',$this->First_Name,true);

		$criteria->compare('Sex',$this->Sex,true);

		$criteria->compare('Comment',$this->Comment,true);


		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}

}

This is my controller file… I am sure that i did not add behavior in controller…


<?php


class PoorController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column2';


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	/**

	 * Displays a particular model.

	 * @param integer $id the ID of the model to be displayed

	 */

	public function actionView($id)

	{

		$this->render('view',array(

			'model'=>$this->loadModel($id),

		));

	}


	/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionCreate()

	{

		$model=new Poor;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Poor']))

		{

			$model->attributes=$_POST['Poor'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}


	/**

	 * Updates a particular model.

	 * If update is successful, the browser will be redirected to the 'view' page.

	 * @param integer $id the ID of the model to be updated

	 */

	public function actionUpdate($id)

	{

		$model=$this->loadModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Poor']))

		{

			$model->attributes=$_POST['Poor'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'index' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

		if(Yii::app()->request->isPostRequest)

		{

			// we only allow deletion via POST request

			$this->loadModel($id)->delete();


			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

			if(!isset($_GET['ajax']))

				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));

		}

		else

			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

	}


	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('Poor');

		$this->render('index',array(

			'dataProvider'=>$dataProvider,

		));

	}


	/**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		$model=new Poor('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Poor']))

			$model->attributes=$_GET['Poor'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}


	/**

	 * Returns the data model based on the primary key given in the GET variable.

	 * If the data model is not found, an HTTP exception will be raised.

	 * @param integer the ID of the model to be loaded

	 */

	public function loadModel($id)

	{

		$model=Poor::model()->findByPk((int)$id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}


	/**

	 * Performs the AJAX validation.

	 * @param CModel the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='poor-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

	}

}



I’m pretty stumped here. As a last effort for me to debug, would it be possible for you to zip up your protected folder and send it to me? I understand if you cannot because of secret stuff, but I do not see what is going on and I would like to debug it completely.

Ok, I think I see what the issue is. the files you sent me do not have a user object, nor is there any login functionality.

Is it possible that you have not done this yet (added database login functionality/ a user table)? Does your app keep track of who the user is?

Audit trail assumes there will be a user class, and that the user class will have an id that can be logged with the changes.

Please advise. The answer to this question will greatly impact what I do next.

Well…

i do have a login functionality which i get by default from yii setup

admin/admin

login/login

there is not table associated with it i think so…

Did adding database user login functionality fix the issue? Please let me know if you are still working on this.

I am sorry for the late reply. I have added YiiUser extension and it has user table from where uname and pwd is fetched. Even then it in not working.

This is my application runtime log


2011/02/22 20:45:34 [trace] [system.CModule] Loading "log" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "request" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "urlManager" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.web.filters.CFilterChain] Running filter PatientinfoController.filteraccessControl()

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "user" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "session" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "db" application component

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:34 [trace] [system.db.CDbConnection] Opening DB connection

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:34 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `patientinfo`

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:34 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `patientinfo`

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:34 [trace] [system.db.ar.CActiveRecord] Patientinfo.findByPk()

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `patientinfo` `t` WHERE `t`.`id`=2 LIMIT 1

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "widgetFactory" application component

in C:\wamp\www\edusoft\protected\views\patientinfo\_form.php (6)

in C:\wamp\www\edusoft\protected\views\patientinfo\update.php (18)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (102)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "messages" application component

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (43)

in C:\wamp\www\edusoft\protected\views\patientinfo\_form.php (38)

in C:\wamp\www\edusoft\protected\views\patientinfo\update.php (18)

2011/02/22 20:45:34 [trace] [system.base.CModule] Loading "user" module

in C:\wamp\www\edusoft\protected\views\layouts\main.php (37)

in C:\wamp\www\edusoft\protected\views\layouts\column2.php (23)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (102)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "coreMessages" application component

in C:\wamp\www\edusoft\protected\views\layouts\main.php (47)

in C:\wamp\www\edusoft\protected\views\layouts\column2.php (23)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (102)

2011/02/22 20:45:34 [trace] [system.CModule] Loading "clientScript" application component

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (102)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "log" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "request" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "urlManager" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.web.filters.CFilterChain] Running filter PatientinfoController.filteraccessControl()

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "user" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "session" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "db" application component

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:40 [trace] [system.db.CDbConnection] Opening DB connection

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:40 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `patientinfo`

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:40 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `patientinfo`

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

2011/02/22 20:45:40 [trace] [system.db.ar.CActiveRecord] Patientinfo.findByPk()

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `patientinfo` `t` WHERE `t`.`id`=2 LIMIT 1

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (88)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.db.ar.CActiveRecord] Patientinfo.update()

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (96)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.db.ar.CActiveRecord] Patientinfo.updateByPk()

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (96)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.db.CDbCommand] Executing SQL: UPDATE `patientinfo` SET `id`=:yp0, `Patient_id`=:yp1, `fname`=:yp2, `lname`=:yp3, `dob`=:yp4, `type_of_diabetes`=:yp5, `primary_lang`=:yp6, `edu_level_achieved`=:yp7, `race_ethnicity`=:yp8, `gender`=:yp9, `email`=:yp10, `inhouse_physician`=:yp11, `community_physician`=:yp12 WHERE `patientinfo`.`id`=2

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (96)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "log" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "request" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "urlManager" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.web.filters.CFilterChain] Running filter PatientinfoController.filteraccessControl()

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "user" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "session" application component

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "db" application component

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (54)

2011/02/22 20:45:40 [trace] [system.db.CDbConnection] Opening DB connection

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (54)

2011/02/22 20:45:40 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `patientinfo`

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (54)

2011/02/22 20:45:40 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `patientinfo`

in C:\wamp\www\edusoft\protected\models\Patientinfo.php (66)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (54)

2011/02/22 20:45:40 [trace] [system.db.ar.CActiveRecord] Patientinfo.findByPk()

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (54)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `patientinfo` `t` WHERE `t`.`id`=2 LIMIT 1

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (158)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (54)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "widgetFactory" application component

in C:\wamp\www\edusoft\protected\views\patientinfo\view.php (37)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (55)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "coreMessages" application component

in C:\wamp\www\edusoft\protected\views\patientinfo\view.php (37)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (55)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "assetManager" application component

in C:\wamp\www\edusoft\protected\views\patientinfo\view.php (37)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (55)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "clientScript" application component

in C:\wamp\www\edusoft\protected\views\patientinfo\view.php (37)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (55)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "format" application component

in C:\wamp\www\edusoft\protected\views\patientinfo\view.php (37)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (55)

in C:\wamp\www\edusoft\index.php (13)

2011/02/22 20:45:40 [trace] [system.base.CModule] Loading "user" module

in C:\wamp\www\edusoft\protected\views\layouts\main.php (37)

in C:\wamp\www\edusoft\protected\views\layouts\column2.php (23)

in C:\wamp\www\edusoft\protected\controllers\PatientinfoController.php (55)

2011/02/22 20:45:40 [trace] [system.CModule] Loading "messages" application component

in C:\wamp\www\edusoft\protected\modules\user\UserModule.php (141)

in C:\wamp\www\edusoft\protected\views\layouts\main.php (37)

in C:\wamp\www\edusoft\protected\views\layouts\column2.php (23)



Hello, I’m having access rules problems as well. I’m using a modified Yii-User-Management install for authentication and I tried echoing the user id in the index view and it’s fine but the access rules just don’t work. This is the access rule code I placed in the DefaultController:




   public function accessRules(){

           return array(

            array('allow',

                'actions' => array('index'),

                'roles' => array('Auditor', 'SiteAdmin'),

            ),

            array('deny',

                'users' => array('*'),

            ),

            );

        }



This is the code I placed in the index view and it prints out the user ID number just fine:




echo Yii::app()->user->id;



This has me puzzled six ways to Sunday since the module apparently sees my customized user class but does not do access control and the rest of the site’s access control works fine.

SOLVED========================================================

Erm… never mind I found out what was wrong. I added this function and all was right:




 public function filters()

    {

        return array(

            'accessControl',

        );

    }



thank you :rolleyes:

Hi guys the issue is solved…

The problem was that i did not have user name and password setup in an external table and connected it to the module.

Best Way to do it:

AuditTrailModule.php is very important and the code below defines how the extension should and will work.


/**

	 * @var string the name of the User class. Defaults to "User"

	 */

	public $userClass = "User";


	/**

	 * @var string the name of the column of the user class that is the primary key. Defaults to "id"

	 */	

	public $userIdColumn = "id";


	/**

	 * @var string the name of the column of the user class that is the username. Defaults to "username"

	 */	

	public $userNameColumn = "username";




[font=“Georgia”][size=“7”]This is an excellent extension and i love it [/size][/font] :D

Poorroop’s issue was that he needed to

  1. use a UserIdentity in his webapp that used an activerecord model forusername/password lookup. By default the yii webapp is create with an array based UserIdentity.

  2. he had a user table named something other than ‘User’. This is ok with auditTrail, but in the config you must specify the user class, the username column, and the id column if they are non-standard.

  3. make sure that changes can only be made by logged in users

Once he dd these thugs auditTrail worked fine for him

Thanks! The auditTrail extension does not require the user extension but I am glad to here that it works well with it!