Working with the latest version of cakephp 3. I have a plugin I am trying to install. In the plugin folder I see it's using it's own bootstrap.php executing the following code.
Configure::config('default', new PhpConfig(dirname(APP) . DS . 'config' . DS));
Configure::load('recaptcha', 'default', false);
I created the file correctly - app/config/recaptcha.php
return [
'Recaptcha' => [
// Register API keys at https://www.google.com/recaptcha/admin
'sitekey' => 'your-sitekey',
'secret' => 'your-secret',
// reCAPTCHA supported 40+ languages listed
// here: https://developers.google.com/recaptcha/docs/language
'lang' => 'en',
// either light or dark
'theme' => 'light',
// either image or audio
'type' => 'image',
]
];
When I try to use
Configure::read('Recaptcha'));
I get a null result. My assumption is the way they are loading the config file is wrong, could anyone please advise?
Configure::config('default', new PhpConfig(dirname(APP) . DS . 'config' . DS));
Plugins should not be setting default config reader. It should be done in app's bootstrap. I suggest the plugin author to remove that line.
I created the file correctly - app/config/recaptcha.php
There's no "app" folder in standard Cake 3 folder structure.
Related
Which one is better to set directory folder for global usage?
Below are set to yii2 web config.
'aliases' => [
'#uploads' => 'uploads/csv',
],
Or in
'params' => [
'adminEmail' => 'admin#example.com',
'uploadCsv' => 'uploads/csv/',
];
If I am using the Yii Advanced template I prefer using the alias option.For the Yii basic template any will be fine.
Example: in the common/config/bootstrap.php of Advanced template
Yii::setAlias('#uploads', dirname(__DIR__) . '/uploads/csv');
I am using Yii2 and have been reading about theming and theme inheritance; however have some questions:
Consider the following example:
'view' => [
'theme' => [
'pathMap' => [
'#app/views' => [
'#app/themes/current',
'#app/themes/default',
],
],
'baseUrl' => '#web/themes/current',
'basePath' => '#webroot/themes/current',
],
],
Now, imagine we request the theme file foo; as I understand it this will first be looked for in the following order:
#app/themes/current/foo.php
#app/themes/default/foo.php
#app/views/foo.php
Now imagine foo.php isn't found in the #app/themes/current/ theme, so it would use the file found in #app/themes/default/.
Now, considering the baseUrl and basePath settings I am a little confused how these are used in these situations.
Now, imagine foo.php references an image file inside the file, wouldn't this still attempt to find #web/themes/current/images/myImage.jpg rather than #web/themes/default/images/myImage.jpg?
In this case, basePath is worthless. Because basePath is only applied when
pathMap is empty.
basePath is not a fallback, It is a shortcut of pathMap, quick use when you only have one theme.
'pathMap' => [
'#app/views' => [
'#app/themes/current/views',
],
],
Equivalent to:
'basePath' => '#app/themes/current',
(Yii understands that folder #app/themes/current/views exist)
baseUrl: It is returned when you call $this->theme->getBaseUrl() in view file. Less worth with multi theme.
About fallback for static files. Theming fallback is not designed for this purpose.
Point your links inside file like this exmaple from docs:
$theme = $this->theme;
// returns: $theme->baseUrl . '/img/logo.gif'
$url = $theme->getUrl('img/logo.gif');
// returns: $theme->basePath . '/img/logo.gif'
$file = $theme->getPath('img/logo.gif');
It will get file from current theme directory.
How to enable multitranslation in yii 2 basic framework? I have tried, but it is not working. I get no error, but translation is not showing. Code:
public function actionLang(){
$lang = \Yii::$app->request->get('lang');
if($lang && in_array($lang,['en-US','ar-SA'])){
$cookie = new Cookie();
$cookie->name = '_lang';
$cookie->value = $lang;
$cookie->expire = time() + 60 * 60 * 24 * 180;
\Yii::$app->response->cookies->add($cookie);
}
$this->redirect(['index']);
}
I'm using this function in SiteController.
Internationalization in Yii is not a one-action job. Here's the documentation on how to make your website multilingual:
https://github.com/yiisoft/yii2/blob/master/docs/guide/tutorial-i18n.md
If docs are unclear, here is a tutorial:
http://code.tutsplus.com/tutorials/programming-with-yii2-localization-with-i18n--cms-23140
If you have gone through all the steps and merely wish to set the current language, you can use:
\Yii::$app->language = 'xxx';
where xxx is a language code in accordance with ISO 639-2.
Here are the mentioned standard's entries:
http://www.loc.gov/standards/iso639-2/php/code_list.php
First of all, from what I have gathered, you are trying to identify a language requested from the current request by doing $lang = \Yii::$app->request->get('lang'); and then set it in the cookie. In my opinion, this should be used as a "helper", meaning, it is useful to know the language preference of the returning client, but you still have to manage languages via URL, i.e. http://yoursite.com/en or http://yoursite.com/de should serve different languages.
Now, there are actually very good plugins out there for multilingual URL management, such as yii2-localeurls , which you can find here. I use it in production in multiple projects and highly recommend it.
To actually manage translations, you have to have a folder in the root of your project (if you are using advance template, you should have it inside frontend/backend/console ) to store the actual block translations, call it messages .
Now, under #app/messages create folders for each non-default language, for example #app/messages/de for German translations.
If you go your config in #app/config/main.php, look for i18n key inside the components array. If you can't find such a key, simply put the following into the components array:
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
'sourceLanguage' => 'en',
'fileMap' => [
'app' => 'app.php',
'app/error' => 'error.php',
],
],
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
]
],
],
Now, you will need to create a translation file inside the relevant directory. In the above configuration, we declared that the default language used is en, that means that all original messages would be in English. Go to #app/messages/de and create a translations file inside that directory. You can call it whatever you like, but for this example, call it site.php.
In this site.php put the following:
return [
'Translate this!' => 'Your relevant translation here in whichever language',
'Translate this also!!!' => 'Stuff...'
];
If all done correctly, when you access your page via http://yousite.com/de, when using Yii::t('site', 'Translate this!') you should be getting 'Your relevant translation here in whichever language' instead.
The beauty of Yii 2 is that it is extremely well documented. Visit the official documentation if you are stuck, it really explains everything quite well.
In advanced app, I tried to implement divided authorization for backend and frontend.
In first case, I used User class from basic app, in order to use users without database. But for frontend part, I used User class from advanced app.
It would seemthat everything is working perfectly. But when you try to log in at the same time on both sides, the latter takes precedence over the previous one. Ie after entering the frontend parts - automatically eject the user from the backend and vice versa.
You have to set different cookies for frontend and backend in config/main.php file. For Eg.:
In backend:
'components' => [
'session' => [
'name' => 'BACKENDID', //Set name
'savePath' => __DIR__ . '/../tmp', //create tmp folder and set path
],
],
In Frontend:
'components' => [
'session' => [
'name' => 'FRONTENDID',
'savePath' => __DIR__ . '/../tmp',
],
],
I'm using zf2 RWOverdijk/AssetManager in a project built upon ZF2 Skeleton Application; it works fine for CSS and JS but can't resolve paths for IMG.
AssetManager configuration in Application/config/module.config.php contains:
namespace Application;
return array (
.
.
// assets manager
'asset_manager' => array(
'resolver_configs' => array(
'paths' => array(
'__NAMESPACE__' => __DIR__ . '/../public',
), // end asset manager paths
'caching' => array(
'default' => array(
'cache' => 'FilePath',
'options' => array(
'dir' => 'public',
)
)
), // end caching
), // end asset manager resolver
), // end assets manaApplicationger
.
.
);
The direcrory structure has:
module
Application
config
public
assets
Application
css
js
images
src
view
public
assets
Application
images
In the view template there is:
<?php
/* Include files */
$this->headScript()->appendFile($this->basePath() .'/assets/Application/js/dom-utils.js');
$this->headLink()->prependStylesheet($this->basePath() . '/assets/Application/css/home.css');
?>
<img src="<?php echo $this->basePath(); ?>/assets/Application/images/image.png" />
While it works fine for the CSS and Javascripts, it does not find the image unless i put it in the public/assets/Application/images directory.
I've recently started working with the AssetManager module and in my case it works with images as expected.
Maybe it was a bug in the version you use (I am working with the current stable release 1.4.1), but it could also be a caching issue, just delete the files in your cache directory or temporarly disable the cache to see if it works.