config helper bootstrap 4 in cakephp 3 - php

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.

Related

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

Namespace error when using gridview using custom theme in yii2

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

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

Yii Bootstrap does not work if not preloaded

I have been using Yii Bootstrap in an application for a while. Now, I have a section where the loaded CSS files are causing issues, and I don't want to load the bootstrap extension in that controller.
In my configuration file, I had bootstrap set to preload:
'preload' => array('log', 'bootstrap')
I have now removed bootstrap from the preload array, and it stops working saying the alias is incorrect:
Alias "bootstrap.widgets.BootNavbar" is invalid. Make sure it points to an existing directory or file.
The alias though has been defined in the components section of the configuration file and works fine when the bootstrap component is preloaded:
'bootstrap' => array(
'class' => 'ext.bootstrap.components.Bootstrap'
),
What can I do to make the bootstrap extension work without preloading it?
Just call this:
Yii::app()->getComponent("bootstrap");
'preload' => 'bootstrap' actually trigers this command. If you just call Yii::app()->bootstrap->init() as suggested by Blizz you will end up calling init() twice, which could be harmful.
I create the bootstrap extension in module init() method on this way. Preload is not needed.
if (!Yii::app()->hasComponent('bootstrap')) {
Yii::setPathOfAlias('bootstrap', realpath(dirname(__FILE__) . '/extensions/bootstrap'));
Yii::createComponent('bootstrap.components.Bootstrap')->init();
}
If you would like to manage Bootstrap component under Yii::app() (e.g. hasComponent method) you can change the last row:
Yii::app()->setComponent('bootstrap',Yii::createComponent('bootstrap.components.Bootstrap'));
This solution not need preload, or init(), but you have to set alias to Boostrap folder manually.
You can anytime import it:
Yii::import('ext.bootstrap.components.Bootstrap');

zend module autoloading

I have developed a small application and now I want to create and administrator module. In the future I would like to add different modules but for now i would like to treat this admin as a module and to access it like http://host/module/controller
I have read about zend_autoloader and wrote this in my Bootstrap.php
protected function _initAutoload() {
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Admin',
'basePath' => '/modules/admin'
));
I have created a default IndexController with the default index view file. When I try to access http://host/admin or http://host/admin/index i get an application error and of course the view is not loaded.
What am i doing wrong?
For everyone having the problem this guy sorts it out in the most newbish way possible.
http://www.zfforums.com/zend-framework-general-discussions-1/resources-developers-37/setup-multi-modules-zend-framework-v1-9-13-steps-3737.html

Categories