Failed to instantiate component or class "yii\bootstrap\BootstrapAsset" - yii2

I'm trying to make a form in yii2 accept big numbers like currency . I want the number to be seperated for example 10000000 seems like that 10.000.000 . I search and find that there is something called auto numiric I use it but I got this error
<?=$form->field($model, 'num')->widget(\extead\autonumeric\AutoNumeric::classname(), [
'pluginOptions' => [
'aSep' => ' ',
'mDec' => 0
]
]);?>
Not instantiable – yii\di\NotInstantiableException
Failed to instantiate component or class "yii\bootstrap\BootstrapAsset".
↵
Caused by: ReflectionException
Class yii\bootstrap\BootstrapAsset does not exist
in E:\xam\htdocs\basic\vendor\yiisoft\yii2\di\Container.php at line 507
if I diddn't use auto numiric
<?= $form->field($model,'num')?>
the error disappear
can any body help ????

It looks like extead/yii2-autonumeric requires yiisoft\yii-bootstrap extension which uses Bootstrap 3.
You can install missing extension through composer:
composer require --prefer-dist yiisoft/yii2-bootstrap
Or you can add it in your composer.json and then run composer update to install it.
Edit: actually, I've missed that yii2-bootstrap4 and yii2-bootstrap5 extensions uses different namespaces so for yii2-autonumeric extension to work you have to install bootstrap 3 extension.
If you can't use bootstrap 3, you should probably switch to another extension for formating values in inputs. For example kartik-v/yii2-number allows you to set what version of bootstrap should be used.

Related

Replace Yii2 core class

I am looking to override the default Model \yii\base\Model class with an extended version I have created. For arguments sake lets say I have it in backend\components\Model
I have tried putting both of these in the bootstrap config file but nothing changes - it continues to use the old class
Yii::$container->set('yii\base\Model', 'backend\components\Model');
Yii::$classMap['yii\base\Model'] = 'backend\components\Model';
and within the backend\Model file:
<?php
namespace backend\components;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\UserException;
use yii\helpers\ArrayHelper;
class Model extends \yii\base\Model
{
/**
* Adds a new error to the specified attribute.
* #param string $attribute attribute name
* #param string $key attribute index
* #param string $error new error message
*/
public function addCustomError($attribute, $key, $error = '')
{
$this->_errors[$attribute][$key][] = $error;
}
}
I have also tried adding it to the config file using:
'container' => [
'definitions' => [
'yii\base\model'=>
['class'=>'backend\components\model']
]
],
No matter what I do - when I create a new ActiveRecord, it still holds the same yii\base\model class.
I have spent the better half of the afternoon trying to solve this and have gone through both the Yii documentation as well as the questions already on StackOverflow. There seems to be a recurring theme of the Container function not working and people transitioning to the ClassMap function - yet neither seem to work.
Thanks for the help.
Overriding by container works if you use container to instantiate overridden class (like Yii::$container->get('yii\base\Model');). If you have class MyModel extends \yii\base\Model you're NOT using container, yii\base\Model will be used as base class no matter what, because this is how PHP works and framework has no way to change that. If you want to do this you have at least 4 options:
Preferable: just use class MyModel extends \backend\components\Model for your models and avoid hacky class replacing.
Desperate 1: copy vendor/yiisoft/yii2/base/Model.php to overridden/Model.php, alter its source code, and override autoloading config to use overridden/Model.php for yii\base\Model - add:
Yii::$classMap['yii\base\Model'] = __DIR__ . '/../overridden/Model.php';
or
require __DIR__ . '/../overridden/Model.php';
after
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php
You need to sync all changes from vendor/yiisoft/yii2/base/Model.php to your copy after framework update. In general this should be last resort, since it is really easy to forget about it and get completely unexpected behavior.
Desperate 2: patch vendor/yiisoft/yii2/base/Model.php directly using cweagans/composer-patches. This is easier to maintain than second option, but it still may be surprising after some time. Also, at some point your patch may get conflicts after framework update and someone that knows what is happening will need to take a look at this.
Desperate 3: fork yiisoft/yii2 and do whatever you want - it is your framework now. It may be quite useful for large and active project, but in other case you may end up with completely outdated framework, because nobody cares to fetch changes from upstream.

Avoid duplicate interface definition for class MagicalRecord.h

When I go to call:
enableShorthandMethods from the file "MagicalRecord+ShorthandMethods.h"using :
#import <MagicalRecord/MagicalRecord+ShorthandMethods.h>
there is an error:
Duplicate interace definition for class MagicalRecord.
I'm getting:
duplicate interface definition for class MagicalRecord.h
MR has been added with cocoaPods.
pod 'MagicalRecord'
pod 'MagicalRecord/ShorthandMethodAliases'
I tried to follow the following guide:
https://github.com/magicalpanda/MagicalRecord/blob/master/Docs/Installing-MagicalRecord.md
To no avail.
After running
'find . -iname "MagicalRecord.h"'
There was a remaining copy of the file from the previous non-pods installation. The got rid of this very message.
Turns out it was something to do with an XCode5 project using ARC. Setting a flag for no ARC fixed the problem. An object associated with the MR was involved.

Chef - override node attribute

We have recipe which use node attribute:
python_pip 'request_proxy' do
virtualenv '/opt/proxy/.env'
version node.default['request-proxy']['version']
Chef::Log.info('Auth request proxy #{version}')
action :install
end
Attribute is set on node level and everything is OK, but for test purposes i want to override it in my local (kitchen/vagrant) node. As first step i add attribute to my .kitchen.yml:
suites:
- name: default
run_list:
- recipe[proxy_install]
attributes: {request-proxy: {'version': '1.0.8'}}
Unfortunately node still use the "default" version. Everything works fine, without any error and completly ignores my attributes.
Later i tried add this to parameter file (chef-client -j params.json) on production node, result was the same.
What I missed? What am I doing wrong?
P.S. Chef::Log.info('Auth request proxy #{version}') is also completely ignored ??
Can you try using YAML? kitchen.yml is not a JSON file, so I'm not sure that your JSON embedded inside it would work.
attributes:
request-proxy:
version: '1.0.8'
Also, you probably should not be using node.default, unless you want to pick up the default value only (and never any overrides). If you want to use the attribute precedence (default, normal, override, force) in Chef, you should be doing:
node['request-proxy']['version']
Finally, you also have a single-quoted string with a variable. This will never work like you expect in Ruby (are you running rubocop? It would have caught this). Try it with double quotes, and remove it from the middle of your resource:
Chef::Log.info("Auth request proxy #{version}")

How can I avoid duplicated symbol errors when I use static libraries with Cocoapods?

I've got a executable target called Foobar, a static library holding some common code called FoobarCommon, and a test target specifically for the common code called FoobarCommonSpecs.
Unsurprisingly, I have made both Foobar and FoobarCommonSpecs depend on the FoobarCommon library.
The Podfile looks something like the below:
target 'FoobarCommon' do
pod 'ReactiveCocoa'
...
end
target 'Foobar' do # links against to FoobarCommon in Xcode
...
end
target 'FoobarCommonSpecs' do # links against to FoobarCommon in Xcode
pod 'LLReactiveMatchers', :git => 'https://github.com/lawrencelomax/LLReactiveMatchers.git'
end
LLReactiveMatchers is a Pod that depends on ReactiveCocoa.
Note that in this situation, ReactiveCocoa is prsent in both FoobarCommon and also in FoobarCommonSpecs
The Problem
Whenever I run FoobarCommonSpecs, I get many duplicate symbol errors for ReactiveCocoa.
I want to say to Cocoapods that it should just IGNORE LLReactiveMatcher's dependency on ReactiveCocoa. It should just let Xcode do its job and it should link with the copy of ReactiveCocoa found in FoobarCommon. How do I do that?
Does the link_with directive have anything to do with anything?

Entity Framework 4.1 strongly-typed Include doesn't provide IntelliSense?

I've added: using System.Data.Entity;
and now I don't get an error on compilation of this:
var k = db.Countries.Include(e => e.Cities);
but I still have to manually go into the database schema and check the current table correct name and copy-paste/type it in the code.
There is no IntelliSense after I use the period:
var k = db.Countries.Include(e => e.
So, the purpose of all this is questionable since it doesn't really help at all. Typing manually the table name (entity set name) in quotation marks isn't any different than typing it in a lambda expression - except for it is shorter as a string.
Hints?
Seems like your problem will be resolved when you add
using System.Data.Entity;
to top of your page
Seems like the problem is in ReSharper 6 IntelliSense. After turning off ReSharper 6 IntelliSense, the original VS2010 IntelliSense works fine. The bug has been reported.