Where to transition from here?
Posted: Wed May 08, 2013 10:14 pm
Hello,
My company allows me the creative freedom to develop anything that could be seen as a benefit to the company as a whole, be it a report generator or a function that gets us out of excel sheets. So, I have been building a project for months now, however going over it, it's mostly (entirely) procedural, but it's like that because everything it does is mostly unique (in my eyes). From my junior experience, I'm trying to see what options I have to continue to develop this project and ensure that it is more scabeable as the project goes on.
My current setup utilizes a Front Controller and View, but that's as far into the MVC pattern that I believe I (can) follow. Essentially, a user will browse to the page, run a report by selecting criteria that are typically specific to that report. It will be based on an "OnClick" attribute that is registered to a function in "ajax.js" which fires an ajax call to "ajax.php" which handles the server-side scripting and the ajax request will update the HTML of a set <DIV> to produce the view for the user.
I've been trying to think about how I can consolidate my code, possibly find a way to have a function for javascript and PHP that I can just pass parameters like the SQL and IDs of inputs used, something. Let alone, I haven't really even gone off to explore JSON results yet.
I'm just looking for general guidance on where I should look to push myself more into OOP and/or consolidating my code, because right now, there is A LOT of copy/page and re-arranging going on.
Thank you for your time!
Examples below, as you can see, imagine ajax.js will pass parameters of inputs and ajax.php will handle all the SQL and HTML presentation. This is the backbone of the majority of my pages, each page will have a minimum of one JS function and 1 php function dedicated to it to ensure data is propagated properly. Ajax.php is a case/switch which is called by the ajax.js url indicating the $_GET.
ajax.js
ajax.php
My company allows me the creative freedom to develop anything that could be seen as a benefit to the company as a whole, be it a report generator or a function that gets us out of excel sheets. So, I have been building a project for months now, however going over it, it's mostly (entirely) procedural, but it's like that because everything it does is mostly unique (in my eyes). From my junior experience, I'm trying to see what options I have to continue to develop this project and ensure that it is more scabeable as the project goes on.
My current setup utilizes a Front Controller and View, but that's as far into the MVC pattern that I believe I (can) follow. Essentially, a user will browse to the page, run a report by selecting criteria that are typically specific to that report. It will be based on an "OnClick" attribute that is registered to a function in "ajax.js" which fires an ajax call to "ajax.php" which handles the server-side scripting and the ajax request will update the HTML of a set <DIV> to produce the view for the user.
I've been trying to think about how I can consolidate my code, possibly find a way to have a function for javascript and PHP that I can just pass parameters like the SQL and IDs of inputs used, something. Let alone, I haven't really even gone off to explore JSON results yet.
I'm just looking for general guidance on where I should look to push myself more into OOP and/or consolidating my code, because right now, there is A LOT of copy/page and re-arranging going on.
Thank you for your time!
Examples below, as you can see, imagine ajax.js will pass parameters of inputs and ajax.php will handle all the SQL and HTML presentation. This is the backbone of the majority of my pages, each page will have a minimum of one JS function and 1 php function dedicated to it to ensure data is propagated properly. Ajax.php is a case/switch which is called by the ajax.js url indicating the $_GET.
ajax.js
Code: Select all
function updateStatus() {
$(function () {
var toggle = $('#updateVTO').val()
$.ajax({
url: 'inc/ajax.php?p=updateStatus',
type: 'POST',
data: 'toggle=' + toggle,
dataType: "html",
success: function (html) {
$('#container').html(html);
}
});
return false;
});
}ajax.php
Code: Select all
case 'updateStatus': {
$toggle = $_POST['toggle'];
$employeeid = $_SESSION['employeeid'];
$sql = "SELECT *
FROM dbo.vto_status where status=$toggle";
$result = sqlsrv_query($msdb, $sql, array(), array('Scrollable' => 'buffered'));
if ($result) {
$rows = sqlsrv_has_rows($result);
if ($rows === false) {
$sql = "UPDATE ww_wfm.dbo.vto_status
SET status = '$toggle'";
$result = sqlsrv_query($msdb, $sql);
echo "<br />Status successfully updated!";
} else {
echo "<br />Status is already set to that!";
}
}
}
break;