[TYPO3-mvc] How to read the settings from typoscript in a model
Sebastian Schreiber
me at schreibersebastian.de
Thu Nov 10 18:56:55 CET 2011
Am 08.11.2011 19:21, schrieb Sebastian Schreiber:
> Am 08.11.2011 18:54, schrieb Malte Beran:
>> Hi Georg,
>> I have an attribute called video. In getVideo() i check if a flv file
>> exists with the uid as filename.
>> The path to the files is stored in typoscript.
>>
>>
>> 2011/11/8 Georg Ringer<typo3 at ringerge.org>
>>
>>> Hi,
>>>
>>> Am 08.11.2011 16:51, schrieb Malte Beran:
>>>> Hi guys,
>>>> is it possible to read the ts settings from my ext within a model
>>>> (Tx_Extbase_DomainObject_AbstractEntity) ?
>>> no and this sounds like definitly wrong. what are you planning to
>>> do? ^^
>>>
>>> georg
>>> _______________________________________________
>>> TYPO3-project-typo3v4mvc mailing list
>>> TYPO3-project-typo3v4mvc at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>>
>>>
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
> I would create a service class:
>
> class Tx_MyExtKey_Service_SettingsService implements t3lib_Singleton {
>
> /**
> * @var mixed
> */
> protected $settings = NULL;
> /**
> * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
> */
> protected $configurationManager;
>
> /**
> * Injects the Configuration Manager and loads the settings
> *
> * @param Tx_Extbase_Configuration_ConfigurationManagerInterface
> An instance of the Configuration Manager
> * @return void
> */
> public function
> injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface
> $configurationManager) {
> $this->configurationManager = $configurationManager;
> }
>
> /**
> * Returns all settings.
> *
> * @return array
> */
> public function getSettings() {
> if ($this->settings === NULL) {
> $this->settings =
> $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
> }
> return $this->settings;
> }
>
> /**
> * Returns the settings at path $path, which is separated by ".",
> e.g. "pages.uid".
> * "pages.uid" would return $this->settings['pages']['uid'].
> *
> * If the path is invalid or no entry is found, false is returned.
> *
> * @param string $path
> * @return mixed
> */
> public function getByPath($path) {
> return
> Tx_Extbase_Reflection_ObjectAccess::getPropertyPath($this->getSettings(),
> $path);
> }
>
> }
>
> If you are using Extbase 1.4 you can have an injectMethod in your Model:
>
> /**
> *
> * @param Tx_MyExtKey_Service_SettingsService $settingsService
> */
> public function
> injectSettingsService(Tx_MyExtKey_Service_SettingsService
> $settingsService) {
> $this->settingsService = $settingsService;
> }
>
>
> And then you can call your ts-setting in your model via
>
> $this->settingsService->getByPath('yourSetting);
>
> ------------
>
> But as Georg mentioned, you should try to avoid such things.
>
> Good luck
>
I don´t want to be rude, but it´s always nice to get some feedback if
somebody points someone in a direction.
Could you achieve something?
--
Sebastian Schreiber
(Medieninformatiker B.Sc.)
(TYPO3 Certified Integrator)
Schanzenstraße 27, Schlosserei 4
D-51063 Köln
T 0221 677 88 541
M 0176 431 05 790
Skype schreibersebastian.de
me at schreibersebastian.de
www.schreibersebastian.de
Steuernummer: 217 / 5269 / 4675
More information about the TYPO3-project-typo3v4mvc
mailing list