1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Something I'm missing with buildPublicLink?

Discussion in 'XenForo Development Discussions' started by Onimua, Feb 11, 2011.

  1. Onimua

    Onimua Well-Known Member

    I've created a form that submits to the database, and everything works fine as you'd expect. The problem occurs in the redirect portion of the code.

    PHP:
            $newMessage $writer->getMergedData();
            
    $return XenForo_Link::buildPublicLink('whiteboard/view-message'$newMessage);

            return 
    $this->responseRedirect(
                
    XenForo_ControllerResponse_Redirect::SUCCESS,
                
    $return,
                new 
    XenForo_Phrase('your_message_has_been_posted')
            );
    The redirect takes me to whiteboard/view-message as I'd expect, and the template loads fine but it doesn't have what I'm expecting to see, which is whiteboard/view-message/title-here.25. Is there something missing that I can't find? I tried searching but didn't find anything that really made it clear.

    I am submitting the data to a separate table within the XF database if that makes a difference.
     
  2. Shadab

    Shadab Well-Known Member

    Have you implemented the "buildLink()" method for the route-prefix class associated with the whiteboard route-prefix?
     
  3. Kier

    Kier XenForo Developer Staff Member

    Can you paste the code from your Whiteboard route prefix class?
     
  4. Onimua

    Onimua Well-Known Member

    Nope, wasn't aware of my needing to do that. This is the first time I've used it so I'm unsure of what I need to do with it. I'm assuming it's stupidly simple?
     
  5. Kier

    Kier XenForo Developer Staff Member

    Yes, it's very simple. You just have to tell the system what to do with the data you provide when building a link. It's done in the Route_Prefix classes.

    For example, posts:
    PHP:
    public function buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
    {
        return 
    XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix$action$extension$data'post_id');
    }
    and pages:
    PHP:
    public function buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
    {
        return 
    XenForo_Link::buildBasicLinkWithStringParam($outputPrefix$action$extension$data'node_name');
    }
     
  6. Onimua

    Onimua Well-Known Member

    Thanks Kier. I ended up one step closer, but apparently I'm missing another step now. [​IMG]

    I now have this: /whiteboard/this-is-a-test-message.27/view-message
     
  7. Kier

    Kier XenForo Developer Staff Member

    /prefix/item.id/action is the way the URL scheme is setup - for example /forums/development-questions.34/create-thread

    If you want to remove the /view-message segment, your action would need to live in actionIndex() from your controller.
     
  8. Onimua

    Onimua Well-Known Member

    Well I do want to keep view-message but switch it to whiteboard/view-message/title.id. I had thought buildPublicLink('whiteboard/view-message') would make it do so but it looks like I'm missing one final piece of the puzzle to get it working 100%. Is that bit simple to do?

    Otherwise I think I might take a different approach with how I'm doing this as I'm probably making it more complex than I should.
     
  9. Kier

    Kier XenForo Developer Staff Member

    The principle of /prefix/item.id/action is fairly ingrained in XenForo. Trying to make /prefix/action/item.id as you suggest is very much swimming against the tide.

    It can be done - you just need to write a custom version of buildLink() and resolveActionWithIntegerParam(), but is it really worth it?

    Consider the URL structure to be like a directory tree. You have a collection of items (prefix) then you pick a single item (item.id) and then you do something with it (action), so you have /forums/myforum.2/create-thread or /posts/1234/edit or /threads/my-thread.234 and so on.
     
  10. Onimua

    Onimua Well-Known Member

    Thanks for the input/time. :) I'll go with the flow and rework my add-on a bit then.
     
    Jeremy likes this.

Share This Page