methods

codeigniter check for user session in every controller

徘徊边缘 提交于 2019-12-17 08:23:37
问题 I have this private session in one of my controllers that checks if a user is logged in: function _is_logged_in() { $user = $this->session->userdata('user_data'); if (!isset($user)) { return false; } else { return true; } } Problem is that I have more than one Controller. How can I use this function in those other controllers? Redefining the function in every Controller isn't very 'DRY'. Any ideas? 回答1: Another option is to create a base controller. Place the function in the base controller

Optional Methods in Java Interface

和自甴很熟 提交于 2019-12-17 08:16:07
问题 From my understanding if you implement an interface in java, the methods specified in that interface have to be used by the sub classes implementing the said interface. I've noticed that in some interfaces such as the Collection interface there are methods which are commented as optional, but what exactly does this mean? Its thrown me a bit as I thought all methods specified in the interface would be required? 回答1: There seems to be an awful lot of confusion in the answers here. The Java

How to export C# methods?

一曲冷凌霜 提交于 2019-12-17 07:31:11
问题 How can we export C# methods? I have a dll and I want to use its methods in the Python language with the ctypes module. Because I need to use the ctypes module, I need to export the C# methods for them to be visible in Python. So, how can I export the C# methods (like they do in C++)? 回答1: Contrary to popular belief, this is possible. See here. 回答2: With the normal Python implementation ("CPython"), you can't, at least not directly. You could write native C wrappers around our C# methods

How to addeventlistener to multiple elements in a single line

﹥>﹥吖頭↗ 提交于 2019-12-17 07:19:02
问题 Example 1 Element1.addEventListener ("input", function() { this function does stuff }); Example 2 Element1 && Element2.addEventListener("input", function() { this function does stuff }); it might not be correct grammatically, but is there a way i can give two elements the same Dom method at the same time (same line) instead of having to write them apart? 回答1: Well, if you have an array with the elements you could do: let elementsArray = document.querySelectorAll("whatever"); elementsArray

How can I get the value of a session variable inside a static method?

匆匆过客 提交于 2019-12-17 07:17:08
问题 I am using ASP.NET page methods with jQuery.... How do I get the value of a session variable inside a static method in C#? protected void Page_Load(object sender, EventArgs e) { Session["UserName"] = "Pandiya"; } [WebMethod] public static string GetName() { string s = Session["UserName"].ToString(); return s; } When I compile this I get the error: An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Session.get'` 回答1: HttpContext.Current.Session[".

class method generates “TypeError: … got multiple values for keyword argument …”

南笙酒味 提交于 2019-12-17 07:14:09
问题 If I define a class method with a keyword argument thus: class foo(object): def foodo(thing=None, thong='not underwear'): print thing if thing else "nothing" print 'a thong is',thong calling the method generates a TypeError : myfoo = foo() myfoo.foodo(thing="something") ... TypeError: foodo() got multiple values for keyword argument 'thing' What's going on? 回答1: The problem is that the first argument passed to class methods in python is always a copy of the class instance on which the method

Passing just a type as a parameter in C#

﹥>﹥吖頭↗ 提交于 2019-12-17 07:07:12
问题 Hypothetically it'd be handy for me to do this: foo.GetColumnValues(dm.mainColumn, int) foo.GetColumnValues(dm.mainColumn, string) where the GetColumns method will call a different method inside depending on the type passed. Yes, I could do it as a boolean flag or similar, I just wondered if there was a way to perhaps pass this, and then ask: typeof(arg[1]) or similar... I could also override the method, use generics, etc - I know there are different ways to do this, I was just curious if

Why does the Scala compiler disallow overloaded methods with default arguments?

南楼画角 提交于 2019-12-17 07:07:11
问题 While there might be valid cases where such method overloadings could become ambiguous, why does the compiler disallow code which is neither ambiguous at compile time nor at run time? Example: // This fails: def foo(a: String)(b: Int = 42) = a + b def foo(a: Int) (b: Int = 42) = a + b // This fails, too. Even if there is no position in the argument list, // where the types are the same. def foo(a: Int) (b: Int = 42) = a + b def foo(a: String)(b: String = "Foo") = a + b // This is OK: def foo

How to get all methods of a python class with given decorator

六眼飞鱼酱① 提交于 2019-12-17 07:02:29
问题 How to get all methods of a given class A that are decorated with the @decorator2? class A(): def method_a(self): pass @decorator1 def method_b(self, b): pass @decorator2 def method_c(self, t=5): pass 回答1: Method 1: Basic registering decorator I already answered this question here: Calling functions by array index in Python =) Method 2: Sourcecode parsing If you do not have control over the class definition , which is one interpretation of what you'd like to suppose, this is impossible

How to get all methods of a python class with given decorator

喜欢而已 提交于 2019-12-17 07:02:11
问题 How to get all methods of a given class A that are decorated with the @decorator2? class A(): def method_a(self): pass @decorator1 def method_b(self, b): pass @decorator2 def method_c(self, t=5): pass 回答1: Method 1: Basic registering decorator I already answered this question here: Calling functions by array index in Python =) Method 2: Sourcecode parsing If you do not have control over the class definition , which is one interpretation of what you'd like to suppose, this is impossible