ZEND tralslations for addMultiOption text in Form for poEdit - zend-framework

I dont have an idea why translations are not working in with Zend_Form.
I would like to be able translate options for selects.
For now i have something like this:
my form class:
(...)
$this->translate = Zend_Registry::get('translate');
Zend_Form::setDefaultTranslator( Zend_Registry::get('translate') );
(...)
$select = new Zend_Form_Element_Select('select');
// $select->addMultiOption('0', $this->translate('Aktywny'));
$select->addMultiOption('0', $this->translate->_('Aktywny'));
$select->addMultiOption('1', 'Nieaktywny');
in my bootstrap file i have something like this:
protected function _initTranslate()
{
Zend_Loader::loadClass('Zend_Translate');
Zend_Loader::loadClass('Zend_Registry');
$translate = new Zend_Translate('gettext', APPLICATION_PATH.'/languages',
'browser',
array('scan' => Zend_Translate::LOCALE_FILENAME));
//changing language and setting it to session if changed
$session = new Zend_Session_Namespace('jezyk');
if(isset($session->language)) {
$translate->setLocale($session->language);
} else
$translate->setLocale('pl');
$registry = Zend_Registry::getInstance();
$registry->set('Zend_Translate', $translate);
}
and it works fine for controllers, phtml files and plugins where i call it by
$this->translate('string to translate');
and in plugins
$this->view->translate('string to translate');
but those methods won't work in form. It throws exception:
Warning: Exception caught by form: No entry is registered for key 'translate' Stack Trace: #0

to make it working as i wrote in comment just have to change line:
$this->translate = Zend_Registry::get('translate');
for
$this->translate = Zend_Registry::get('Zend_Translate');
cause i didn't saw that i'm getting wrong translate from registry. It should be Zend_Translate like in Bootstrap file, not translate as i did.
And this is solution for my problems with translate and now i can make translations in form files :)

Related

Writing to extConf in extbase controller

I have a litte extbase extension that changes my color settings (e.g. css, cookiebar, etc.), and I also want to change the color of the backend plugin button, in the backend sysext in my controller.
Getting the value:
$var = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['backend']);
$var["loginHighlightColor"]="#444444";
But now, how do I save the value?
When trying the following statement, it sets the value correctly but it doesn't get persisted:
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['backend'] = serialize($var);
Even trying to persist manually with the PersistentManager doesn't work.
Thanks to Bernd Wilke I got it:
$var = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['backend']);
$var["loginHighlightColor"]="#444444";
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['backend'] = serialize($var);
$configurationUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
$newConfiguration = $configurationUtility->getCurrentConfiguration("backend");
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($newConfiguration, $var);
$configurationUtility->writeConfiguration(
$configurationUtility->convertValuedToNestedConfiguration($newConfiguration),
"backend"
);
This is how it works inside my AdditionalConfiguration.php. Maybe you can adapt it:
$resourcePath = 'EXT:' . $extKey . '/Resources/Public/Images/';
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['backend'] = serialize(
[
'loginLogo' => $resourcePath . 'logo.svg',
'loginHighlightColor' => '#c0c0c0',
'loginBackgroundImage' => $resourcePath . 'login-bg.svg',
]
);
you propably need to do the same than found here:
http://api.typo3.org/typo3cms/current/html/_configuration_controller_8php_source.html#l00156
as that function is protected you can't call it from your code.
there are two public functions you possibly can use:
public function saveAction(array $config, $extensionKey) (line 109)
public function saveAndCloseAction(array $config, $extensionKey) (line 131)

zend session namespace not working

I am unable to access zend session in included file via layout.
what i have done so far -
//bootstrap
public function _initSession()
{
Zend_Session::start();
$test = new Zend_Session_Namespace('test');
}
//controller
public function init(){
$test = new Zend_Session_Namespace('test');
$test->abc = 'defghi';
}
//layout include file
<?php include_once( APPLICATION_PATH . '/data/ga_test.php');?>
//ga_test.php
$test = new Zend_Session_Namespace('test');
echo 'this is ' . $test->abc;
I am not able to access the variable in ga_test file. I am getting an empty variable. But if I include ga_test end of each view file then it works. Obviously I don't want to go to every view file and include ga_test.php. Can I do this via layout.
I am sure, I am doing something wrong here. Any help would be really appreciated.
Thanks

how to use insert record function in moodle

I am trying to insert record into my database using moodle.
I am using version 1.9.19. i am trying the following code :
<?php
require_once('config.php');
require_once('uplo.php');
$mform = new uplo();
$mform->display();
if(isset($_POST['submitbutton'])){
$name = $mform->get_data('name');
$email = $mform->get_data('email');
$table='mdl_tet';
$res=insert_record($table, '$name','$email') ;
}
?>
But this is not working correctly. How to do that correctly.
Note : Why am using 1.9.19 means my client using this version so i cant change the version.
The insert_record() function takes two parameters - the name of the table (without the prefix) and an object containing the data to insert into the table.
So, in this case, you should write something like:
$ins = (object)array('name' => $name, 'email' => $email);
$ins->id = insert_record('tet', $ins);
OR:
$ins = new stdClass();
$ins->name = $name;
$ins->email = $email;
$ins->id = insert_record('tet', $ins);
(As an aside - make sure you turn on debugging - https://docs.moodle.org/19/en/Debugging - it will make your life a lot easier).

Gettext and Zend Translate, using multiple languages

I have the following setup in my application Bootstrap.php
protected function _initTranslation()
{
$langPath = APPLICATION_PATH.'/languages/';
$translate = new Zend_Translate_Adapter_Gettext($langPath . 'site-ro.mo', 'ro');
$translate = new Zend_Translate_Adapter_Gettext($langPath . 'site-en.mo', 'en');
$translate->setLocale('en');
Zend_Registry::set('Zend_Translate', $translate);
}
and in my add.phtml file I have it like this
<label for="page_title" class="sr-only"><?= $this->translate("Page title") ?></label>
I know this works only if i have the setLocale to 'en' and if there exists an translation. But i don't know how to set for multiple translations and also not to throw errors if the .po file doesn't have a translation.
look at here:
Additional features for translation
You can always change your language in controller by these code :
$translate = Zend_Registry::get('Zend_Translate');
$translate->setLocale('ro');
after that your locale will be changed.

zfdatagrid - Plugin by name 'Table' was not found in the registry;

I've just installed the library and tried a simple table with an array
$grid = Bvb_Grid::factory("Bvb_Grid_Deploy_Table");
$grid->setSource(new Bvb_Grid_Source_Array($this->pkg));
$myGrid = $grid->deploy();
I get this error:
Plugin by name 'Table' was not found in the registry; used paths: Bvb_Grid_Template_: Bvb/Grid/Template/
I'm not familiar with how this works, but would guess looking at the error that it looks in the Bvb/Grid/Template/ directory, there is a Table.php in there with the class Bvb_Grid_Template_Table.Thank you.
Try a little bit different. Write "Table" instead of "Bvb_Grid_Deploy_Table". In my example there is also grid configuration file...
$config = new Zend_Config_Ini(dirname(__FILE__) . '/../configs/grid.ini','clients');
$grid = Bvb_Grid::factory('Table', $config);
$model = new Sand_Model_DbTable_Asset();
$source = new Bvb_Grid_Source_Zend_Table($model);
$grid->setSource($source);
/*
more code here...
*/
$myGrid = $grid->deploy();
$this->view->grid = $myGrid;