Jump to content

Recommended Posts

Lol! Ok let's see...

 

index.php

<?php
/*
index.php
this file will be under /var/www/site/public_html or some other public dir
*/

//this will look into ../application
//you can do something like /var/www/site/application if you want
define("APP_PATH", __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "application" . DIRECTORY_SEPARATOR);
define("LIB_PATH", APP_PATH . "lib" . DIRECTORY_SEPARATOR);

//This is because we don't want direct access to files, we'll be checking in every private file
//if this is defined
define("O_FRAMEWORK", "Bla bla bla");

//Had to make theese variable because i had some problems with the require_once when using constants + strings, i'll fix this soon
$config_path = APP_PATH . "config.php";
$router_path = LIB_PATH . "Router.php";
$front_path	 = LIB_PATH . "Front.php";

require_once($config_path);
require_once($front_path);
require_once($router_path);

if(isset($autoload)){
if(!autoload($autoload)){
	echo "zzz";
	exit(); //Errors when trying to open files...
}
}

$router = new Router();

if($router->isRouteValid() == false){
echo "404";	
exit(); //Didn't find route
}

$front = new Front();
$front->servePage($router->getRoutePath());

//This part of code should probably be optimized...
function autoload($autoload)
{
for($i = 0; $i < sizeof($autoload); $i++){
	if(!file_exists(APP_PATH . $autoload[$i] . ".php"))
		return false;
	require_once($autoload[$i] . ".php");
}
return true;
}
?>

 

Front.php

<?php
/*
Front.php

Ok hm... this is very uncomplete :/
*/

if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();}

define("CONTROLLER_PATH", APP_PATH . "controllers" . DIRECTORY_SEPARATOR);

class Front
{
public function __construct(){}
public function servePage($routePath)
{
	if(strpos("/", $routePath)){
		//Will do this later 
	}
	else {
		$controller_name = $routePath;
		$method = "index";
	}

	require_once(CONTROLLER_PATH . $controller_name . ".php");
	$controller = new $controller_name();
	$controller->$method();
}

}
?>

 

Router.php

<?php
/*
Router.php
*/

if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();}

class Router
{
private $_route;
private $_available_routes = array (
	"Homepage" => "/",
);
private $_route_path;


public function __construct()
{
                $this->_route = $_SERVER["REQUEST_URI"];
}

public function getRoute()
{	
	return $this->_route;
}

public function getRoutePath()
{
	return $this->_route_path;
}

public function isRouteValid()
{
	foreach($this->_available_routes as $route){
		if($this->_route == $route){
			$this->_route_path = array_keys($this->_available_routes, $route, true);
			$this->_route_path = $this->_route_path[0];
			return true;
		}
	}
	return false;
}
}

?>

 

config.php

<?php
//This is empty atm
?>

 

Homepage.php (this is the home controller)

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();}

class Homepage
{
public function __construct(){}

public function index()
{
	echo "Homepage";
}
}

?>

 

This is what i got, it's all messed up but i'll fix it soon  8)

Link to comment
https://forums.phpfreaks.com/topic/223219-omega-framework/
Share on other sites

Because it's fun! and also we can do better  ::)

 

EDIT: Also.. if people will like this framework they can use it, but hm... yea maybe there are too many frameworks like this around, what if i do it without OOP? do you think it would be useful to someone? Someone who may wants the fastest framework he can get...

Link to comment
https://forums.phpfreaks.com/topic/223219-omega-framework/#findComment-1153973
Share on other sites

Ok, I rewrote it, and now is far simpler... thanks, i'll update the first post

 

EDIT: looks like i can't edit the first post, well i'll post it here:

 

index.php

<?php
define("O_FRAMEWORK", "Bla bla");
define("APP_PATH", __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "application" . DIRECTORY_SEPARATOR);
require_once(APP_PATH . "Omega.php");

$routes = array(
array("/", "index", "index"),
    array("/about", "about", "index"),
);

new Omega($routes);
?>

 

Omega.php

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access is not allowed"; exit();}

class Omega
{
private $_uri;
private $_routes;
private $_route;

public function __construct($routes)
{
	$this->_uri = $_SERVER['REQUEST_URI'];
	$this->_routes = $routes;

	if(!$this->_isUriValid()){echo "404";exit();}

	$controller_name = $this->_route[1] . "Controller";
	$method_name = $this->_route[2] . "Action";
	require_once(APP_PATH . "controllers" . DIRECTORY_SEPARATOR . $controller_name . ".php");

	$controller = new $controller_name();
	$controller->$method_name();
}

private function _isUriValid()
{
	foreach($this->_routes as $route){
		if($route[0] == $this->_uri){
			$this->_route = $route;
			return true;
		}
	}
	return false;
}

}

?>

 

indexController.php

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access is not allowed"; exit();}

//Will extend Controller
class indexController
{
public function __construct(){}
public function indexAction()
{
	echo "Index method of IndexController";
}
}

?>

 

 

aboutController.php

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access is not allowed"; exit();}

//Will extend Controller
class aboutController
{
public function __construct(){}
public function indexAction()
{
	echo "Index method of aboutController";
}
}

?>

 

I'll create the parent class Controller with a few things right now.

 

What do you think?

Link to comment
https://forums.phpfreaks.com/topic/223219-omega-framework/#findComment-1153985
Share on other sites

The code is getting a bit messy, i gotta clean it up, also there's almost no error check or validation so i'll need to build an Error class to manage that... and... the layout system is really stupid atm, well, i'll change a few things later today, for now this is the code:

 

public_html/index.php

 

<?php
define("O_FRAMEWORK", "Bla bla");
define("APP_PATH", __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "application" . DIRECTORY_SEPARATOR);
require_once(APP_PATH . "Omega.php");

$routes = array(
array("/", "index", "index"),
    array("/about", "about", "index"),
);

new Omega($routes);
?>

 

application/Omega.php

 

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access is not allowed"; exit();}

class Omega
{
private $_uri;
private $_routes;
private $_route;

public function __construct($routes)
{
	$this->_uri = $_SERVER['REQUEST_URI'];
	$this->_routes = $routes;

	if(!$this->_isUriValid()){echo "404";exit();}

	$controller_name = $this->_route[1] . "Controller";
	$method_name = $this->_route[2] . "Action";
	require_once(APP_PATH . "controllers" . DIRECTORY_SEPARATOR . $controller_name . ".php");

	$controller = new $controller_name();
	$controller->$method_name();
}

private function _isUriValid()
{
	foreach($this->_routes as $route){
		if($route[0] == $this->_uri){
			$this->_route = $route;
			return true;
		}
	}
	return false;
}

}
?>

 

application/controllers/indexController.php

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access is not allowed"; exit();}
require_once(APP_PATH . "Controller.php");

class indexController extends Controller
{
public function __construct(){}
public function indexAction()
{
	$this->_loadView("index");
}
}
?>

 

application/controllers/aboutController.php

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access is not allowed"; exit();}
require_once(APP_PATH . "Controller.php");

class aboutController extends Controller
{
public function __construct(){}
public function indexAction()
{
	$this->_loadView("index");
}
}
?>

 

application/Controller.php

<?php
if(!defined("O_FRAMEWORK")){ echo "Direct file access is not allowed"; exit();}

class Controller
{
public function __construct(){}

protected function _loadView($action)
{
	//Remove the "Controller" part of the name
	$controller_name = str_replace("Controller", "", get_class($this));

	//Here we include the top part, then the content and then the bottom part to get the full page...
	//I think there are better ways to do this >_>
	//Also there's no error checking, that's because i didn't make an Error class yet
	require_once(APP_PATH . "layout" . DIRECTORY_SEPARATOR ."top.phtml");
	//->
	require_once(APP_PATH . "views" . DIRECTORY_SEPARATOR .
				 $controller_name . DIRECTORY_SEPARATOR . $action . "View.phtml");
	//->
	require_once(APP_PATH . "layout" . DIRECTORY_SEPARATOR ."bottom.phtml");
}

protected function _loadModel($model)
{
	require_once(APP_PATH . "models" . DIRECTORY_SEPARATOR . $model . "Model.php");
}
}
?>

 

application/layout/top.phtml

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title</title>
</head>
<body>
<div id = "header">
<h1>Omega Framework</h1>
</div>
<div id = "nav">
<ul>
	<li>Homepage</li>
	<li>About</li>
</ul>
</div>
<div id = "content">

 

application/layout/bottom.phtml

 

</div>
<div id = "footer">
<p>Footer</p>
</div>
</body>
</html>

 

application/views/about/indexView.phtml

 

<h2>About page</h2>
<p>Hmmm what?</p>

 

application/views/index/indexView.phtml

 

<h2>Index Page</h2>
<p>This is the index page!</p>

 

public_html/.htaccess

 

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

 

Don't use this code for a real project, it sucks! I'll update it when i can

Link to comment
https://forums.phpfreaks.com/topic/223219-omega-framework/#findComment-1154017
Share on other sites

You need to host this on github or something. Constantly pasting the updated code will not work. You can also setup a notification list for sending quick updates. Not sure if github do this, but if not setup your own discussion board where people can discuss the framework, test, submit ideas and bugs etc

Link to comment
https://forums.phpfreaks.com/topic/223219-omega-framework/#findComment-1154085
Share on other sites

I agree with Anti-Moronic. This is a help forum, not a 'look at my code' forum. Get yourself some project hosting (Github is awesome) and go from there, who knows, you may get lucky and find someone that want's to help you.

 

My opinion? As far as frameworks go there are simple, and there are ridiculously simple. Your stretching the boundaries of what I would consider a framework and what I would simply call skeleton code (ridiculously simple).

 

I'm closing this topic. This is not the place, nor do we have a place for it.

Link to comment
https://forums.phpfreaks.com/topic/223219-omega-framework/#findComment-1154113
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.