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.
Related
how I can load an external-site module? I have a common module I need to load in distinct Yii2 sites, like advanced-template my idea is to have a common dir where store generic modules wich I can load to each site. A file system structure can be like this:
/
site-1/
(loads modules from common-modules dir for site-1)
site-2/
(loads modules from common-modules dir for site-2)
common_sites_modules/
module-1/
module-2/
carrello/
Carrello.php
Each site in his configuration have to load modules from common-modules/
Is possible to implement this structure?
Edit 1
The configuration:
'cart' => [
'class' => dirname(dirname(dirname(__DIR__))) . '/common_sites_modules/carrello/Carrello',
'params' =>[
...
],
'components' => [
...
],
],
and this is the first line of the class Carrello.php:
<?php
namespace common_sites_modules\carrello;
...
The top bar of editor with the path of the class and the error returned by Yii:
Edit 2:
Thanks to #Yupik for support and suggests, the new settings:
bootstrap.php:
Yii::setAlias('#common-modules', dirname(dirname(dirname(__DIR__))) . '/common_sites_modules');
main-local.php:
'class' => '#common-modules\carrello\Carrello',
The generated error:
Like suggested in the comments the solution is to declare an alias and then use the name of alias for call the module. Like suggested by #Yupik I've set in the common/config/bootstrap.php an alias as follow:
Yii::setAlias('#common_modules', dirname(dirname(dirname(__DIR__))) . '/common_modules');
In the main configuration:
'carrello' => [
'class' => ''common_modules\carrello\Carrello',
...
]
Obviously namespace have to be configured based on the position on filesystem.
Thanks for the suggestions
Yes, we can do this by making a symlink of common_sites_modules directory in both site folder (site1, site2).
Helle ZF2 Guru! Normally we get the zf2 translation file from a directory in Appliction module.config.php like this: 'base_dir' => DIR . '/../language' .
Is it possible to get it from a Uri?
Application module.config.php:
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',//http://example.com/
'pattern' => '%s.mo',
),
),
),
Why this is important?Correct me if I am wrong! In a multilingual application, language files are static files and for a real world application any static files better be on cloud like AWS CloudFront or CDON for better performance of Application and longer caching period.
I don't think this way is possible and I think it's not interresting to have this file outside the App directory because it's a part of your PHP software which will be interpreted and "compiled" by your web server at each HTTP request.
It's interresting for a JSON file downloaded by the navigator with AJAX request for example because the navigator will store the file in cache.
Our solution was to determine what is the current language in application.config.php:
define ('SITE_LANG', ...);
In our case it was simply the first two letters of the path:
www.site.com/en/...
Then in module.config.php:
'translator' => [
'locale' => SITE_LANG,
'translation_file_patterns' => [
[
'type' => 'phparray',
'base_dir' => 'vendor/zendframework/zendframework/resources/languages/',
'pattern' => '%s/Zend_Validate.php',
],
and it did the trick.
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.
I seem to have a problem configuring Yiistrap in the Yii basic template (which I used as a starting point for my web-site).
What I aim to do is adding icons in my NavBar and using an image file as the brand in the NavVar. It seems the normal NavBar of Yii is unable to do this as the "brand' option is not recognized.
So I installed YiiStrap using composer in my vendor directory. But then it is said in http://www.getyiistrap.com/site/started to adjust my main.php file (but here isn't one)!
So basically, how do I configure this correctly so I can add the extra features in the navbar?
Kind regards
Code which I used (composer):
Downloaded Yiistrap in /basic/vendor/2amigos/yiistrap
Config directory has these files:
console.php
db.php
main.php
params.php
web.php
The code of main.php is
<?php
// main configuration
return array(
// path aliases
'aliases' => array(
'bootstrap' => realpath(__DIR__ . '/vendor/2amigos/yiistrap'), // change this if necessary
),
// import paths
'import' => array(
'bootstrap.helpers.TbHtml',
),
// application modules
'modules' => array(
'gii' => array(
'generatorPaths' => array('bootstrap.gii'),
),
),
// application components
'components' => array(
'bootstrap' => array(
'class' => 'bootstrap.components.TbApi',
),
),
);
I'm following the method described here to have my control panel in backend folder.
The problem is I don't want to create two assets folders so I want to set assetManager baseUrl property in my backend/config/main.php but I'm enable to get the URL of the backend in the config. I don't want it hard coded because I need the code to be portable.
What can I do?
Thanks.
You can configure asset manager's baseUrl in /backend/config/main.php
'components' => array(
...
'assetManager' => array(
'class' => 'CAssetManager',
'baseUrl' => 'frontend.assets'
),
...