antony2kx wrote:
I can help if you need
i suggest that you are doing somethings similar to this
<?php
$page = isset($_GET['page']) ? trim($_GET['page']) : '';
swicth($page)
{
default:
case 'index':
$pageCatcher->fetch('index'); //where index is a function
break;
case 'login':
pageCatcher->fetch('login'); //where login is a function
break;
}
?>
Yeah but more like...
<?php define('MGIGS_START', microtime(TRUE));
/**
* MobileGigs Mobile Community.
*
* Simple mobile community script.
*
* @author Neo Ighodaro
* @copyright CreativityKills Web Development
* @license LICENSE.txt
*/
// Start session
session_start();
// Directory separator
define('DS', DIRECTORY_SEPARATOR);
// Document root
define('DOCROOT', realpath(dirname(__FILE__)).DS);
// System and Application directory
define('SYSPATH', DOCROOT.'system'.DS);
define('APPPATH', DOCROOT.'application'.DS);
// Include the bootstrap file
include DOCROOT.'bootstrap.php';
// Set default language
I18n::set_lang('en-us');
// Requested action/page
$action = arrGet($_GET, 'ac', 'index');
if ( ! Mgigs::valid_page($action))
{
// The page was not found :P
call_user_func('mg_action_error', '404');
exit();
}
if (mg_db_connect() === FALSE)
{
// Could not connect to database O_o
call_user_func('mg_action_error', '3000');
exit();
}
// Launch the page
call_user_func('mg_action_'.$action);
Thats the index that handles the requests. Though im thinking of actually making it totally OOP, but just for the sake of simplicity, im leaving it this way. Though categorizing the functions into classes sounds like another good plan.
I think there are enough users interested in contributing to post the source codes. So i will be attaching it now.
Added after 27 minutes:
The title text has been updated and the source attached. Before we start suggesting codes, we will just take some time to study the script shall we? 🙂
Architechture. . .File: index.php
I commented on the codes as much as i can so it should not be too hard to follow it. But then lets just explain how requests are handled. Pages are loaded from the $_GET['ac']. All pages are stored in the pages.php under system and applications folders.
Why application and system folders? I decided to separate the core libraries and the custom made application libraries and files. The system has classes that are extensible by creating a duplicate and extending it. For example, to extend the View class, create a file in the classes directory of the application folder named view.php and extend the original core class...
<?php
class View extends Core_View {
// Extension code goes here...
}
There are many other things to consider before suggesting codes. I place alot of imoportance to coding styles. Let me share a few...
//------------------------------------
<?php echo $var ?> [okay]
<?=$var?> [not okay] ...some servers disable the short start tags for PHP by default.
//------------------------------------
This also applies to pretty much any codes with { curly braces } ...foreach, for, if, while etc.
if (1===1)
{
echo 'hi'; [okay] ...its really readable
}
if (1===1)
echo 'hi'; [not ok]
if (1===1){
echo 'hi'; [not okay]
}
//------------------------------------
I cant really cover everything im currently tired. if you have any questions about how it works feel free to ask. Next we will start reviewing the existing codes for security.