PHP - Oop / Modular Help
Hey everyone,
My first post here Im always wondering how do you guys keep stuff organized. Let me explain for example I have a class BOX Class Box is used on page1.php and page2.php and page3.php. But now page2.php requires some new functionality which requires me to update a function inside class BOX.. But when I do this I might break page 1 and 3 because I forgot they use that function also. What is the best way to manage this? Should I write a new class which extends BOX for page2 or ???? Similar TutorialsPlease bear with me, a newbie here. I'm trying to implement these on php but after a long googling, still not able to get better information. 1. Procedural packages function(main(myVar) { var mylocalVar="I'm a variable"; function(subA(){ expr.... }; function(subB(){ expr...}, } main("php")->subA() I can do this approach in other language but I'm not able to do it in php.. Any other equivalent solution? 2. How can I overwrite, append, insert, delete an existing modular function (like question 1). append -> means just add sub function to the existing function, and always become part of the function insert -> you can insert a function in a collection of a function, (usage might be on re-ordering the action) delete -> delete/disable a function in a collection of a function I'm trying to make my codes dynamic and flexible as much as possible so I can plug any function that I want. Thank you in advance. Its like an elusive goal of mine. To be able to write big pieces of code that are reusable in multiple projects.
For example: Lets say we are coding a simple 'Membership system'- login / signup etc.
How would for instance something like routing would be handled in this so that it remains modular. Reusable in multiple projects that may be using a different router for their projects.
Any guidance please ? Is there a book that shows how its done ?
Happy New Year, folks! I am having an issue that's been dragging my life for quite some time. I am creating a website for my church maranatha.tv The site's Menu and Content are pulled from a MySQL database I created. As far as this goes, everything is fine; content is pulled from my database with no issues. My problem is as follow: I am including an online bible, which is a third party script I downloaded. This scripts comes with its own database, which I have installed for use in my web server. I used Include() to include the index.php file of the online bible script, from its folder. I just don't know if this the right way to do it. Of course, this script has its own folder and a set of files which makes up the entire bible script. I use an if condition so that when the user clicks on the menu button BIBLE, the script's index.php file is included instead of text from my database. This way of adding the third party script is rendering some unwanted results such as layout distortion (which I don't care at this point), broken links (main issue), and links (although broken) are sent to new pages, instead of staying within my site's CONTENT page template. I need to find a way to make my script more modular so everything renders as intended. Here's my content function: Code: [Select] function content(){ // DETERMINE which page ID to USE in our query below ******************** if (!isset($_GET['jesusid'])) { $pageid = '1'; } else { $pageid = preg_replace('#[^0-9]#i', '', $_GET['jesusid']);} // filter everything but numbers for security) //preg_replace($pattern, $replacement, $string);//preg_replace() Function structure // Query the body section for the proper page $query = mysql_query ("SELECT body_text,title,linklabel, author FROM content WHERE id = '$pageid' LIMIT 1 ") or die (mysql_error()); while ($row = mysql_fetch_array($query)) { echo ucwords($row['title']).' por '; echo '<b>'.$row['author']. '</b><br>'; echo ucwords($row['body_text']); //Add Bible Script if (ucwords($row['title'])=='Biblia') //use row title -- UPPERCASED word { include ('bible/__WINDOWS/search.php'); } } } ?> Just click on the BIBLE button, and then on any link within that page and you will see what I mean. I am still learning PHP and I don't have any background integrating third party scripts to an existing PHP website. I hope someone can help me. Thanks in advance for your assistance. |