Namespace error when using gridview using custom theme in yii2 - php

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'],

Related

config helper bootstrap 4 in cakephp 3

I have installed cakephp plugin twbs/bootstrap via composer
composer require twbs/bootstrap:4.0.0
was successfully and loaded in bootstrap.php
Pugin::loadAll();
next setting is helper modified,
when I looked config helper bootstrap3 in elboletaire/twbs-cake-plugin
the setting helper seem like
//in AppController.php
public $helpers =[
'Less.Less',
'BootstrapUI.Form',
'BootstrapUI.Html',
'BootstrapUI.Flash',
'BootstrapUI.Paginator'
];
and loading of them in AppView.php
public function initialize()
{
$this->loadHelper('Less', ['className' => 'Less.Less']);
$this->loadHelper('Html', ['className' => 'BootstrapUI.Html']);
$this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']);
$this->loadHelper('Form', ['className' => 'BootstrapUI.Form']);
$this->loadHelper('Paginator', ['className' = 'BootstrapUI.Paginator']);
}
the questions, where is config helper bootstrap4, since I'm newbie and interest with twitter bootstrap4 which combine cakephp 3.5.11, thanx for anyone to help me
twbs/bootstrap isn't a CakePHP plugin, it's just Bootstrap. elboletaire/twbs-cake-plugin is a CakePHP plugin, and it doesn't support Bootstrap 4 yet.
https://github.com/elboletaire/twbs-cake-plugin/issues/6
FriendsOfCake/bootstrap-ui will probably be Bootstrap 4 ready soon, so maybe keep an eye on that.
https://github.com/FriendsOfCake/bootstrap-ui/pull/207
For the latest version of the Bootstrap 4 plugin:
see https://github.com/FriendsOfCake/bootstrap-ui/tree/develop
Although it a dev version, it works fine for me.

Laravel blade template (Undefined class Meta) error

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

How to use Facebook PHP SDK with Yii 2?

I am trying to implement Facebook SDK for PHP with Yii 2. I am totally new to this and doing this in my config file:
'facebook' => [
'class' => 'frontend/components/Facebook/Facebook'
]
The 'Facebook' folder is placed inside components folder, inside frontend. I am trying to include it like this:
use Facebook/Facebook;
But it doesn't work. How can I do it right? Any help regarding this?
In Facebook class you should have namespace:
namespace frontend\components\facebook;
And then use this like:
use frontend\components\Facebook\Facebook;
If u defined it in components in config just use it like:
\Yii::$app->facebook
it you are doing social login yii2-eauth is best for every type of social login....
check git code here
Checkout demo here

ZF2 'unable to render template' when shifting module names in the array in app config

Good day.
I've just started learning ZF2, replicated the Album example step-by-step, and then decided to make it a bit more interesting by adding user registration, and then make the two work together in some way, so i added a new 'Auth' module.
So, when i only had one module in the module list (aside from the Application module) in application.config.php, it was all fine, but when i added the Auth module to the list like so:
'modules' => array('Application', 'Album','Auth',)
i got the following error when trying to access any views from the album module which was working absolutely fine prior to this change:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "album/album/index"; resolver could not resolve to a file
But when i changed the order in which the modules are presented in this array like so:
'modules' => array('Application', 'Auth','Album',)
not a single view (and it has only one) from the Auth module could be rendered, while the Album module was fine.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "auth/user/index"; resolver could not resolve to a file
Both of these views exist at these locations, but the renderer doesn't see them for some reason.
You can see the project's contents here.
Thank you for any tips in advance.
Looks like you copy pasted the the view manager config for Auth module.config.php.
This should be auth rather than album for your templates to work correctly.
'view_manager' => array(
'template_path_stack' => array(
'auth' => __DIR__ . '/../view',
),
),

Loading core scripts such as jQuery in Yii 2

I've been having a hard time trying to figure out how to load jQuery or other CORE scripts in Yii 2.
In Yii 1 it seemed this was the way:
<?php Yii::app()->clientScript->registerCoreScript("jquery"); ?>
In Yii 2, $app is a property of Yii, not a method, so the above naturally doesn't work, but changing it to:
<?php Yii::$app->clientScript->registerCoreScript("jquery"); ?>
produces this error:
Getting unknown property: yii\web\Application::clientScript
I couldn't find any documentation for Yii 2 about loading core scripts, so I tried the below:
<?php $this->registerJsFile(Yii::$app->request->baseUrl . '/js/jquery.min.js', array('position' => $this::POS_HEAD), 'jquery'); ?>
Whilst this loads jQuery in the head, a second version of jQuery is also loaded by Yii when needed and hence causes conflict errors.
Additionally, I don't want to use Yii's implementation of jQuery, I would prefer to maintain my own and hence that is why I am doing this.
How can I load jQuery and other core files without Yii loading duplicate copies of them when it needs them?
In order to disable Yii2's default assets you can refer to this question:
Yii2 disable Bootstrap Js, JQuery and CSS
Anyway, Yii2's asset management way is different from Yii 1.x.x. First you need to create an AssetBundle. As official guide example, create an asset bundle like below in ``:
namespace app\assets\YourAssetBundleName;
use yii\web\AssetBundle;
class YourAssetBundleName extends AssetBundle
{
public $basePath = '#webroot';
public $baseUrl = '#web';
public $css = [
'path/file.css',//or files
];
public $js=[
'path/file.js' //or files
];
//if this asset depends on other assets you may populate below array
public $depends = [
];
}
Then, to publish them on your views:
use app\assets\YourAssetBundleName;
YourAssetBundleName::register($this);
Which $this refers to current view object.
On the other hand, if you need to only register JS files into a view, you may use:
$this->registerJsFile('path/to/file.js');
yii\web\View::registerJsFile()
And if you need to only register CSS files into a view, you may use:
$this->registerCssFile('path/to/file.css');
yii\web\View::registerCssFile()
You can remove the core jQuery from loading like so:
config/web.php
'assetManager' => [
'bundles' => [
// you can override AssetBundle configs here
'yii\web\JqueryAsset' => [
'sourcePath' => null,
'js' => []
],
],
],

Categories