For example, I am looking at the trait, "AuthenticatesUsers". It has several methods,which in turn make use of other methods. Case in point, "postLogin()" which calls, "$this->validate([])"
However, "$this->validate" can not be found anywhere. I had always believed that $this-> always referred to a method within the class, but there is not validate() method within this class.
So - is my understanding wrong or is Laravel 5.1 doing some funky stuff ?
How do I find methods with $this-> which are not in the class ?
Thanks
Controller AuthController in Laravel 5 uses AuthenticatesAndRegistersUsers trait. It also extends Controller, which uses ValidatesRequests trait. It has a validate method.
Related
I need to call a method from my action object inside the JSP, something like:
var currentStatus = ${getCurrentStatus()};
I cannot call an attribute, and I tried following this answer (How to call an action method using OGNL) and it didn't work.
There are a variety of ways to call methods (on actions, on other objects, or static methods from classes) from OGNL.
In this case, however, I don't see any issue with using a normal accessor. Note that the JavaBean convention is almost (completely?) about naming. A getter named getCurrentStatus(), accessed simply in OGNL via currentStatus, can contain whatever code you want.
This could include the DB access you mention in your question, etc.
I've this two lines on all the action() in the controller so I want to move it to init() so it will get called each time. It doesn't work so I tried __construct and it won't work as it says "PHP Fatal error: Uncaught Error: Call to a member function get() on null"
Maybe that can be done in factory and you still call getServiceLocator in factory class? If I can do it within controller that will be even better as that's less step to do and is that possible to do it in controller so every action will have that?
$view_helper = $this->getServiceLocator()->get('viewhelpermanager');
$view_helper->get('headScript')->appendFile(....);
Only two solutions exist:
You can do an abstract controller, and use the viewhelpermanager as dependency in your constructor. This means you will need to pass the viewhelpermanager in all the subclasses factories and not forget to call the parent construct and so on when creating the object.
You can use a delegator in the service manager and an abstract controller that contains a setViewHelperManager method and a viewhelpermanager (or worst, a trait :) and a ViewHelperManagerAwareInterface and an initializer), and do a "soft dependency", but that's a wrong way to do things in terms of maintenance (code readability).
Why don't you write your own view helper and make that include the js file(s). You can then use this in all the view.phtml files that require these files. If you need to change/add/remove js files then just do this in your view helper, obviously this change will reflect in all your views that use it.
This keeps the view stuff away from your controller.
Hope this helps.
I have a standard class stack in a .NET MVC5 using Entity Framework 6:
MyController()
MyService() : ServiceBase()
ServiceBase() : IServiceBase
All methods/classes are public at the moment.
ServiceBase() contains generic(T) methods and is inherited by all services.
The problem is that MyController() can call the generic methods in ServiceBase() directly. Important properties need to be set on the Entity before being passed to ServiceBase().
Is there any way to hide the ServiceBase() methods from MyController() forcing MyController() to go through MyService() rather than calling ServiceBase() methods directly?
Thanks all.
Why are you starting from an interface? I think you are getting your OO a little confused. I think the problem you are having is that you start at an interface, which doesn't have method visiblity controls. So you try to hide it in ServiceBase, but MyService has to know about the interface so that is why you cannot change visibility midway through.
I would suggest you rethink your OO strategy a bit.
However, if you really want to keep the interface and hide the methods in the base class, you can blank them out in MyService and inside of another method of MyService you can directly call the base class. I have created an example here.
But like I said, I would discourage this behavior and come up with a better OO strategy. If you can get around to posting your code, perhaps in a separate question, then I and the rest of the community can help you out with that. FYI, this might go better in the codereview stackexchange site.
The answer is to make the base classes that I don't want the controllers to access directly abstract while continuing to contain method implementation.
Make the ServiceBase classes abstract with a protected constructor. Then only classes that derive from them can access their methods directly, forcing the controller to call the controllers service which then calls the base service classes.
I wrote all this up in a blog post here
I'm trying to get a list of the methods defined in our Rails codebase, without including anything defined in superclass or dynamically defined at runtime. I've tried instance_methods(false), but a ton of methods are returned:
> User.instance_methods(false).length
=> 310
I'm guessing this is because Rails defines a bunch of methods at runtime. Is there any way to get a list of the methods only defined in the files in our app? Hoping there's a Ruby way and not just running a grep across all of the files. Bonus points for class methods as well...
User.instance_methods will show all the inherited methods as well, so you should run something like that
User.instance_methods - User.superclass.instance_methods
Be ware thought that it will show heaps of other methods that are generated by AR when you inherited the ActiveRecord::Base class
Use MyClass.instance_methods(false), but make sure to pass false as an argument if you don't want it to return the methods defined in the superclasses.
Additionally, use MyClass.singleton_methods(false) for class methods.
More info:
https://apidock.com/ruby/Object/singleton_methods
https://apidock.com/ruby/Module/instance_methods
i want to overwrite a method of
symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php.
I think a good way could be writing again the method in the form class
where i need that method.
In that case if i need that method in other form class should i write
again the new method, so i would break the rule DRY...
So is there any better way?
Regards
Javi
You should be using BaseFormDoctrine if this is a Doctrine specific method or BaseForm if you want the method to apply to all forms. These form classes are provided specifically for this purpose.
Piggybacking on Colonel Sponz's answer, I've done this many times by extending the class I want to override. By extending the class, you don't have to duplicate anything. In the method(s) you want to customize, just add your customized code and then call parent::method_name() to execute the same method of the super class. You get all the benefits of both. Calls to methods that don't exist in the subclass will execute against the super class.
It should be noted that this strategy is basic OOP stuff and isn't limited to Symfony or even PHP.
You could create a new class that inherits from sfFormDoctrine that redeclares the methods you need and then use your new class in place of sfFormDoctrine wherever you need that method.