scope

PHP/CodeIgniter - Setting variables in __construct(), but they're not accessible from other functions

ⅰ亾dé卋堺 提交于 2020-01-12 19:05:10
问题 I'm happy a bit of a variable scoping problem. Maybe I just need more coffee... Here's my (simplified) code - this is in CodeIgniter 2: class Agent extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('agent_model'); // Get preliminary data that will be often-used in Agent functions $user = $this->my_auth_library->get_user(); $agent = $this->agent_model->get_agent($user->id); } public function index() { $this->template->set('info', $this->agent

filter $scope Error: Unknown provider: $scopeProvider <- $scope <- transformSensorStatusFilter

折月煮酒 提交于 2020-01-12 12:25:15
问题 marsApp.filter("transformSensorStatus", function($scope) { return function(input, options) { var sensorReading = ( input ? ( input / 1000) : 0); var sensorLowLimit = (options["lowLimit"] ? (options["lowLimit"] / 1000) : 0); var sensorHighLimit = (options["highLimit"] ? (options["highLimit"] / 1000) : 0); var curStat; switch (sensorReading) { case 255: case 254: case 253: curStat = generateStateInnerHtml(sensorReading); break; default: curStat = generateStateInnerHtml(options["sensorStatus"]);

filter $scope Error: Unknown provider: $scopeProvider <- $scope <- transformSensorStatusFilter

拟墨画扇 提交于 2020-01-12 12:23:34
问题 marsApp.filter("transformSensorStatus", function($scope) { return function(input, options) { var sensorReading = ( input ? ( input / 1000) : 0); var sensorLowLimit = (options["lowLimit"] ? (options["lowLimit"] / 1000) : 0); var sensorHighLimit = (options["highLimit"] ? (options["highLimit"] / 1000) : 0); var curStat; switch (sensorReading) { case 255: case 254: case 253: curStat = generateStateInnerHtml(sensorReading); break; default: curStat = generateStateInnerHtml(options["sensorStatus"]);

C++ namespace alias in entire class scope

孤人 提交于 2020-01-11 18:35:29
问题 I expected to be able to use a namespace alias in a class declaration but get a compiler syntax error. struct MyClass { namespace abc = a_big_namespace; void fn() { abc::test(); } }; The only way I can get it to work is to put the alias in every function. void fn() { namespace abc = a_big_namespace; abc::test(); } Additionally I would like to be able to use the alias for function parameters. I haven't found a work-around for that. void fn(abc::testType tt) { abc::test(tt); } Is there a way to

python variable referenced before assignment int vs array

荒凉一梦 提交于 2020-01-11 11:27:09
问题 When I compile this snippet with func1 I get an error about referencing output before assignment, which seems reasonable to me: def func1(): output += 1 output = 0 func1() print(output) But when I compile this snippet with func2 I don't get an error, which seems unreasonable to me. def func2(): output.append(1) output = [] func2() print(output) Thoughts? Thanks in advance and sorry if this is a duplicate. I didn't didn't see this particular question addressed in similarly titled posts when

is there a way to access a non-global shadowed variable in javascript

馋奶兔 提交于 2020-01-11 10:41:13
问题 I'm currently learning javascript scope and was just wondering whether it is possible to access a non-global shadowed variable in javascript? i.e. in the example below, the variable a that equal to 10 in the aFunc function var a = 1; function aFunc(){ var a = 10; function innerFunc(){ var a = 100; console.log("innerFunc a = " + a); console.log("is it possible to access outer function's a variable?"); console.log("global a = " + window.a); } innerFunc(); } aFunc(); ps - I understand naming

is there a way to access a non-global shadowed variable in javascript

主宰稳场 提交于 2020-01-11 10:41:09
问题 I'm currently learning javascript scope and was just wondering whether it is possible to access a non-global shadowed variable in javascript? i.e. in the example below, the variable a that equal to 10 in the aFunc function var a = 1; function aFunc(){ var a = 10; function innerFunc(){ var a = 100; console.log("innerFunc a = " + a); console.log("is it possible to access outer function's a variable?"); console.log("global a = " + window.a); } innerFunc(); } aFunc(); ps - I understand naming

PHP and function scope

若如初见. 提交于 2020-01-11 06:34:06
问题 I was wondering what exactly happens when I do this: $my_variable = 'foo'; function whatever(){ $my_variable = 'bar'; global $my_variable; } I know that, within the scope of the function $my_variable is now 'foo'. What's going on internally? When I do $my_variable = 'bar'; inside my function, I've created a local variable. When I do global $my_variable; on the next line what exactly happens? The local one is automatically deleted? 回答1: Up until the global is processed, the function will be

Inject into private, package or public field or provide a setter?

ぃ、小莉子 提交于 2020-01-10 17:58:13
问题 I see many Java examples using dependency injection with private fields without a public setter like this: public SomeClass { @Inject private SomeResource resource; } But that is a bad idea when the injection should be performed manually for example in unit tests. There are several possibilities to solve this: add a public setter: setSomeResource(SomeResource r) make the field public make the field package protected I'd like to avoid the setter, since nothing really happens in it. So I'd

Argument Error: The scope body needs to be callable

点点圈 提交于 2020-01-10 07:19:13
问题 I'm working through the 'Ruby On Rails 3 Essential Training' and have received a problem when using name scopes. When finding records and using queries withing the Rails console everything went smoothly until I tried to use a name scope in my subject.rb file. This is my code in the subject.rb file. Class Subject < ActiveRecord::Base scope :visible, where(:visible => true) end I saved the .rb file and restarted my Rails console but when I run from my rails console: subjects = Subject.visible I