Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
569 views
in Q2A Core by
edited by

When accessing Q2A from external code, how would I get the path to the Q2A root, for use in links? Calling qa_path only returns 1234/question-title when I need either /qa/1234/question-title or http://example.com/qa/1234/question-title.

I've tried doing global $qa_root_url_relative but that's always NULL for some reason. It looks like some functions in 1.5 might do what I want, e.g. qa_path_to_root() - is there an equivalent in 1.4?

Q2A version: 1.4

1 Answer

0 votes
by

It sounds like you want to create an absolute URL to a question page on the Q2A site. If so, you want to use something like this:

qa_path(qa_q_request($questionid, $title), null, qa_opt('site_url'))

Q2A 1.5 has a function qa_q_path(...) that makes this a little easier for you, since you can just pass in a parameter that says you want to use absolute URLs.

by
Thanks. A relative URL would be fine too, but I get "1234/question-title" when I am in a different folder and it should be "../qa/1234/question-title"
by
Yes, that's because relative URLs only work if the entire page view was created within Q2A. They won't work with external access to the Q2A code, so I'd recommend sticking with absolute URLs, or passing '' for the third parameter to qa_path(...) and adding on the prefix yourself.
...