0

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 ?

Tharif
  • 13,794
  • 9
  • 55
  • 77
Joris Blanc
  • 601
  • 1
  • 10
  • 24

2 Answers2

1

I have worked with Q2A a bit, and I can tell you the architecture actually isn't too bad. It follows MVC well (separating program logic from data logic from output control).

If you want a name for it, I would call it "procedural style" as opposed to object-oriented style. There are some classes used (the HTML output class for example) but it is mostly a bunch of functions, separated into different files.

DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290
  • If it's procedural than it's not MVC...the "M" (model) relies on OOP – Lusitanian Jul 19 '12 at 17:17
  • @David how so? It's about separating the 3 concerns. If all the data-access is completely separated, and the function return *some kind* of data structure (arrays, objects, whatever) then it is a "Model". (Note: using classes does not make something instantly "OOP": http://blog.ircmaxell.com/2012/07/oop-vs-procedural-code.html) – DisgruntledGoat Jul 20 '12 at 11:57
  • Clearly, using classes does not make something OOP. MVC is not _just_ about the separation of the concerns...that's what (literally) separation of concerns is. Though MVC is a design pattern and can be in theory implemented in the procedural paradigm, I'd like to see it done correctly in practice before agreeing. – Lusitanian Jul 20 '12 at 16:47
0

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.

Lusitanian
  • 11,012
  • 1
  • 41
  • 38