We are building a web application using Yii as the framework. Where would be a good location for us to put a version information array?
This version array is not the version of Yii but the version our application is on. This way we can use it global throughout the application. Example when deploy the application on our servers we can have a conditional that compares the required_php_version against the server's php version (phpversion()) to throw errors. This is just a simple example.
The array would consist of (with possibility to evolve later):
<?php
array(
'version' => '2.0.1',
'required_php_version' => '5.4.4'
);
?>
As far as I know, The best place to put your configurations in an application based on Yii, is main.php config file, which is situated in protected/config/main.php. But it is important to put your custom configurations in a right place. That is in params array. You can put your configs like below in config file:
'params' => array(
'webmaster' => 'YourEmail#example.com',
'required_php_version' => '5.4.1',
'my_app_version'=>'2.0.1.1',
'info_in_array'=>array(1,2,3,4,'so on ...')
// and so on
),
You can use these information in everywhere of your application like below:
Yii::app()->params['required_php_version'] //which returns 5.4.1 in this example.
Related
I am building a site that uses ar and en languages, and according to the silverstripe docs here, I did the text collection process and went successful. but only one en.yaml file is created in the lang folder in my current theme. there should be another ar.yaml file!.
here's my _config.php file:
<?php
global $project;
$project = 'mysite';
FulltextSearchable::enable();
global $databaseConfig;
$databaseConfig = array(
'type' => 'MySQLDatabase',
'server' => 'localhost',
'username' => 'dbuser',
'password' => '123',
'database' => 'cont_learning_2',
'path' => ''
);
// Set the site locale
i18n::set_locale('ar_EG');
Director::set_environment_type('dev');
if(!Director::isDev()) {
// log errors and warnings
SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors-warnings.log'), SS_Log::WARN, '<=');
// or just errors
SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors.log'), SS_Log::ERR);
// or notices (e.g. for Deprecation Notifications)
SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors-notices.log'), SS_Log::NOTICE);
}
Security::setDefaultAdmin('admin','admin');
// multi-language configuration - translatable module
Translatable::set_default_locale('ar_EG');
Translatable::set_allowed_locales(array(
'ar_EG',
'en_US',
));
SiteTree::add_extension('Translatable');
The text-collector task isn't aware of the possible locales your installation will/can have. So it basically just collects all strings and puts them in a default yml file.
If you have an en.yml file, copy it as ar.yml, make sure it starts with ar: instead of en: and translate all text to Arabic.
Using https://github.com/Zauberfisch/silverstripe-better-i18n you are able to create and update different languages in one task. You can install it with composer as a development-only requirement.
I run it like
http://localhost/dev/tasks/BetterI18nTextCollectorTask?module=mysite,themes/my-theme&targetlocale=de,en
to create german and english yml files in mysite and themes/my-theme.
It will create a bunch of items prefixed with double underscore (as pseudo comments) and also the default keys for your database fields.
I have created a custom Drupal 8 module that works as is with a custom block and block form to collect some info.
This is all good.
I also have a twig template that I want to render a twitter feed using a php feed class I bought. I just don't know how it integrate this into the module.
This is the setup for the class: http://austinbrunkhorst.com/demos/twitter-class/#setup
It contains two files:
ultimate.twitter.feed.php
and
tmhOAuth.php
Which is currently a require_once 'tmhOAuth.php'; in the head of ultimate.twitter.feed.php
According to the instruction I should be creating a php file that has this:
$options = array(
'screen_name' => 'FeedTestUser',
'consumer_key' => '...',
'consumer_secret' => '...',
'user_token' => '...',
'user_secret' => '...',
);
$twitter = new Twitter($options);
$twitter->PrintFeed();
Which I'm guessing is also a hurdle as twig files are not php
Any help with this is very much appreciated.
C
I would setup the class as a Service in your module. Your block will then implement that service and do the handling. You don't really want to use require_once() if you can avoid it, rather use Drupal constructs (in part so that if you reorganize things later Drupal will help find the files in their new location).
Place the class in your module's src directory, and add a namespace to the start of the file (assuming there isn't one there already). Then in your block's class file you should be able to add a use statement that references that name space (even better would be to use a dependency injection, but the details on that would get in your way here).
In your block class's build() method you then instantiate the class as described in your question, but instead of just letting the module print HTML, you can want to capture that HTML and place it into your block as markup. If the class allows you to do that without using a buffer, you should (but I didn't see anything in the docs to support that), and then attempt to theme the structured data. If not, you can use PHP's output buffering to capture its attempt to print:
ob_start();
$twitter->PrintFeed();
$content= ob_get_contents();
ob_end_clean();
Then place the generated markup into a render array:
return [
'my_twitter_block' => [
'#markup' => $content,
],
];
Create a custom block and add the result of PrintFeed() to the render array. Just as with any usual custom block. In the render array you can specify a template which should be used (if needed). If you wanna output pure html without any template you could use the '#markup' key.
Small example:
Your block render array:
return array(
'#theme' => 'name_of_your_theme',
'#some_twig_variable' => $twitter->PrintFeed();
);
your your_module.module file (in the root of your module folder):
function your_module_theme() {
return array(
'name_of_your_theme' => array(
'variables' => array(
'some_twig_variable' => some-default-value,
),
),
);
}
your name-of-your-theme.html.twig template (should be under your_module/templates):
{{ some_twig_variable }}
As far as using the class: I see no problem using a require_once for that matter (in your Block php file). Of course it's always better/nicer if you can require the library/package via the make file or composer and then use the autoloader, but if that's not possible just put it e.g. in your drupal root under /libraries/twitter or so and then require it. If you do it like that you have to check that library into your git repository obviously.
have you use ultimate.twitter.feed.php in your TwitterBlock.php file
If not then try adding this line before class block beginns:
require_once 'path/to/twitter_class/ultimate.twitter.feed.php';
It should be "trivial", but after some chating on #laravel irc channel, I found it may be impossible for now. But I'll ask it here before doing it the ugly-go-horse way just to have the project done. If it's indeed impossible by current means, I'll fill a request on github (after handing over the project to my client).
I'm using Zizaco\Confide to handle authentication in my service. It uses Laravel Lang everywhere to get strings in one of the 8 bundled languages of the package. But I need to override some of those strings, and I don't want to modify the package files (which would defeat the whole purpose of Composer). How can I do this?
For example, I needed to modify confide::confide.alerts.wrong_credentials for pt_BR language. What I tried so far:
/app/lang/pt_BR/confide.php file, with contents return array('alerts' => array('wrong_credentials' => '...')). It works for Lang::get('confide.alerts.wrong_credentials') but not for the namespaced Lang::get('confide::confide.alerts.wrong_credentials')
/app/lang/pt_BR/packages/zizaco/confide/confide.php with return array('alerts' => ......)
/app/lang/pt_BR/packages/zizaco/confide/confide/alerts.php with return array('wrong_credentials' => ...)
/app/lang/packages/zizaco/confide/pt_BR/confide.php with array('alerts' => array('wrong_credentials' => '...')) - /app/lang/packages/zizaco/confide/pt_BR/confide/alerts.php with return array('wrong_credentials' => ...)
Any clue on what am I missing? Or does Laravel4 really lacks this feature?
Thanks in advance!
actually it fixed in Laravel 4.1 core
you can now overwrite it by doing
app/lang/packages/(locale)/confide/confide.php
check this
laravel 4 language issue
correct path for overriding package languages
So, as for today, Laravel really does lack this feature.
I've asked for it creating a issue on github.
Meanwhile, this functionality could be achieved seamlessly using crynobone's Orchestra Platform 2 Translation Component, which can be found here
All you need to do is require it in composer.json
{
"require": {
"orchestra/translation": "2.0.*"
}
}
and replace the original translation package ('Illuminate\Translation\TranslationServiceProvider') in /config/app.php
'providers' => array(
//'Illuminate\Translation\TranslationServiceProvider',
// ...
'Orchestra\Translation\TranslationServiceProvider',
),
That's it! Now, having app/lang/en/packages/confide/confide.php will do it!
(please note that the path should be /packages/packagename/, not /packages/vendor/packagename/
It really saved me from a big headache, hope others find this useful too.
I need to implement Zend Translation in a project that is made in Core PHP that is i don't want to use Full ZF Just Zend Translation Classes that is used for Translation.
How would i do that means how would i start ?
which classes i need to add ??
i need the Flow that how would i do this ??
You need to copy these files from Zend Library
Zend_Translate.php and Zend_Translate (directory) everything else is in documentation.
You are wrong in thinking that docs says about implementation in ZF.
Here is example page:
First code snippet from above page:
try {
$translate = new Zend_Translate(
array(
'adapter' => 'Company_Translate_Adapter_MyFormat',
'content' => '/path/to/translate.xx',
'locale' => 'en',
'myoption' => 'myvalue'
)
);
} catch (Exception $e) {
// File not found, no adapter class...
// General failure
}
As you see, there is only Zend_Translate class used.
All zend library is developed to be quite standalone, which means that you can separate classes by theirs functionalities (you can do it by copy files using class names). More informations you can find in documentation (as always ;))
how we could create translate validate error messages on zend framework?
someone could give a example ?
thanks
From the ZF Manual on Zend_Validate Validation Messages
$validator = new Zend_Validate_GreaterThan();
$validator->setMessage('Please enter a lower value',
Zend_Validate_GreaterThan::NOT_GREATER);
And also:
Zend Framework is shipped with more than 45 different validators with more than 200 failure messages. It can be a tendious task to translate all of these messages. But for your convinience Zend Framework comes with already pre-translated validation messages. You can find them within the path /resources/languages in your Zend Framework installation.
[...]
So to translate all validation messages to german for example, all you have to do is to attach a translator to Zend_Validate using these resource files.
$translator = new Zend_Translate(
'array',
'/resources/languages',
$language,
array('scan' => Zend_Locale::LOCALE_DIRECTORY)
);
Zend_Validate_Abstract::setDefaultTranslator($translator);
Of course, you can also provide your own translations. All you have to do is load make them available to the translation adapter. Basically you just swap out the part shown above to your custom path.
I just want to improve a little bit the answer from Gordon:
a working example is
$translator = new Zend_Translate(
'array',
'resources/languages', // you need to copy the resources folder
// (from your Zend Framework installation)
// in the application folder
'it', // 'it' for italian, 'fr' for french, etc.
// Just look at the directories
// Zend_Translate, NOT Zend_Locale
array(
'scan' => Zend_Translate::LOCALE_DIRECTORY
)
);
Zend_Validate_Abstract::setDefaultTranslator($translator);
Cheers!
Bruno