Yii Framework Forum: Catchallrequest Using Database Query - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Catchallrequest Using Database Query Rate Topic: -----

#1 User is offline   David Walker 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-August 12

Posted 19 July 2013 - 11:56 AM

I have created a web application based around Nagios and everything is working fine except that when the Nagios process there is a delay before all the data is written from the program at startup into the mysql database.

I have found that there is a table called programstatus that is empty when the program is restarting but once complete contains one and only one record.

I had built some logic into the main layout file that did

if(ProgramStatus::model()->count() == 0)
	echo "Site down"; //this is just for example I will use a renderpartial in reality
	yii::app()->end();
end if



This works but doesnt seem the correct way to do this. I have tried the Yii method of using 'catchAllRequest' in the config/main.php file

'catchAllRequest' => (Programstatus::model()->count() == 0) ? array('site/maintenance') : null,


However this causes problem because yii isn't initialized yet and I get errors like

include(Programstatus.php): failed to open stream: No such file or directory


and if I use php to include the file I then get issues with the database connection

Uncaught exception 'CDbException' with message 'Active Record requires a "db" CDbConnection application component.


I think I understand why this is happening but is there a better way to achieve my goal elegantly.

Thanks

Dave
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users