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
Related
i have a little problem.
I'm developing a php application using Yii2 framework and i want to save a log messagges into db table.
I'm coding my own component witch extends DbTarget, in this component i rewrite export() function to save data into my table. It's works fine, but i can't get the log message.
For example, when i call Yii:log('message log'), all my data are saved in my db except 'message log' because i don't know how to get this value in my component.
Any solutions?
thanks
P.s. I'm newbee with yii2 and i have read the official documentation, but i didn't find any solution.
It seems you should specify level of the message
Yii:log('message log', Logger::LEVEL_TRACE);
or use shortcut methods
Yii::info('message log');
Yii::trace('message log');
Yii::error('message log');
Check your config for another targets. May be your message goes to level or category of another target. Notice that default category is 'application'.
To be shure you can make this configuration
'components' => [
'log' => [
'targets' => [
[
'class' => 'YourDbTarget',
'levels' => ['info'],
'categories' => ['application'],
],
],
],
],
And try to log info message
Yii::info('message log'); // target = info, category = application
I have a CakePHP 3.3.14 application where I've created 2 subdirectories, webroot/data/downloads/ and webroot/data/master
I want to put these paths in a custom configuration file and reference them in a Controller. But I can't see how to do this.
I've followed the documentation on Configuration but it's not very clear.
So what I've done:
Created config/my_config.php
The above file defines an array:
return [ 'downloadsPath' => 'webroot/data/downloads/', 'masterPath' => 'webroot/data/master/' ];
In config/bootstrap.php I've put: Configure::load('my_config', 'default');
How do I then use this in a Controller? If I put Configure::read('my_config.masterPath'); it gives an error saying: Class 'App\Controller\Configure' not found
If I add use Cake\Core\Configure; to the top of my Controller, that clears the error but the return value is null:
debug(Configure::read('my_config.masterPath')); // null
Loading another config file just extends the default App.config. So just use \Cake\Core\Configure::read('masterPath') and you are good.
EDIT
If it is your goal to have different config paths you could do it like this:
// my_config.php
return [
'MyConfig' => [
'masterPath' => '...',
...
]
];
Then use the config like this:
<?= \Cake\Core\Configure::read('MyConfig.masterPath') ?>
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'
I wanna use smarty template engine in yii2.
In my project, i need load view codes from database and render them from controller.
My question is this:
Is there any way to render a view code from string and control it like common render?
i need something like below:
$this->renderAsString($templateStr, ['param1'=>$val1, 'param2'=>$val2]);
this is important for me can access variable and function like as below code in index.tpl file.
$this->render('index.tpl'['param1'=>$val1, 'param2'=>$val2]);
I read this http://www.smarty.net/docs/en/resources.string.tpl but my answer is different, i think.
There is special separate extension called yii2-smarty for rendering views with Smarty. You need to install it via Composer, then configure like this for usage:
return [
//....
'components' => [
'view' => [
'renderers' => [
'tpl' => [
'class' => 'yii\smarty\ViewRenderer',
//'cachePath' => '#runtime/Smarty/cache',
],
],
],
],
];
As for your specific problem, look at these two issues on Github:
Add ability to render view from string
View renderer from db - not implemented yet
Core developer Klimov Paul recommends to use eval, but also in Smarty dedicated function exists exactly for these kind of situations.
Example 8.4. Another {eval} example
This outputs the server name (in uppercase) and IP. The assigned
variable $str could be from a database query.
<?php
$str = 'The server name is {$smarty.server.SERVER_NAME|upper} '
.'at {$smarty.server.SERVER_ADDR}';
$smarty->assign('foo',$str);
?>
Where the template is:
{eval var=$foo}
I am new to yii2, but I have been using Yii 1.x for quite a long time. I am using advanced template of Yii2 and implementing custom theme for the backend. I am using https://github.com/mithun12000/adminUI theme for the backend. I have set up my theme as follows:
install theme using composer
added theme support in backend/config/main.php as follows:
'view'=>[
'theme'=>[
'pathMap'=>['#app/views'=>'#webroot/themes/admin/views'],
'baseUrl'=>'#web/themes/admin'
]
],
Changed namespace app\assets; into namespace backend\assets; in backend/assets/AppAsset.php
I created my theme in web folder as backend/web/themes/admin and put my views there.
In my controller, to use the theme I just created, I put the following code:
$this->getView()->theme = Yii::createObject([
'class' => '\yii\base\Theme',
'pathMap' => ['#backend/views' => '#webroot/themes/admin/views'],
'baseUrl' => '#web/themes/admin',
]);
The login screen works fine. But if I have any widget, suppose Gridview, then I get namespace error. The error I get is:
Unknown Class – yii\base\UnknownClassException
Unable to find 'app\assets\AppAsset' in file: D:\projects\bmjobs\site\backend/assets/AppAsset.php. Namespace missing?
If I change the namespace in AppAsset.php to app\assets, then I get the following error:
PHP Fatal Error – yii\base\ErrorException
Call to a member function checkAccess() on a non-object
I am not sure where I went wrong. Can anybody please help me out with this?
Thanks in advance.
you may change your pathMap in backend/config/main.php
'pathMap' => ['#app/views' => '#app/themes/admin/views'],