I’ll first describe my initial problem – I have a few site global variables (such as whether I’m online/offline, the price of the item etc).. I was wondering how best to store/retrieve these as they are needed on most pages.
In the end after some guidance I’ve opted to store them in a DB and create a component class (in Yii) to access them from where ever: e.g. echo Yii::app()->variables->price
I’m new to Yii, and I’ve been searching around but cannot find out how to properly interface a DB (AR Style) connection with a component.. So far I’ve created a Model class and the DB with columns 'id', 'name', 'value'
Just to get the hang of it I’m writing a method: getTestValue() in my component class, but I just don’t know how to go about retrieving the row with name test using Yii’s ActiveRecord. Could someone point me in the right direction please? 🙂
Many thanks!
This should work: