Dart Object -> JSON String failing to convert to JSON - json

I'm trying to serialize an object to JSON and then back from JSON to object again.
This is the code snippet that is supposed to give me proper JSON:
LoginRequest req = new LoginRequest();
req.username = username;
req.password = password;
req.created = 123456;
req.test = "KOTS";
print(req.toString());
What I'm seeing in the console is this:
{} (:1)
In pubspec.yaml I'm importing json_object as a dependency:
environment:
sdk: '>=1.0.0 <2.0.0'
dependencies:
...
json_object: any
I have a base message class that extends JsonObject:
import 'package:json_object/json_object.dart';
class Message extends JsonObject {
int created = new DateTime.now().millisecondsSinceEpoch;
}
and then I have a LoginRequest that extends Message:
import 'Message.dart';
class LoginRequest extends Message {
String _username;
String _password;
String test;
String get username => _username;
set username(String username) {
_username = username.trim();
}
String get password => _password;
set password(String password) {
_password = password.trim();
}
}
I was thinking that only the base class will be converting to Json, so I wrote another test case:
Message msg = new Message();
msg.created = 123456;
print(msg.toString());
This is also printing:
{} (:1)
Calling objectToJson does the same:
objectToJson(msg).then((jsonStr) => print(jsonStr));
objectToJson(req).then((jsonStr) => print(jsonStr));
Outputs:
{}
{}
Removing extends JsonObject causes the above code to spew a stack trace:
Exception: Uncaught Error: Converting object to an encodable object failed.
Stack Trace:
#0 _JsonStringifier.writeObject (dart:convert/json.dart:660)
#1 _JsonStringStringifier.printOn (dart:convert/json.dart:831)
#2 _JsonStringStringifier.stringify (dart:convert/json.dart:813)
#3 JsonEncoder.convert (dart:convert/json.dart:243)
#4 JsonCodec.encode (dart:convert/json.dart:141)
#5 login (package:falm/login-dialog.dart:47:22)
#6 Function.apply (dart:core-patch/function_patch.dart:28)
#7 GeneratedObjectAccessorService.invoke (package:smoke/static.dart:149:28)
#8 invoke (package:smoke/smoke.dart:43:41)
#9 HtmlElement&Polymer.dispatchMethod (package:polymer/src/instance.dart:1054:19)
#10 BindingDelegate&PolymerEventBindings.getEventHandler.<anonymous closure> (package:polymer/src/events.dart:82:32)
#11 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#12 _RootZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1122)
#13 BindingDelegate&PolymerEventBindings.prepareEventBinding.<anonymous closure>.<anonymous closure> (package:polymer/src/events.dart:101:67)
Clicked Login (:1)
Exception: Uncaught Error: Class '_LocalClassMirror' has no instance getter 'getters'.
NoSuchMethodError: method not found: 'getters'
Receiver: Instance of '_LocalClassMirror'
Arguments: []
Stack Trace:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1 _serializeObject (package:json_object/src/mirror_based_serializer.dart:127:16)
#2 objectToSerializable (package:json_object/src/mirror_based_serializer.dart:53:21)
#3 objectToJson (package:json_object/src/mirror_based_serializer.dart:22:23)
#4 login (package:falm/login-dialog.dart:43:17)
#5 Function.apply (dart:core-patch/function_patch.dart:28)
#6 GeneratedObjectAccessorService.invoke (package:smoke/static.dart:149:28)
#7 invoke (package:smoke/smoke.dart:43:41)
#8 HtmlElement&Polymer.dispatchMethod (package:polymer/src/instance.dart:1054:19)
#9 BindingDelegate&PolymerEventBindings.getEventHandler.<anonymous closure> (package:polymer/src/events.dart:82:32)
#10 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#11 _RootZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1122)
#12 BindingDelegate&PolymerEventBindings.prepareEventBinding.<anonymous closure>.<anonymous closure> (package:polymer/src/events.dart:101:67)
Clicked Login (:1)
Exception: Uncaught Error: Converting object to an encodable object failed.
Stack Trace:
#0 _JsonStringifier.writeObject (dart:convert/json.dart:660)
#1 _JsonStringStringifier.printOn (dart:convert/json.dart:831)
#2 _JsonStringStringifier.stringify (dart:convert/json.dart:813)
#3 JsonEncoder.convert (dart:convert/json.dart:243)
#4 JsonCodec.encode (dart:convert/json.dart:141)
#5 login (package:falm/login-dialog.dart:47:22)
#6 Function.apply (dart:core-patch/function_patch.dart:28)
#7 GeneratedObjectAccessorService.invoke (package:smoke/static.dart:149:28)
#8 invoke (package:smoke/smoke.dart:43:41)
#9 HtmlElement&Polymer.dispatchMethod (package:polymer/src/instance.dart:1054:19)
#10 BindingDelegate&PolymerEventBindings.getEventHandler.<anonymous closure> (package:polymer/src/events.dart:82:32)
#11 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#12 _RootZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1122)
#13 BindingDelegate&PolymerEventBindings.prepareEventBinding.<anonymous closure>.<anonymous closure> (package:polymer/src/events.dart:101:67)
Clicked Login (:1)
Exception: Uncaught Error: Class '_LocalClassMirror' has no instance getter 'getters'.
NoSuchMethodError: method not found: 'getters'
Receiver: Instance of '_LocalClassMirror'
Arguments: []
Stack Trace:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1 _serializeObject (package:json_object/src/mirror_based_serializer.dart:127:16)
#2 objectToSerializable (package:json_object/src/mirror_based_serializer.dart:53:21)
#3 objectToJson (package:json_object/src/mirror_based_serializer.dart:22:23)
#4 login (package:falm/login-dialog.dart:44:17)
#5 Function.apply (dart:core-patch/function_patch.dart:28)
#6 GeneratedObjectAccessorService.invoke (package:smoke/static.dart:149:28)
#7 invoke (package:smoke/smoke.dart:43:41)
#8 HtmlElement&Polymer.dispatchMethod (package:polymer/src/instance.dart:1054:19)
#9 BindingDelegate&PolymerEventBindings.getEventHandler.<anonymous closure> (package:polymer/src/events.dart:82:32)
#10 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#11 _RootZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1122)
#12 BindingDelegate&PolymerEventBindings.prepareEventBinding.<anonymous closure>.<anonymous closure> (package:polymer/src/events.dart:101:67)
Importing dart:convert and using JSON.encode does the same:
import 'dart:convert' show JSON;
...
print(JSON.encode(msg));
print(JSON.encode(req));
Outputs:
{}
{}
If I remove the extends JsonObject, then it throws a stack trace:
Exception: Uncaught Error: Converting object to an encodable object failed.
Stack Trace:
#0 _JsonStringifier.writeObject (dart:convert/json.dart:660)
#1 _JsonStringStringifier.printOn (dart:convert/json.dart:831)
#2 _JsonStringStringifier.stringify (dart:convert/json.dart:813)
#3 JsonEncoder.convert (dart:convert/json.dart:243)
#4 JsonCodec.encode (dart:convert/json.dart:141)
#5 login (package:falm/login-dialog.dart:47:22)
#6 Function.apply (dart:core-patch/function_patch.dart:28)
#7 GeneratedObjectAccessorService.invoke (package:smoke/static.dart:149:28)
#8 invoke (package:smoke/smoke.dart:43:41)
#9 HtmlElement&Polymer.dispatchMethod (package:polymer/src/instance.dart:1054:19)
#10 BindingDelegate&PolymerEventBindings.getEventHandler.<anonymous closure> (package:polymer/src/events.dart:82:32)
#11 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#12 _RootZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1122)
#13 BindingDelegate&PolymerEventBindings.prepareEventBinding.<anonymous closure>.<anonymous closure> (package:polymer/src/events.dart:101:67)
Clicked Login (:1)
Exception: Uncaught Error: Class '_LocalClassMirror' has no instance getter 'getters'.
NoSuchMethodError: method not found: 'getters'
Receiver: Instance of '_LocalClassMirror'
Arguments: []
Stack Trace:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1 _serializeObject (package:json_object/src/mirror_based_serializer.dart:127:16)
#2 objectToSerializable (package:json_object/src/mirror_based_serializer.dart:53:21)
#3 objectToJson (package:json_object/src/mirror_based_serializer.dart:22:23)
#4 login (package:falm/login-dialog.dart:43:17)
#5 Function.apply (dart:core-patch/function_patch.dart:28)
#6 GeneratedObjectAccessorService.invoke (package:smoke/static.dart:149:28)
#7 invoke (package:smoke/smoke.dart:43:41)
#8 HtmlElement&Polymer.dispatchMethod (package:polymer/src/instance.dart:1054:19)
#9 BindingDelegate&PolymerEventBindings.getEventHandler.<anonymous closure> (package:polymer/src/events.dart:82:32)
#10 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#11 _RootZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1122)
#12 BindingDelegate&PolymerEventBindings.prepareEventBinding.<anonymous closure>.<anonymous closure> (package:polymer/src/events.dart:101:67)
Clicked Login (:1)
Exception: Uncaught Error: Converting object to an encodable object failed.
Stack Trace:
#0 _JsonStringifier.writeObject (dart:convert/json.dart:660)
#1 _JsonStringStringifier.printOn (dart:convert/json.dart:831)
#2 _JsonStringStringifier.stringify (dart:convert/json.dart:813)
#3 JsonEncoder.convert (dart:convert/json.dart:243)
#4 JsonCodec.encode (dart:convert/json.dart:141)
#5 login (package:falm/login-dialog.dart:47:22)
#6 Function.apply (dart:core-patch/function_patch.dart:28)
#7 GeneratedObjectAccessorService.invoke (package:smoke/static.dart:149:28)
#8 invoke (package:smoke/smoke.dart:43:41)
#9 HtmlElement&Polymer.dispatchMethod (package:polymer/src/instance.dart:1054:19)
#10 BindingDelegate&PolymerEventBindings.getEventHandler.<anonymous closure> (package:polymer/src/events.dart:82:32)
#11 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#12 _RootZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1122)
#13 BindingDelegate&PolymerEventBindings.prepareEventBinding.<anonymous closure>.<anonymous closure> (package:polymer/src/events.dart:101:67)
Is JsonObject still the right way to go for serializing objects to JSON and deserializing JSON to objects? (I see in the code copyright 2013 which is ancient by now). If so, am I missing something in my classes?
In the dart cookbook there are examples where every class has its own toJson method and where all the values are manually copied into a map, this is cumbersome, if my whole app is JSON-driven, then I'll be spending most of my time writing boilerplate toJson / fromJson methods - this is exactly what I'm trying to get away from, hence the reason for choosing dart.
Furthermore I see examples on StackOverflow where mirrors are being used followed by comments that mirrors aren't fully supported in dart2js - since this is a browser based application, it is crucial that it can compile to javascript.
Update:
Based on Robert's answer, it seems doing the boilerplate is unavoidable:
Message.dart
import 'dart:convert' show JSON;
class Message {
int created = new DateTime.now().millisecondsSinceEpoch;
Map toJson() {
Map map = new Map();
map["created"] = this.created;
return map;
}
String toString(){
return JSON.encode(this);
}
}
LoginRequest.dart
import 'Message.dart';
class LoginRequest extends Message {
String _username;
String _password;
String test;
String get username => _username;
set username(String username) {
_username = username.trim();
}
String get password => _password;
set password(String password) {
_password = password.trim();
}
Map toJson() {
Map map = super.toJson();
map["username"] = this.username;
map["password"] = this.password;
return map;
}
}
Test code:
LoginRequest req = new LoginRequest();
req.username = username;
req.password = password;
req.created = 123456;
req.test = "KOTS";
print(req);
// outputs: {"created":123456,"username":"asdfasdf","password":"adfasdf"} (:1)
Message msg = new Message();
msg.created = 123456;
print(msg);
// outputs: {"created":123456} (:1)
toString I only need to implement once on the Message class, toJson will need to go on every class.

I think your problem is that you use print(req.toString());. Have you tried to do this:
objectToJson(req).then((jsonStr) => print(jsonStr)); Maybe this gives you a json string.
I personally feel like you actually SHOULD provide a toJson/toObject method because you have full control over what is serialized and how it is serialized (e.g. exclude private fields, null values, ...).
// EDIT
Because you use extends JsonObject toString() returns an empty map.
// EDIT
https://code.google.com/p/dart/issues/detail?id=6490 doesn't look like it is supported well. But then you can't use the json_object package anyway.
Exception: Uncaught Error: Class '_LocalClassMirror' has no instance getter 'getters'. This should be because the package requires experimental mirror features.
Using JSON.encode you cannot put an object into there. See https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:convert.JsonCodec#id_encode :
Either you specify the second parameter or implement .toJson().

Related

MediaWiki TemplateParser.php internal error

I have a local wiki (MediaWiki 1.38.4 ; Apache with xampp) that worked perfectly for a few weeks, but today started giving me errors with the TemplateParser.php and now is completely unnaccesible and shows the following error details:
MediaWiki internal error.
Original exception: [3d60e113338e8a53946d26be] /fangirlbook/index.php/P%C3%A1gina_principal TypeError: Cannot access offset of type string on string
Backtrace:
from C:\xampp\htdocs\fangirlbook\includes\TemplateParser.php(134)
#0 C:\xampp\htdocs\fangirlbook\includes\TemplateParser.php(289): TemplateParser->getTemplate(string)
#1 C:\xampp\htdocs\fangirlbook\includes\skins\SkinMustache.php(65): TemplateParser->processTemplate(string, array)
#2 C:\xampp\htdocs\fangirlbook\skins\Vector\includes\SkinVector.php(455): SkinMustache->generateHTML()
#3 C:\xampp\htdocs\fangirlbook\includes\skins\SkinTemplate.php(150): Vector\SkinVector->generateHTML()
#4 C:\xampp\htdocs\fangirlbook\includes\OutputPage.php(2807): SkinTemplate->outputPage()
#5 C:\xampp\htdocs\fangirlbook\includes\MediaWiki.php(926): OutputPage->output(boolean)
#6 C:\xampp\htdocs\fangirlbook\includes\MediaWiki.php(939): MediaWiki::{closure}()
#7 C:\xampp\htdocs\fangirlbook\includes\MediaWiki.php(563): MediaWiki->main()
#8 C:\xampp\htdocs\fangirlbook\index.php(53): MediaWiki->run()
#9 C:\xampp\htdocs\fangirlbook\index.php(46): wfIndexMain()
#10 {main}
Exception caught inside exception handler: [3d60e113338e8a53946d26be] /fangirlbook/index.php/P%C3%A1gina_principal TypeError: Cannot access offset of type string on string
Backtrace:
from C:\xampp\htdocs\fangirlbook\includes\TemplateParser.php(134)
#0 C:\xampp\htdocs\fangirlbook\includes\TemplateParser.php(289): TemplateParser->getTemplate(string)
#1 C:\xampp\htdocs\fangirlbook\includes\skins\SkinMustache.php(65): TemplateParser->processTemplate(string, array)
#2 C:\xampp\htdocs\fangirlbook\skins\Vector\includes\SkinVector.php(455): SkinMustache->generateHTML()
#3 C:\xampp\htdocs\fangirlbook\includes\skins\SkinTemplate.php(150): Vector\SkinVector->generateHTML()
#4 C:\xampp\htdocs\fangirlbook\includes\OutputPage.php(2807): SkinTemplate->outputPage()
#5 C:\xampp\htdocs\fangirlbook\includes\exception\MWExceptionRenderer.php(157): OutputPage->output()
#6 C:\xampp\htdocs\fangirlbook\includes\exception\MWExceptionRenderer.php(76): MWExceptionRenderer::reportHTML(TypeError)
#7 C:\xampp\htdocs\fangirlbook\includes\exception\MWExceptionHandler.php(107): MWExceptionRenderer::output(TypeError, integer)
#8 C:\xampp\htdocs\fangirlbook\includes\exception\MWExceptionHandler.php(202): MWExceptionHandler::report(TypeError)
#9 C:\xampp\htdocs\fangirlbook\includes\MediaWiki.php(585): MWExceptionHandler::handleException(TypeError, string)
#10 C:\xampp\htdocs\fangirlbook\index.php(53): MediaWiki->run()
#11 C:\xampp\htdocs\fangirlbook\index.php(46): wfIndexMain()
#12 {main}
I have already restarted the system, re-installed the wiki and copying the manual backup I had of the files and the database, and no solution. Any ideas?

Unhandled Exception: Invalid argument(s): Illegal length 0 on DART

when i try to make a simple select with mysql1 dart library, the app throws this exception:
E/flutter (11252): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Invalid argument(s): Illegal length 0
E/flutter (11252): #0 _NativeSocket.read (dart:io-patch/socket_patch.dart:819:7)
E/flutter (11252): #1 _RawSocket.read (dart:io-patch/socket_patch.dart:1614:22)
E/flutter (11252): #2 Buffer.readFromSocket (package:mysql1/src/buffer.dart:48:30)
E/flutter (11252): #3 BufferedSocket._readBuffer (package:mysql1/src/buffered_socket.dart:178:36)
E/flutter (11252): #4 BufferedSocket._onData (package:mysql1/src/buffered_socket.dart:93:9)
E/flutter (11252): #5 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (11252): #6 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (11252): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (11252): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (11252): #9 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter (11252): #10 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter (11252): #11 _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter (11252): #12 _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter (11252): #13 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1556:33)
E/flutter (11252): #14 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1052:14)
E/flutter (11252): #15 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (11252): #16 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter (11252):
this is the function that makes the query (I call that function in a FutureBuilder in flutter):
Future<bool> askPlacaTurno(String idServicio)async{
var conexion = await conectarse();
var res = await conexion.query("select placa from servicios where id = ?", [idServicio]);
bool usaPlaca = false;
for(var row in res){
usaPlaca = row[0] == 'on' ? true : false;
}
return usaPlaca;
}
EDITED
the connection and close connection functions, here is the problem, i've tried to make a connection without execute any query and throws the same exception:
Future conectarse() async{
final conexion = await MySqlConnection.connect(ConnectionSettings(
host: "192.168.0.18",
port: 3306,
user: "root",
password: '',
db: "gobernacion"
)
);
print("conectado a la base de datos");
return conexion;
}
Future desconectarse(MySqlConnection conexion) async{
await conexion.close();
}

yii2 - An Error occurred while handling another error:

I am trying to implement Metronic Theme to my Yii-2 advanced application's backend. I followed the instructions on GitHub step by step, however I keep getting a blank page with the following error on it. I am truly stuck.
Here is the error:
An Error occurred while handling another error:
Error: Call to undefined method yii\base\ErrorException::getSeverity() in
C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\ErrorHandler.php:287
Stack trace:
#0 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\ErrorHandler.php(107):
yii\base\ErrorHandler->logException(Object(yii\base\ErrorException))
#1 [internal function]: yii\base\ErrorHandler-
>handleException(Object(yii\base\ErrorException))
#2 {main}
Previous exception:
yii\base\ErrorException: Illegal string offset 'id' in
C:\xampp\htdocs\advanced\vendor\dlds\yii2-metronic\widgets\NavBar.php:59
Stack trace:
#0 C:\xampp\htdocs\advanced\vendor\dlds\yii2-
metronic\widgets\NavBar.php(59): yii\base\ErrorHandler->handleError(2,
'Illegal string ...', 'C:\\xampp\\htdocs...', 59, Array)
#1 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Object.php(107):
dlds\metronic\widgets\NavBar->init()
#2 [internal function]: yii\base\Object->__construct(Array)
#3 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\di\Container.php(381):
ReflectionClass->newInstanceArgs(Array)
#4 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\di\Container.php(156):
yii\di\Container->build('dlds\\metronic\\w...', Array, Array)
#5 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\BaseYii.php(348):
yii\di\Container->get('dlds\\metronic\\w...', Array, Array)
#6 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Widget.php(89):
yii\BaseYii::createObject(Array)
#7 C:\xampp\htdocs\advanced\backend\views\layouts\main.php(47):
yii\base\Widget::begin(Array)
#8 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\View.php(330):
require('C:\\xampp\\htdocs...')
#9 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\View.php(250):
yii\base\View->renderPhpFile('C:\\xampp\\htdocs...', Array)
#10 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Controller.php(396):
yii\base\View->renderFile('C:\\xampp\\htdocs...', Array,
Object(dektrium\user\controllers\SecurityController))
#11 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Controller.php(382):
yii\base\Controller->renderContent('\n\n <div clas...')
#12 C:\xampp\htdocs\advanced\vendor\dektrium\yii2-
user\controllers\SecurityController.php(166): yii\base\Controller-
>render('login', Array)
#13 [internal function]: dektrium\user\controllers\SecurityController-
>actionLogin()
#14 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\InlineAction.php(57):
call_user_func_array(Array, Array)
#15 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Controller.php(156):
yii\base\InlineAction->runWithParams(Array)
#16 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Module.php(523):
yii\base\Controller->runAction('login', Array)
#17 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\web\Application.php(102):
yii\base\Module->runAction('user/security/l...', Array)
#18 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Application.php(380):
yii\web\Application->handleRequest(Object(yii\web\Request))
#19 C:\xampp\htdocs\advanced\admin\index.php(15): yii\base\Application-
>run()
#20 {main}
You must add 'error' on actions
'rules' => [
[
'actions' => ['error', ...

Yii2 migration configException error

Suddenly any of the migration command is not working in my project and i don't know why. following is the errors in cmd.
C:\wamp64\www\project>yii migrate
Exception 'yii\base\InvalidConfigException' with message 'Failed to instantiate component or class "user".'
in C:\wamp64\www\project\vendor\yiisoft\yii2\di\Instance.php:139
Stack trace:
#0 C:\wamp64\www\project\vendor\yiisoft\yii2\filters\AccessControl.php(100): yii\di\Instance::ensure(Object(yii\di\Instance), 'yii\\web\\User')
#1 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Object.php(107): yii\filters\AccessControl->init()
#2 [internal function]: yii\base\Object->__construct(Array)
#3 C:\wamp64\www\project\vendor\yiisoft\yii2\di\Container.php(381): ReflectionClass->newInstanceArgs(Array)
#4 C:\wamp64\www\project\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('yii\\filters\\Acc...', Array, Array)
#5 C:\wamp64\www\project\vendor\yiisoft\yii2\BaseYii.php(348): yii\di\Container->get('yii\\filters\\Acc...', Array, Array)
#6 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Component.php(183): yii\BaseYii::createObject(Array)
#7 C:\wamp64\www\project\vendor\yiisoft\yii2\BaseYii.php(529): yii\base\Component->__set('beforeRequest', Array)
#8 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Object(yii\console\Application), Array)
#9 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Application.php(205): yii\base\Object->__construct(Array)
#10 C:\wamp64\www\project\vendor\yiisoft\yii2\console\Application.php(89): yii\base\Application->__construct(Array)
#11 C:\wamp64\www\project\yii(26): yii\console\Application->__construct(Array)
#12 {main}
Please help me to solve it.

How do you pass a function to a listener in Dart?

I want to pass a function to a class constructor. The function will ultimately be used in an onBlur listener. Something isn't working. (FWIW, this code is being executed in the "then" function a HttpRequest.getString())
This works:
query("${_element_id}_input").onBlur.listen((e) {
InputElement species_id = query("#id_species_id");
species_id.value = value;
print(species_id.value);
});
If I replace that with the following I get an error:
onBlur = ((e) {
InputElement species_id = query("#id_species_id");
species_id.value = value;
print(species_id.value);
});
if (onBlur != null) {
query("#{_element_id}_input").onBlur.listen(onBlur);
}
If I name the function I get the same error. The error is:
Uncaught Error: SyntaxError: Internal Dartium Exception
Stack Trace:
#0 Document.query (file:///mnt/data/b/build/slave/dartium-lucid32-full-trunk/build/src/out/Release/gen/blink/bindings/dart/dart/html/Document.dart:123:128)
#1 query (dart:html:448:49)
#2 AutoComplete.AutoComplete.<anonymous closure> (package:canopy/auto_complete.dart:69:14)
#3 _ThenFuture._zonedSendValue (dart:async/future_impl.dart:371:24)
#4 _TransformFuture._sendValue.<anonymous closure> (dart:async/future_impl.dart:348:48)
#5 _ZoneBase._runInZone (dart:async/zone.dart:74:15)
#6 _ZoneBase._runUnguarded (dart:async/zone.dart:102:22)
#7 _ZoneBase.executeCallback (dart:async/zone.dart:58:23)
#8 _TransformFuture._sendValue (dart:async/future_impl.dart:348:26)
#9 _FutureImpl._setValueUnchecked (dart:async/future_impl.dart:184:26)
#10 _FutureImpl._setValue (dart:async/future_impl.dart:174:23)
#11 _FutureImpl._setOrChainValue (dart:async/future_impl.dart:336:16)
#12 _ThenFuture._zonedSendValue (dart:async/future_impl.dart:377:21)
#13 _TransformFuture._sendValue.<anonymous closure> (dart:async/future_impl.dart:348:48)
#14 _ZoneBase._runInZone (dart:async/zone.dart:82:17)
#15 _ZoneBase._runUnguarded (dart:async/zone.dart:102:22)
#16 _ZoneBase.executeCallback (dart:async/zone.dart:58:23)
#17 _TransformFuture._sendValue (dart:async/future_impl.dart:348:26)
#18 _FutureImpl._setValueUnchecked (dart:async/future_impl.dart:184:26)
#19 _FutureImpl._asyncSetValue.<anonymous closure> (dart:async/future_impl.dart:218:25)
#20 _asyncRunCallback (dart:async/event_loop.dart:9:15)
#21 _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:8:13)
#22 _Timer._Timer.<anonymous closure> (file:///mnt/data/b/build/slave/dartium-lucid32-full-trunk/build/src/dart/tools/dom/src/native_DOMImplementation.dart:255:17)
Exception: SyntaxError: Internal Dartium Exception
_DefaultZone.handleUncaughtError.<anonymous closure> (dart:async/zone.dart:146:7)
_asyncRunCallback (dart:async/event_loop.dart:9:15)
_asyncRunCallback (dart:async/event_loop.dart:13:7)
_createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:8:13)
_Timer._Timer.<anonymous closure> (file:///mnt/data/b/build/slave/dartium-lucid32-full-trunk/build/src/dart/tools/dom/src/native_DOMImplementation.dart:255:17)
The culprit isn't the handler function, but your call to query to add the listener:
query("#{_element_id}_input").onBlur.listen(onBlur); - the '$' is missing to resolve {_element_id}