CDbMessageSource
CDbMessageSource represents a message source that stores translated messages in database.
The database must contain the following two tables:
CREATE TABLE SourceMessage
(
id INTEGER PRIMARY KEY,
category VARCHAR(32),
message TEXT
);
CREATE TABLE Message
(
id INTEGER,
language VARCHAR(16),
translation TEXT,
PRIMARY KEY (id, language),
CONSTRAINT FK_Message_SourceMessage FOREIGN KEY (id)
REFERENCES SourceMessage (id) ON DELETE CASCADE ON UPDATE RESTRICT
);
The 'SourceMessage' table stores the messages to be translated, and the 'Message' table
stores the translated messages. The name of these two tables can be customized by setting
sourceMessageTable and
translatedMessageTable, respectively.
When
cachingDuration is set as a positive number, message translations will be cached.
Property Details
public string $cacheID;
the ID of the cache application component that is used to cache the messages.
Defaults to 'cache' which refers to the primary cache application component.
Set this property to false if you want to disable caching the messages.
public integer $cachingDuration;
the time in seconds that the messages can remain valid in cache.
Defaults to 0, meaning the caching is disabled.
public string $connectionID;
the ID of the database connection application component. Defaults to 'db'.
public string $sourceMessageTable;
the name of the source message table. Defaults to 'SourceMessage'.
public string $translatedMessageTable;
the name of the translated message table. Defaults to 'Message'.
Method Details
Initializes the application component.
This method overrides the parent implementation by preprocessing
the user request data.
|
protected array loadMessages(string $category, string $language)
|
| $category |
string |
the message category |
| $language |
string |
the target language |
| {return} |
array |
the loaded messages |
Loads the message translation for the specified language and category.