WingTsun
01-11-2012, 12:15 PM
Hello to everyone!
I have working as a web-site developer for a while now. I have been mixing HTML, PHP, JS, and more .. all together. One by one, project by project I have started to make them more and more separate. Now its time to separate them completely.
And here is the problem, I can not find the best way to to that. I do not want to use any of the Frameworks. I want to make a clean code.
Here is a smell of my last structure :
core.php
// All kind of Main Functions
function page() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); }
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
classes/exchange.php
class exchange {
public $method;
function rewrite_mehod_name_full() {
global $global;
$method = $this -> method;
$method = $global['global']['payMethod_full'][$method];
return $method;
}
function rewrite_mehod_name_short() {
global $global;
$method = $this -> method;
$method = $global['global']['payMethod_short'][$method];
return $method;
}
function rewrite_mehod_currency() {
global $global;
$method = $this -> method;
$currency = $global['global']['payMethod_currency'][$method];
return $currency;
}
}
$objekts = new exchange;
regular_page.php
include('../includes/core.php');
include("../class/exchange.php");
include("../header.php");
<table border="0" cellspacing="0" cellpadding="0" class="history">
<tr class="head">
<!-- <td> <? echo $global['history']['table']['title']['nr']; ?> </td> -->
<td> <? echo $global['history']['table']['title']['date']; ?> </td>
<td> <? echo $global['history']['table']['title']['from_method']; ?> </td>
<td> <? echo $global['history']['table']['title']['from_amount']; ?> </td>
<td> <? echo $global['history']['table']['title']['to_method']; ?> </td>
<td> <? echo $global['history']['table']['title']['to_amount']; ?> </td>
<td> <? echo $global['history']['table']['title']['state']; ?> </td>
<td> </td>
</td>
<?
if($_bills) {
while($bill = mysql_fetch_array($bills)){
$objekts -> method = $bill['from_method'];
$objekts2 -> method = $bill['to_method'];
$height = '580';
$width = '650';
echo "<tr class='bill'>";
//echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=450,height=500')>".$bill['nr']."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".date("j.n.Y", $bill['date'])."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".$objekts -> rewrite_mehod_name_short()."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".format_2($bill['from_amount'])." ".$objekts -> rewrite_mehod_currency()."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".history_rewrite_method($bill['to_method'])."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".format_2($bill['to_amount'])." ".$objekts2 -> rewrite_mehod_currency()."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".history_rewrite_state($bill['state'])."</td>";
echo "<td> <a href='history_view.php 'onClick='window.print(); return false;'> <img src='images/print_a.png' width='16' height='16' /> </a> </td>";
echo "</tr>";
}
}
else {
echo "<tr><td colspan='8' align='center'> ".$global['history']['table']['data']['empty'].". </td></tr>";
}
?>
</table>
So please help my to find the best way to structurize my web-sites. Thank you!
I have working as a web-site developer for a while now. I have been mixing HTML, PHP, JS, and more .. all together. One by one, project by project I have started to make them more and more separate. Now its time to separate them completely.
And here is the problem, I can not find the best way to to that. I do not want to use any of the Frameworks. I want to make a clean code.
Here is a smell of my last structure :
core.php
// All kind of Main Functions
function page() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); }
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
classes/exchange.php
class exchange {
public $method;
function rewrite_mehod_name_full() {
global $global;
$method = $this -> method;
$method = $global['global']['payMethod_full'][$method];
return $method;
}
function rewrite_mehod_name_short() {
global $global;
$method = $this -> method;
$method = $global['global']['payMethod_short'][$method];
return $method;
}
function rewrite_mehod_currency() {
global $global;
$method = $this -> method;
$currency = $global['global']['payMethod_currency'][$method];
return $currency;
}
}
$objekts = new exchange;
regular_page.php
include('../includes/core.php');
include("../class/exchange.php");
include("../header.php");
<table border="0" cellspacing="0" cellpadding="0" class="history">
<tr class="head">
<!-- <td> <? echo $global['history']['table']['title']['nr']; ?> </td> -->
<td> <? echo $global['history']['table']['title']['date']; ?> </td>
<td> <? echo $global['history']['table']['title']['from_method']; ?> </td>
<td> <? echo $global['history']['table']['title']['from_amount']; ?> </td>
<td> <? echo $global['history']['table']['title']['to_method']; ?> </td>
<td> <? echo $global['history']['table']['title']['to_amount']; ?> </td>
<td> <? echo $global['history']['table']['title']['state']; ?> </td>
<td> </td>
</td>
<?
if($_bills) {
while($bill = mysql_fetch_array($bills)){
$objekts -> method = $bill['from_method'];
$objekts2 -> method = $bill['to_method'];
$height = '580';
$width = '650';
echo "<tr class='bill'>";
//echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=450,height=500')>".$bill['nr']."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".date("j.n.Y", $bill['date'])."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".$objekts -> rewrite_mehod_name_short()."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".format_2($bill['from_amount'])." ".$objekts -> rewrite_mehod_currency()."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".history_rewrite_method($bill['to_method'])."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".format_2($bill['to_amount'])." ".$objekts2 -> rewrite_mehod_currency()."</td>";
echo "<td onClick=window.open('history_view.php?id=".$bill['id']."','villexchange','width=".$width.",height=".$height."')>".history_rewrite_state($bill['state'])."</td>";
echo "<td> <a href='history_view.php 'onClick='window.print(); return false;'> <img src='images/print_a.png' width='16' height='16' /> </a> </td>";
echo "</tr>";
}
}
else {
echo "<tr><td colspan='8' align='center'> ".$global['history']['table']['data']['empty'].". </td></tr>";
}
?>
</table>
So please help my to find the best way to structurize my web-sites. Thank you!