How to call a helper function from a library class [duplicate] - codeigniter-3

This question already has answers here:
How do you load a helper within a library in codeigniter?
(2 answers)
Closed 12 months ago.
I have a library class "Weekprint.php" (libraries/Weekprint.php) and in a helper file (calendar_helper.php) I have function like
print_calendar($start, $events, $cal_type).
I can use them separately,
I wonder if/how I can call print_calendar from Weekprint.
I use Codeigniter 3.1.5

You can call the helper from the library. The helper needs to be loaded before it can be used. Pick the logical spot in Weekprint.php to do that in the usual way.
$this->load->helper('calendar_helper');
After that, you can call it in the usual way when needed.
print_calendar($start, $events, $cal_type);
Obviously, the various arguments to the helper function need to be assigned values.

I could do it,
$CI = &get_instance();
$CI->load->helper('calendar_helper');
Inside the library Weekprint.php

Related

Dart - How to access global scope? [duplicate]

This question already has answers here:
How can I call a function from a method of the same name?
(3 answers)
Closed 12 months ago.
The simple actual question is
How to access GLOBAL scope in Dart?
Below is just the answer why I'm looking for it.
I have a problem which requires me to learn about Dart's scope resolution from here but unfortunately I can't find the solution for my problem, not even from Google or here, which was surprising me to have to open this question.
Dart allows user to exclude the this. on member variable access within class's scope so if two potentially conflicted variables need to share the same name, they need to be differentiated with scope operator and reference.
I need to define a class with member variable print where there is also global function print being called somewhere within the class. Of course print() => print(...) will returns error so I'm expecting something as simple as print() => global.print(..) but neither that is working.
I know there's workaround to solve it but please I need a straightforward one if any. Thank you.
you could add this line at the top of your file:
import 'dart:core' as core;
Then you would be able to refer to print as core.print(...);
The problem is that now you would have to use core. for every primitives like int, example:
core.int variable = 1;
I think this is not worth it and it's better to use another name for your print method.

What is the point of adding 'new' in front of a widget in Flutter? [duplicate]

This question already has answers here:
Do you need to use the "new" keyword in Dart?
(3 answers)
Closed 2 years ago.
For instance,
return new Container(child: new Text('Hello'),);
VS
return Container(child: Text('Hello'),);
I see people use both and was just wondering what the point is. Is it possible to use the same widget again somewhere or something?
the "new" keyword was once required in dart (the language used for flutter) for object instantiation, but this requirement was removed.
In order to prevent breaking old code, the keyword remains but is now optional. There is no difference between using it or not using it.
You may choose to use it if you want to make it clear that you are intending to do object instantiation and not call a function, as attempting to do new somefunction() //not a constructor will fail, though this is optional.

What does external keyword mean in Dart? [duplicate]

This question already has answers here:
What does external mean in Dart?
(6 answers)
Closed 2 years ago.
For example: this is a private named constructor of DateTime class from date_time library :
external DateTime._now();
I found a stack overflow post asking the same question:
What does external mean in Dart?
9.4 External Functions An external function is a function whose body is provided separately from its declaration. An external function may
be a top-level function (17), a method
The body of the function is defined somewhere else. As far as I know
this is used to fix different implementations for Dart VM in the
browser and Dart VM on the Server.
-Günter Zöchbauer

Dynamic field reference for nested structures [duplicate]

This question already has answers here:
Dynamical access to nested fields in Matlab
(2 answers)
Closed 4 years ago.
In our MATLAB code, we've been using dynamic field references a lot, and they're pretty fantastic. We have a lot of different data structures with different field sets, so it makes it a whole lot easier to access any one of them simply using the struct.('field') notation, without having to use an eval statement.
However, where we run into problems is that many of these structures have multiple levels, and we don't always know how deep into the structure we will need to go. Ideally we'd like to be able to access them without using an eval statement, perhaps something like
struct.('field.field2.field3')
Is there a way to dynamically access structures with unknown depth using the builtin functionality? Or will we have to create a custom function for accessing all of our structures?
This code works for the following assumptions and usage cases:
There is a field that you do not know where it is within some nested dynamic structure.
The name of this field is unique, i.e. there is no other field anywhere in the struct with the same name.
The following function works:
function [fieldplace]=findfield(s,field)
% is one of these?
fieldplace={};
if (isfield(s,field))
fieldplace{end+1}=field;
return;
end
if ~isstruct(s)
fieldplace={};
return;
end
% otherwise is nested somewhere, use recursivity.
fnames=fieldnames(s);
for ii=1:numel(fnames)
fieldplace=findfield(s.(fnames{ii}),field);
if ~isempty(fieldplace)
fieldplace=[fnames{ii} fieldplace];
return;
end
end
end
Usage case:
s.a=1;
s.b.c=2;
s.b.d=3;
s.e.f.g=4;
s.h.i.j.k=5;
result=findfield(s,'k');
You can read the field as:
getfield(s,result{:})

How to prefix/suffix identifiers within a macro? [duplicate]

This question already has answers here:
Is it possible to declare variables procedurally using Rust macros?
(4 answers)
Closed 5 years ago.
When using a macro that defines a function, is it possible to add a prefix to the function?
macro_rules! my_test {
($id:ident, $arg:expr) => {
#[test]
fn $id() {
my_test_impl(stringify!($id), $arg);
}
}
}
For example, fn my_test_$id() {
I'm defining tests using an identifier which may begin with numbers, and I would like to use a common prefix.
Currently this is not supported in stable.
However there is a feature in nightly called concat_idents:
concat_idents!(my_test_, $id)
See
Rust docs
Issue
Update: it seems there aren't near-term plans to add this into stable releases, see issue.
[...] is it possible to add a prefix to the function?
No. Really, really no. Super totally not at all even in the slightest.
I would like to have use a common prefix.
Put them all in a mod instead.
As mentioned, you should use submodules for this, but remember that macros can create submodules, submodules can be nested allowing their names to overlap, submodules can provide impls, and the tests submodule is not magic.
I once submitted a pull request that avoids numerous "boiler plate names" by refactoring the code using these tricks, although the #[no_mangle] exports make it harder.