Is there a way to change the HTML given by the method render(), on Laravel's pagination?
Note: I solved this creating a helper that uses str_replace, but I don't think this is the most correct way...
Thanks
First you need to create a CustomPaginator Class that extends
Illuminate\Pagination\BootstrapThreePresenter
And override its methods.
I needed a custom class attached pagination with 1 onEachSide instead of 3.
So I did this:
https://gist.github.com/aykutcan/495d43041571854a7507
I've found this library -
Landish/Pagination
- that already brings some paginators and lets you easily create your own.
Related
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.
I am using Spring security rest plugin to authenticate the user. In this, there is a class named RestAuthenticationFilter. Now I want to call the methods of some custom class say CustomRestAuthenticationFilter (which extends RestAuthenticationFilter) instead of RestAuthenticationFilter. How to do this?
Is there any way that we define in resources.groovy or somewhere else that to use CustomRestAuthenticationFilter instead of RestAuthenticationFilter ?
I believe the filtering is nicely described ... in the documentation!
https://grails-plugins.github.io/grails-spring-security-core/guide/filters.html
Just amend the grails.plugin.springsecurity.filterChain.filterNamesvalue in the Config.groovy file so it contains your RestAuthenticationFilter instead of RestAuthenticationFilter and you should be good to go.
I need to append a suffix to the config value "grails.plugin.springsecurity.auth.loginFormUrl = /login/auth" dynamically at runtime. So I think I would have to change the field "loginFormUrl" in class "LoginUrlAuthenticationEntryPoint". The method "setLoginFormUrl" is deprecated so I wonder how can I change that at runtime? Should I inject/create a new "LoginUrlAuthenticationEntryPoint" everytime I need to do that? How/where would I do that?
So the solution is quite simple. I implemented my own AuthenticationEntryPoint which is pretty much like the LoginUrlAuthenticationEntryPoint but has a different implementation of the determineUrlToUseForThisRequest method.
Then you only have to add this to your resources.groovy:
authenticationEntryPoint(MyCustomEntryPoint) {}
I am trying to refactor my views a bit and up til now i have been using the built HTML helpers but i thought i would create my own - they're extension methods right?
I wonder if anyone can confirm or give advise when an HTML is needed? I think i once saw a document that said if you use 1 IF statement in your views encapsulate it into a html helper - would anyone agree with that?
With regards to creating html helpers, would it be better to create my own class rather than add extension methods to the HTML class that ships with MVC? Any body have ideas on this?
Or possible i shouldn't bother with HTML helpers and just use the built in ones and continue to use my IF statements within views.
Thanks in advance
Use HTML helpers when you want to encapsulate the output of a piece of HTML markup that can take varying values.
I'd recommend creating them as extension methods to HtmlHelper rather than creating your own class, as your own class won't be available inside of the default ViewPage without either instantiating a new instance inside of the View or subclassing ViewPage and using this in the View (or passing in on the model, but that's just wrong!).
HTML Helpers are extension methods. I can confirm as well that I too use the 'if' rule when it comes to views. Any view logic coded should, IMO, be in a helper.
You can use helper to render custom markup, or control which markup(ie existing view) is displayed.
Not too sure about the ease of this, but it does lend itself to more unit testing (please comment on this aspect if someone has more info).
With regards to creating html helpers, would it be better to create my own class rather than add extension methods to the HTML class that ships with MVC? Any body have ideas on this?
If I understand correctly, in this respect my suggestion would to separate your helpers into their own classes. The reasoning behind this for me would be that you easily know when looking at your views what are standard helpers vs the ones you've created. I think this will improve maintainability.
i shouldn't bother with HTML helpers and just use the built in ones and continue to use my IF statements within views.
I'd say No! (or it depends). One of the benefits of using a helper would be to reuse the same view logic in multiple views as opposed to re-coding the same if statements. This means your code is more DRY, which is always better. In the event you need to debug some weirdness error, you only need to look in one place, the newly created helper.
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.