Following https://docs.zendframework.com/zend-navigation/quick-start/, i try to make a navigation for my application. I registered a navigation, i added the DefaultNavigationFactory to the service-manager, but i get an error when i try to print the navigation.
This is my module/Application/config/module.config.php:
namespace Application;
use Zend\Navigation\Service\DefaultNavigationFactory;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\View\Helper\Navigation;
return [
'navigation' => [
'default' => [
/* ... */
]
] ,
'service_manager' => [
'factories' => [
'navigation' => DefaultNavigationFactory::class,
],
],
];
But when $this->navigation('default')->menu(), i get this error, excluding the stack trace:
Fatal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: A plugin by the name "navigation" was not found in the plugin manager Zend\View\HelperPluginManager in C:\Users\bikke_000\Documents\Sites\slapenenzo\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php:133
Running
composer require zendframework/zend-navigation
fixed the issue it seems that in zf3 navigation isn't installed by default
In addition to the answer of #Ponsjuh I had to include the module "Zend\Navigation" in my modules config.
you need to pass 'navigation' instead of 'default' as below:
$this->navigation('navigation')->menu();
Check your "development mode". In production mode, 'config_cache_enabled' is true. When you install new module, you must refresh cache.
Default: 'data/cache/module-config-cache.application.config.cache.php'
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).
I’m getting error “Undefined class Meta” on my laravel blog application. Also it doesn't provides the title on output. On html output I get blank . Is it problem because of Undefined class Meta? If then how can I define that class on blade engine? Any idea?
Check screen shot to understand
Looks like you haven't installed the package but you're trying to use it.
First, type composer require eusonlito/laravel-meta
Then, in your config/app.php add:
'providers' => [
'...',
Eusonlito\LaravelMeta\MetaServiceProvider::class
];
'aliases' => [
'...',
'Meta' => Eusonlito\LaravelMeta\Facade::class,
];
Then retry. Your app should work
Right now I'm trying to implement themming for my Yii2 based project.
How I see the thing now:
User chooses an application theme from the list on the settings
page in backend.
Using yii2-settings I'm saving all the
configuration data in DB (pretty easy).
In the application
bootstrap.php I'm creating new alias called #theme. Basically it
should lead us to a application theme base path (used in search
paths, assets manager, e.t.c.).
According to official
documentation, that's how I configured my view component:
'view' => [
'theme' => [
'basePath' => '#theme',
'baseUrl' => '#theme',
'pathMap' => [
'#app/views' => '#theme',
'#app/widgets' => '#theme/widgets',
'#app/modules' => '#theme/modules',
],
],
],
An issue I have is with p.3. According to yii2-settings documentation that's how I supposed to read the settings:
$theme = Yii::$app->settings->get('name', 'general');
Yii::setAlias('#theme', realpath(dirname(__FILE__)."/../../themes/$theme"));
But obviously, it's not working for me because of yii2-settings component didn't initialized yet when bootstrap.php is called. I've been trying to initialize it later in the init() method of my base controller, then adjust other aliases manually, but I feel that way being somewhat 'unclean', and also it still fails because of #theme alias is also used in asset file which is Yii2 starting to publish before calling the controller's init method.
So does anyone has any thoughts of how to do that 'hacking' the code as less as possible? I know I could just move configuration to some file, then read it manually before the application initialization, but it's still not the way I want to go.
Maybe there's some way to override some system component to set the alias after db component is loaded, but before view component configuration? Or Yii loads this components in a different order? Anyway. Any help would be appreciated!
You could try an Application Event in bootstrap:
\Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function ($event) {
$theme = Yii::$app->settings->get('name', 'general');
Yii::setAlias('#theme', realpath(dirname(__FILE__)."/../../themes/$theme"));
});
OR in configuration file:
[
'on beforeRequest' => function ($event) {
// ...
},
]
From Yii 2 docs:
EVENT_BEFORE_REQUEST This event is triggered before an application
handles a request. The actual event name is beforeRequest.
When this event is triggered, the application instance has been
configured and initialized. So it is a good place to insert your
custom code via the event mechanism to intercept the request handling
process. For example, in the event handler, you may dynamically set
the yii\base\Application::$language property based on some parameters.
Here's the final solution:
config/bootstrap.php:
// Setting a temporary path for components configuration - will be changed later
Yii::setAlias('#theme', realpath(dirname(__FILE__)."/../../themes/"));
config/main.php
'components' => [
'view' => [
'theme' => [
'basePath' => '#theme',
'baseUrl' => '#theme',
'pathMap' => [
'#app/views' => '#theme',
'#app/widgets' => '#theme/widgets',
'#app/modules' => '#theme/modules',
],
],
],
],
'on beforeRequest' => function ($event) {
$theme = Yii::$app->settings->get('theme', 'general');
Yii::setAlias('#theme', realpath(dirname(__FILE__)."/../../themes/$theme"));
},
I wrote a module in the backend with this name space:
namespace backend\modules\payment;
so if I move module to another project in frontend the module will broke;
and another problem is that I add module with name "payment" in config
'payment' =>
[
'class' => 'backend\modules\payment\Bank',
'components' =>
[
'service' =>
[
'class' => 'backend\modules\payment\components\Service',
]
]
]
and I get full url to actionReturn in module's "service" component using this method:
public function getReturnUrl()
{
return \yii\helpers\Url::toRoute('payment/return',true);
}
now if I want to change module name in another project , I have to go and change all this functions to get valid url ,
is there any way to fix this and action's url not be depended on module name
If you create the module in your vendor namespace you ca refer to the module always with the same url / routing
and you can easy install the module copyng tour vendor subdir
vendor\yourVendorName\yourModuleName\
configure properly the module.php and add in modules section in main.php
If you think the module you assign in config/main.php could conflit with other module you shoudl assign to your module a proper name.
The name use in url for module is the name you assign in config/main.php section modules
this way:
'modules' => [
.....
'auth'=> [
'class' => 'vendor\dfenx\auth\Module',
],
'yourModuleName' => [
'class' => 'vendor\yourVendorName\yourModuleDir\Module',
],
'anotherModuleName' =>[
'class' => 'vendor\anotherVendorName\anotherModuleDir\Module',
],
.....
],
obviously the modules name yourModuleName and anotherModuleName can't be the same otherwise the ruoting based on the url can't work properly.
In last you could assigne the name of your module in the url to a vars and mapping to this var the module name you assign in the config. In this way the name of module and the related name in url are completed easily remappable.
I hope this is useful for you
Using the config.php always_load configuration, how does one load a language file from a package?
All of the fuelphp documentation alludes to being able to do this, but only shows the syntax for loading from a module.
Here's what I'm trying to do:
fuel/app/config/config.php
'always_load' => [
'language' => [
// loads fuel/app/lang/en/login.php into login group
'login',
],
],
fuel/app/config/production/config.php
'always_load' => [
'language' => [
// override /config/config.php with contents from
// /fuel/packages/pkg/lang/en/login.php
'lang_file_from_package' => 'login',
],
],
Packages are core extensions, which means it will merge the contents of the files found in app and in the package.
As such, there is no method to define you want to load it from the package only, other then by specifying a fully qualified pathname, which will always load just that file.