Asset management in yii2 - yii

I have the code like this:
class BootBoxAsset extends AssetBundle
{
public $sourcePath = '#vendor/almasaeed2010/adminlte';
public $css = [
];
public $js = [
'https://cdn.bootcss.com/bootbox.js/4.4.0/bootbox.js'
];
public $depends = [
'plugins\jQuery\jquery-2.2.3.min.js',
'bootstrap\js\bootstrap.min.js',
];
public $jsOptions = ['position' => \yii\web\View::POS_HEAD];
}
As the code shows above, I want to use bootbox.js which requires the related jquery and bootstrap dependency that located in my $sourcePath variable combined with the directories in $depends array,
when I register this asset in my view, there's an error tells me that the Class plugins\jQuery\jquery-2.2.3.min.js does not exist, so what should I do to register the dependency not start from yii directory?
thanks!

this mean that you have wrong path for
your dependency
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
then check for proper path
but for these assets you could use
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];

Related

Adding lit-element and lit-html to a global variabel

I have several lit-elements on my page, but I can't compile them all together so I would like to "share" the lit stuff through a global variable. Might be a bit unconventional, but right now it will save me a lot of bytes.
I'm using rollup to do the packaging.
I think I'm pretty close to achieve what I want, but there is something that I'm missing...
This is my component..
#customElement('tab-strip')
export class TabStrip extends LitElement {
Resulting in
var tabstrip = (function (exports, litElement, repeat, classMap) {
//SOME OTHER STUFF
exports.TabStrip = class TabStrip extends litElement.LitElement {...
.
.
.
${repeat.repeat(this._tabs, e => litElement.html
}({}, Globals, Globals.repeat, Globals.classMap))
I have create a Globals.ts file that looks like this..
import { customElement, html, LitElement, property } from "lit-element";
import { Template, TemplateResult } from "lit-html";
import { classMap } from "lit-html/directives/class-map";
import { repeat } from "lit-html/directives/repeat";
class Globals {
public html = html;
public LitElement = LitElement;
public customElement = customElement;
public property = property;
public repeat = repeat;
public classMap = classMap;
public Template = Template;
public TemplateResult = TemplateResult;
}
window["Globals"] = new Globals();
And at last my rollup.config
input: inputDir + name + ".ts",
output: {
file: outputDir + name + ".js",
name: name,
format: format,
sourcemap: true,
globals: {
"lit-element": "Globals",
'customElement': 'Globals.customElement',
'lit-html': "Globals.LitHtml",
'html': "Globals.html",
'property': "Globals.property",
'lit-html/directives/repeat': "Globals.repeat",
'lit-html/directives/class-map': 'Globals.classMap',
'Template': 'Globals.Template',
'TemplateResult': 'Globals.TemplateResult'
}
},
plugins: [
typescript({
experimentalDecorators: true
}),
resolve(),
// terser({"ecma":"2019"}),
],
external: ['lit-element', 'lit-html', "lit-html/directives/repeat", "lit-html/directives/class-map"]
Gut feeling is that I have misunderstood something in the external stuff of rollup..
AS you can see in the generated file it says litElement.LitElement instead of just litElement
Any help??
Does it work for you? This seems correct just taking it at face value.
Looking at what your Globals is, it's an object with the properties LitElement, property, html, and so on.
If we look at your tabstrip function, the second argument is litElement, which matches the Globals Object being passed in.
So class TabStrip extends litElement.LitElement
makes sense, since the litElement is referencing your Globals object, and that has the LitElement property.

How to manually add custom data to behaviors

I've use BlameableBehavior but in some of my controller I want to manually set the user created value but it can't work.
public function behaviors()
{
return [
BlameableBehavior::className(),
];
}
this not work.
$model->createdBy = 1;
$model->save();
it try to use the BlameableBehavior.
how can I manually add it.
Thanks.
Try to use named behavior and detach it before saving model:
public function behaviors()
{
return [
'blameable' => BlameableBehavior::className(),
];
}
And then:
$model->detachBehavior('blameable');
$model->createdBy = 1;
$model->save();

Is it possible to pass though a template option to a module (as a variable parameter)

I have a page that uses a module for defining form content. It is rather generically usable but needs different resulting pages after form actions have been triggered (button click, etc.).
class CreateOrganisationPage extends Page {
static url = "#contact/organisation/create"
static at = {
form.displayed
}
static content = {
form(wait: true) {
module BusinessEntityFormModule, businessEntityName: 'organisation'
}
}
}
The module implementing the form content contains a UI control saveCommand that requires that a page ViewBusinessEntityPage is navigated to after submitting. In order to keep that module more reusable across different tests I wanted to provide that page as a parameter.
What is the best approach to do so?
class BusinessEntityFormModule extends Module {
String businessEntityName = "entity"
String idPrefix = "edit"
static content = {
self {
def id = "$idPrefix-" + StringUtils.capitalize(businessEntityName)
$("form", id: id)
}
saveCommand(to: ViewBusinessEntityPage) {
$('[data-command="save"]')
}
}
}
Simply define a property for the destination page in your module and use it in the content definition:
class BusinessEntityFormModule extends Module {
Class postSavePage
static content = {
saveCommand(to: postSavePage) {
$('[data-command="save"]')
}
}
}
And then set it when defining the module as part of the page:
class CreateOrganisationPage extends Page {
static content = {
form(wait: true) {
module BusinessEntityFormModule, businessEntityName: 'organisation', postSavePage: ViewBusinessEntityPage
}
}
}

Omnipay add new gateway

Based on this answer: Omnipay how to add new gateway
I try to add a new gateway for omnipay.
My folder structure:
lib/omnipay/newgw/
lib/omnipay/newgw/src/
lib/omnipay/newgw/src/Gateway.php
lib/omnipay/newgw/composer.json
vendor/omnipay/...
...
composer.json
In main composer.json I have:
{
"require": {
...
"omnipay/omnipay": "dev-master"
...
},
"autoload": {
"psr-0": {
"": "lib/",
"Omnipay\\NewGw\\" : "lib/omnipay"
}
}
}
Do composer update.
In gateway.php:
namespace Omnipay\NewGw;
use Omnipay\Common;
use Omnipay\Common\AbstractGateway;
use Omnipay\NewGw\Message\PurchaseRequest;
use Omnipay\NewGw\Message\RefundRequest;
class Gateway extends AbstractGateway{
}
And when I try to run it:
use Omnipay\Omnipay;
class TestController extends ControllerBase{
public function index(){
$gateway = Omnipay::create('NewGw');
}
}
It say's that class not found:
Omnipay\Common\Exception\RuntimeException: Class '\Omnipay\NewGw\Gateway' not found
I don't figure it out why the class isn't loaded.
Please help, Thanks.
I just created a new Gateway myself, I believe your problem is the fact that you are doing something like
"psr-0": {
"": "lib/",
"Omnipay\\NewGw\\" : "lib/omnipay"
}
And it should be
"Omnipay\\NewGw\\" : "lib/omnipay/src"
You are setting the namespace of the new library to lib/omnypay but it should actually be lib/omnypay/src

Can not find model class in module application

I'm new in Zend, i had defined in my application.ini some lines to use multiple db.
resources.multidb.sitgm.adapter = "pdo_pgsql"
resources.multidb.sitgm.host = "localhost"
resources.multidb.sitgm.username = "postgres"
resources.multidb.sitgm.password = "pass"
resources.multidb.sitgm.dbname = "mydb"
resources.multidb.sitgm.isDefaultTableAdapter = true
In my APPLICATION Bootstrap i have a function:
public function _initDbRegistry()
{
$this->_application->bootstrap('multidb');
$multidb = $this->_application->getPluginResource('multidb');
Zend_Registry::set('db_sitgm', $multidb->getDb('sitgm'));
}
But when i had migrated to module squema, i have a default module, i added another DEFAULT Bootstrap.
class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
public function _initDbRegistry()
{
//Do i must add something here to access application DB conf like app bootstrap????
}
}
In this point How i can call the application config beacuse i am getting an error in my default model class which can not find it.
class Default_Model_Base {
protected $db;
public $sql="";
function __construct() {
$this->db = Zend_Registry::get("db_sitgm"); //HERE I GOT THE ERROR
$this->db->setFetchMode(Zend_Db::FETCH_OBJ);
}
}
Thanks in advance
You don't have to define the _initDbRegistry in your module bootstrap as well. You can leave it in your application Bootstrap.php