milanello72 Posted April 23, 2014 Share Posted April 23, 2014 Hello! i'm newer in OOP and I have made an website in PHP classic. I want to modify the website and to use OOP. For example in .htaccess I have RewriteRule ^index.html index.php [N] RewriteRule ^([a-zA-Z0-9-_]+).html$ index.php?pagina=$1 [L,QSA] RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9-.\s]+).html$ index.php?pagina=$1&poll=$2 [L,QSA] RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9-.\s]+)/([0-9-_]+)$ index.php?pagina=$1&paginaphoto=$2&id_photo=$3 [L,QSA] #RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9-.\s]+)/([0-9-_]+)/?.jpg$ index.php?pagina=$1&paginaphoto=$2&id_photo=$3 [L,QSA] in index.php I have if ($_GET['pagina']=='katarina') { if ($_GET['paginaphoto'] == '') { echo '<td valign="top" style="border-left: 1px solid #cccccc; padding: 2px;">'; include('includes/katarina.php'); } elseif ($_GET['paginaphoto'] == 'photo') { echo '<td valign="top" style="border-left: 1px solid #cccccc; padding: 2px; border-right: 1px solid #cccccc; padding: 2px;">'; include('includes/photo.php'); } elseif (!empty($_GET['paginaphoto']) and $_GET['paginaphoto'] != 'photo') { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=/katarina/index.html">'; exit; } } so in index.php I used the method GET to load the page katarina.php My problem is how could I change index.php if I would want to use OOP? I need some suggestions of you... Or maybe a good video on youtube or a good article on web. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/287971-a-problem-in-oop/ Share on other sites More sharing options...
trq Posted April 23, 2014 Share Posted April 23, 2014 You don't just migrate existing code to OOP. It is a completely different design approach. To do whatever it is you want, you will need to learn OOP. Quote Link to comment https://forums.phpfreaks.com/topic/287971-a-problem-in-oop/#findComment-1477078 Share on other sites More sharing options...
Psycho Posted April 23, 2014 Share Posted April 23, 2014 I see no need to implement OOP in the above code. When writing OOP you need to have "Objects". For example, if you are creating, editing, viewing data associated with Users, then you would write a class for a User object. That class would handle methods such as creating users, getting the data for users, editing users, etc. However, the code above has a logical flaw. The last elseif() should just be an else. If neither of the first two conditions was to pass then the last condition would always be true. So, it is acting as an else now. But, the problem is that if you make changes in the future you could end up with a setup where a condition doesn't match any of the conditions and a blank page loads. You really need to understand your 'branching' logic and ensure there are no holes. Plus, looking at the conditions, the first one is for when the parameter has an empty value whereas the last is when the parameter has a value but apparently doesn't have a value that you would expect to see. And, in that case, you are doing a redirect wiping out the values. Is there some reason you don't use the first condition as the default? Lastly, your script *assumes* the variables are set which is not a good practice. Assuming the first condition is a viable default result, here is what I would have used if(isset($_GET['pagina']) && $_GET['pagina']=='katarina') { if(isset($_GET['paginaphoto']) && $_GET['paginaphoto']=='photo') { echo '<td valign="top" style="border-left: 1px solid #cccccc; padding: 2px; border-right: 1px solid #cccccc; padding: 2px;">'; include('includes/photo.php'); } else { echo '<td valign="top" style="border-left: 1px solid #cccccc; padding: 2px;">'; include('includes/katarina.php'); } } Quote Link to comment https://forums.phpfreaks.com/topic/287971-a-problem-in-oop/#findComment-1477079 Share on other sites More sharing options...
milanello72 Posted April 23, 2014 Author Share Posted April 23, 2014 So, is it possible to modify the website and to use OOP? Do you know a good video or a good article on web? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/287971-a-problem-in-oop/#findComment-1477083 Share on other sites More sharing options...
Psycho Posted April 23, 2014 Share Posted April 23, 2014 So, is it possible to modify the website and to use OOP? Do you know a good video or a good article on web? Thank you! Based upon how you asked the question, I'm not sure you understand what OOP really is or how it would be used. Yes, you could rewrite the pages to use OOP. But, why would you want to do that? Does the site work as it should? If so, leave it the hell alone. If you want to learn how to program in OOP you might find a tutorial here: http://lmgtfy.com/?q=PHP+OOP+tutorial Quote Link to comment https://forums.phpfreaks.com/topic/287971-a-problem-in-oop/#findComment-1477119 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.