Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Is it possible to override an already declared Controller method?

businessdadbusinessdad Stealth contributor MVP
edited July 2012 in Vanilla 2.0 - 2.8

After a short absence, I'm back with my odd questions. This time I'd like to override ProfileController_Discussions method, but, obviously, I cannot just redeclare it as Vanilla doesn't like having such a conflict.

What I need to do is changing what happens when User opens the /profile/discussions/ page. It's not just a matter of cosmetic changes, I really need to change the logic, therefore I have to implement a Controller.

At the moment, since the "brute force redeclare" doesn't work, I created a Controller with a slightly different name and it works, but it would be nice if it were possible to avoid this workaround.

As usual, thanks for the help.

Comments

  • Options
    ToddTodd Chief Product Officer Vanilla Staff

    We don't really allow redeclares like that right now. Doing what you did is a good idea and you could complete the whole thing by also adding a route that maps /profile/discussions to your new method.

  • Options
    businessdadbusinessdad Stealth contributor MVP

    @Todd Thanks for the answer, at least I know I made the right choice. By the way, how do I add the route you mentioned?

  • Options
    ToddTodd Chief Product Officer Vanilla Staff
    edited July 2012

    There is a routes link in the Dashboard. You can use regular expressions in it so you can make something like /profile/dashboard(.*) point to /profile/dashboard2$1.

  • Options
    businessdadbusinessdad Stealth contributor MVP

    @Todd Thanks, I never noticed it. I learned something new!

  • Options

    best do the route like so

    ^/profile/discussions(/.*)?$ ->/profile/discussions2$1

    ok it is unlikely that you will have something else with discussions, but it good practice any way.

    grep is your friend.

  • Options
    businessdadbusinessdad Stealth contributor MVP

    @x00 I tried to configure the Route as you described, but, if I try to open /profile/discussions, that's exactly the page I get, I don't get routed to my other Controller method. Do I have to enable something to make the routes work?

  • Options

    No I made a mistake there is no leading slash

    ^profile/discussions(/.*)?$->profile/discussions2$1

    grep is your friend.

  • Options
    businessdadbusinessdad Stealth contributor MVP

    @x00 I'm sorry, I feel quite dumb, but I don't seem to be able to make it work.

    To recap, since I can't override Profile_Discussions, I implemented a Profile_DiscussionsList, which can be accessed as /profile/discussionslist. I tried to add a route, so that anyone accessing /profile/discussions would be redirected to /profile/discussionslist, but I can't figure out the syntax.

    I thought something like ^profile/discussions(/.*)?$->profile/discussionslist2$1 would work, as it looks like a normal regex to me, yet I get a 404 when I try to access the routed address.

    Sorry for this repeated question and thanks again for the help.

  • Options
    peregrineperegrine MVP
    edited July 2012

    profile/discussionslist2$1

    take the 2 out
    profile/discussionslist$1

    you are not going to profile/discussionslist2/blah/blah blah

    you are not going to profile/discussionslist/blah/blah blah

    if I answered the question and it worked and saved x00 some time responding maybe he could help me with my asset question - please :)

    If I didn't solve it maybe x00 could help please help me with my asset question :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    businessdadbusinessdad Stealth contributor MVP

    peregrine said:
    profile/discussionslist2$1

    A-ha! I didn't spot it! I'm getting old... Thanks for the tip. :)

Sign In or Register to comment.