Search code examples
phpfunctionquestion2answer

Question2Answer type of coding used


I am working on a website and I want to add some kind of question and answer system like Stackoverflow.

I downloaded question2answer and it works perfectly, but when I look a how it is coded I don't understand a whole bunch, it is purely php with a lot of functions and I didn't come across any HTML. Looking into how it is written I find it interesting. I would like to learn more about how all of it works, but I have no idea what it is called (if it has a name). Does anyone know of a tutorial where I could learn a bit more about it.

I am not counting on using question2answer for my website, I just used it to have an idea of how the system works and in the end I want to make this system on my own.

The code looks something like this if it can help :

require_once QA_INCLUDE_DIR.'qa-db-selects.php';
require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-updates.php';

//  Determine whether path begins with qa or not (question and answer listing can be accessed either way)

$requestparts=explode('/', qa_request());
$explicitqa=(strtolower($requestparts[0])=='qa');

if ($explicitqa)
    $slugs=array_slice($requestparts, 1);
elseif (strlen($requestparts[0]))
    $slugs=$requestparts;
else
    $slugs=array();

$countslugs=count($slugs);


//  Get list of questions, other bits of information that might be useful

$userid=qa_get_logged_in_userid();

@list($questions1, $questions2, $categories, $categoryid, $favorite, $custompage)=qa_db_select_with_pending(
    qa_db_qs_selectspec($userid, 'created', 0, $slugs, null, false, false, qa_opt_if_loaded('page_size_activity')),
    qa_db_recent_a_qs_selectspec($userid, 0, $slugs),
    qa_db_category_nav_selectspec($slugs, false, false, true),
    $countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null,
    ($countslugs && isset($userid)) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_CATEGORY, $slugs) : null,
    (($countslugs==1) && !$explicitqa) ? qa_db_page_full_selectspec($slugs[0], false) : null
);

My website is kinda like a social website mostly for action sports, mostly to share media (pictures and videos) and ask questions etc. Do you think it could be a good idea to rewrite all my website in the same kind of format as question2answer ?


Solution

  • No. You should write it with a proper architecture and readable code, and what you posted is a clusterfuckmess. Try any of the over 9000 freely available PHP frameworks such as Symfony2 or Yii.