Jump to content
Larry Ullman's Book Forums

another_noob

Members
  • Posts

    60
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by another_noob

  1. That is what I am noticing, there a lot of descriptions and outright opinions as to what a "proper" MVC implementation is. I have read some white papers that left me dazed and confused. I think it is best (for me) to not over think it and just do it with a smallish project. I am starting to get a lot of paying jobs now and I am trying to come up with a consistent way of doing things. I need to start thinking in terms of a "reusable code base". These are smaller projects and I agree that trying to "OOP it up" would definitely be overkill. However, they lend themselves to a MVC implementation very well. Then, after I am comfortable with my MVC framework, I will venture into OOP if it seems appropriate to the specific project. I started using PhpStorm by JetBrains as an IDE and love the ability to start a full HTML5 boiler plate application (Php Storm imports the latest version automatically) with a couple mouse clicks, drop my shiny new bootstrap files into the project and be on my way to a solid MVC implementation in less than 60 seconds. Thank you HartleySan for your time, as always I really appreciate your input.
  2. I am slowly working my way through the book trying to not peek too far ahead. I have built the chapter 2 modularized site example and found it to be very interesting. My question is more of a theoretical one I guess. I understand the basic concept of MVC...well I think I do. I understand OOP conceptually, for the most part anyway. Where I think I am getting confused is that this bootstrap system looks like a MVC implementation of sorts. The modules can be called views, the index.php makes up a controller and separate db files for database operations make up the models. I was thinking that the book was going to build upon this bootstrap in subsequent chapters, but it does not revisit it at all. It left me wondering the best way for me to use it with my current knowledge without coding a hodge-podge of concepts. Since I am not ready for a "full on" major OOP project just yet, would it be silly to code a pseudo MVC application using procedural php and this bootstrap system as the base framework? It seems like a good idea at the moment, but as I learn more I realize I have coded a few WTFs that with new found knowledge, I am able to refactor my code base and save some head scratching by seasoned php developers. Am I on the right track with this thinking? Could I call this a MVC implementation or is it just another way of organizing the code base and not to be confused with MVC?
  3. I found this at SO http://stackoverflow.com/questions/1705856/socket-transport-ssl-in-php-not-enabled perhaps it will help.
  4. Yeah, exactly. That is what I see. Very good explanation. That clears it up for me, now I can move on. Thank you very much. I like this task list code. I have integrated it into my current projects in the admin section so I can stay better organized and my clients can see where I am headed. They can "read only" and I can remove as items are accomplished. As far as I am concerned, the code and new knowledge gained in the first 25 pages has more than paid for this book. Thanks for your time HartlySan.
  5. Time to flaunt my noobnis over here now. I just bought the book and am working through the first chapter. Page 23 item 9 suggests adding the following code for debugging: echo '<pre>' . print_r($tasks,1) . '</pre>'; What I can't get clear up in my head is...what is the optional bool parameter doing? I read all over the 'net that it allows for assigning the print_r value to a variable instead of printing it out. That is what the PHP manual states also: http://fr2.php.net/print_r The output I get from print_r($tasks,1) for the code in the book is this, just as shown in the book: Array ( [0] => Array ( [1] => Must Do This! [2] => Another Task [3] => My New Task [4] => This is a new task! ) [2] => Array ( [5] => Subtask 1 [6] => Subtask 2 [8] => Subtask 3 ) [6] => Array ( [7] => Subsubtask 1 ) ) If I omit the bool and use print_r($tasks), like this: echo '<pre>' . print_r($tasks) . '</pre>'; This is my output: Array ( [0] => Array ( [1] => Must Do This! [2] => Another Task [3] => My New Task [4] => This is a new task! ) [2] => Array ( [5] => Subtask 1 [6] => Subtask 2 [8] => Subtask 3 ) [6] => Array ( [7] => Subsubtask 1 ) ) The PHP manual shows that I should get the output with new lines with the bool omitted. I am getting human readable data in either case, but the former output is easier to read than the latter. Nowhere do I read that using the optional bool parameter will format the output for a better formatted output. I hate to ignore little things like this because they always find a way to haunt me later. What is going on here with the optional bool? I am using PHP version 5.4.4 if that makes a difference. Thanks.
  6. Thanks HartleySan, that thread really sums it up. Looks like a few others over at SO have had a head scratching time with this issue also. I looked around over there, but didn't find that thread. Now it all makes sense. I will adopt the "fix it all" function described in the thread at SO and include it in my scripts from now on. Thanks for your reply. Now off to break some more code...
  7. I use the console.log function with Firebug all over the place in my javascript/jquery without any problems, I couldn't develop without it really. I am just finishing up a major project and decided I better test this app on IE. My javascript files choked as the page loaded and I got an unresponsive browser. After a panicky debugging session, I found that IE was throwing a "console undefined" error. I commented out all of my console.log function calls and all is well now. Strange thing though...when I activated the developer console while using (in this case) IE9, my javascript worked okay and my calls to console.log were logged to the console. This confused me because it appeared that my javascript was working fine. If I closed the developer console the javascript would continue to work just fine. If I refreshed the browser with the developer console closed the javascript files with the calls to console.log would stop working again. I thought that console.log should work on all modern browsers. Is IE9 not considered a modern browser? I could live just fine without IE if everybody else in the world would set it ablaze. Anyone had an issue like this and if so, what is a simple way to deal with it. Thanks.
  8. I refactored my javascript to jquery just for fun and the problem is fixed. Due to the lack of experience when I originally wrote the javascript, I had some ugly code. Lessons learned from my last thread helped me get through this and fix it. I am not sure really what was causing the problem specifically, but I suspect several things. That darn learning curve! Thanks.
  9. I am using the code from the book to make the modal, just a div. The way I am using the modal is this: A row of questions in an HTML table is clicked by the user. This sends the row id of the clicked row to an ajax function that sends the row id to a PHP script that fetches the question and returns the string and this HTML inside the modal window: <?php echo' <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Test</title> </head> <body> <div style="margin-top: 100px; margin-left:10px; overflow: hidden;"> <form id="edit_form" action="update_question.php" method="POST" > <fieldset> <legend>Edit the selected text and submit the changes</legend> <textarea name="editText" rows="10" cols="100">This is some text to send to the script</textarea> <input type="hidden" name="quest_id" value="1"> <div style="text-align: center; margin-top: 50px;"> <input type="submit" name="submit" value="submit"> </div> </fieldset> </form> </div> </body> </html>'; ?> I simplified the script for clarity. Up to this point everything works fine. When I click submit, The form's action is ignored and the method defaults to GET and I get redirected to the same page every time. I var_dumped the POST at update_question.php, but I never actually get there. If I take the same code and put it into a separate script without using the modal window, it works as expected. It works fine in Firefox every time. It must be a problem with how I am using this echoed string as my response text to create the form in the first place. I am perplexed at this point. Thanks for your time.
  10. Well, before anybody wastes any time trying to help me. I find the problem has nothing to do with the modal window. I copied the form code to a new script outside of the modal and I am having the same issue. I will look over my code and report my error. Sorry for wasting bandwidth.
  11. I am using a modal window as a container for a simple form. This "POST" form submission works fine in Firefox every time. In IE9 and Chrome the form action and method is apparently being ignored. In IE and Chrome the submission redirects the user to a random page because the method defaults to "GET" and all of the POST data ends up in the query string. The form should should "POST" data to a PHP script that saves the data and then redirects the user back to the original page. Here is the form action: <form id="edit_form" action="update_question.php" method="POST"> The submission ignores the action and method. So, I guess the question is: Should I be able to use a modal window as a form container...that will work in all modern browsers of choice?
  12. I don't mean to keep beating this thread to death, but in my studies to understand why "click" or "bind" did not work for me, I found this info at the jQuery site http://learn.jquery.com/events/handling-events/ I changed my code to use the "on" function and it works as expected. This is the first I have heard of the "on" function. I will post the revised code just in case anyone is following this thread. The button that is in each HTML table row: <td><button id="contact_id_' . $contact_row['contact_id'] . '" class="reply_button">Reply</button></td> The javascript turned jQuery: $(document).ready(function() { //This block of code gets the contact_id of the row when a reply button is clicked and makes an ajax call for the reply form var reply_btn = $('.reply_button'), i, len; for (i = 0, len = reply_btn.length; i < len; i += 1) { //Add a click event listener and pass our function as an anonymous function reply_btn[i].on('click', function(){ //store our php sent variable in a js variable var contact_id = this.id.substr(11); console.log('contact_id = ' + contact_id); //Send the contact_id variable as data in our ajax call var data = 'contact_id=' + contact_id; //ajax call with anonymous callback function. returns a HTML reply form $.post('getReplyForm.php', data, function(contact_reply_form){ $('#reply_div').html(contact_reply_form); }); // Prevent the form from submitting: return false; }); } }); // Document ready.
  13. I decided to use a jQuery click handler just to keep it all one way or another as opposed to mixing vanilla javascript with jQuery. I couldn't get a jQuery click function to work on the reply_btn array and using "bind" didn't work either. I could have left it alone, but I am trying to understand all this higher level stuff. I decided to go with an anonymous function here as well. Thanks again for your help, I learned a lot with this seemingly simple script. This is my script now and it is working fine. $(document).ready(function() { var reply_btn = $('.reply_button'), i, len; for (i = 0, len = reply_btn.length; i < len; i += 1) { //Add a click event listener and pass our function as an anonymous function reply_btn[i].addEventListener('click', function(){ //store our php sent variable in a js variable var contact_id = this.id.substr(11); //Send the contact_id variable as data in our ajax call var data = 'contact_id=' + contact_id; //ajax call with anonymous callback function. returns a HTML reply form $.post('getReplyForm.php', data, function(contact_reply_form){ $('#reply_div').html(contact_reply_form); }); // Prevent the form from submitting: return false; },false); } }); // Document ready.
  14. Thank you HartleySan for the reply. Yeah, my code was a mess after looking at your solution. Just when I start to get a handle on javascript, I get tossed into a jQuery world and get a little confused. After playing around with the code a bit, this is the entire block of code that gets the contact_id from the corresponding button in the html table row, sends it off as data in an ajax request and fills a div in the html with a reply form. It all seems to work without error or having to click twice. If you see anything you would change, please let me know. i appreciate your time for helping me with this issue. The script: $(document).ready(function() { var reply_btn = document.getElementsByClassName('reply_button'), i, len; for (i = 0, len = reply_btn.length; i < len; i += 1) { reply_btn[i].onclick = getContactId; } function getContactId() { //store our php sent variable in a js variable var contact_id = this.id.substr(11); console.log('contact_id = ' + contact_id); //Send the contact_id variable as data in our ajax call var data = 'contact_id=' + contact_id; //ajax call with anonymous callback function $.post('getReplyForm.php', data, function(contact_reply_form){ $('#reply_div').html(contact_reply_form); }); // Prevent the form from submitting: return false; } }); // Document ready.
  15. This solution you provided not only helped me solve the problem, but helped me get a better understanding of how to get PHP data from HTML tables which I seem to need to do a lot. I modified this example and now I am putting a button into each table row. When the user clicks the button, the contact_id value is passed to javascript and is used for data in an ajax call. This is all working as expected except I have to click a button twice the first time after the page is loaded. After that, one click is all that is necessary. I know the click event is working because I am getting the console.log('Reply button clicked') string in the Firebug console. The second click I get the string and the second log entry with the contact_id value. It appears that function getContactId() is not getting called on the initial click, but is getting called any click after that. Here is the relevant HTML button code: <button id="contact_id_' . $contact_row['contact_id'] . '" class="reply_button">Reply</button> And here is the relevant javascript: $(document).ready(function() { // Watch for the reply button click: $('.reply_button').click(function() { var reply_btn = document.getElementsByClassName('reply_button'), i, len; for (i = 0, len = reply_btn.length; i < len; i += 1) { reply_btn[i].onclick = getContactId; console.log('Reply button clicked'); } function getContactId() { var contact_id = this.id.substr(11); console.log('contact_id = ' + contact_id); } // Prevent the form from submitting: return false; }); // button click function }); // Document ready. It is not much different than the original post example...just using a button and jquery. I search SO for answers, but couldn't find a solution that seemed to apply in this case. I wrote the rest of the code for this and all is working except this silly problem. Any suggestions? Thanks.
  16. Well, after struggling with this issue far too long, I commented out the lines of code giving me the duplicate submission: // Check for a duplicate submission, just in case: // Uses sessions, you could use a cookie instead. if (isset($_SESSION['token']) && ($_SESSION['token'] == $token)) { $errors['token'] = 'You have apparently resubmitted the form. Please do not do that.'; } else { // New submission. $_SESSION['token'] = $token; } My thinking on this decision is that this script relies on javascript entirely to process the payment. With that in mind there isn't an easy progressive enhancement technique that is going to be worth my time to figure out. Javascript disables the submit button immediately after the user clicks it anyway, so a dual submission seems impossible. As the tutorial is written, if the user has javascript disabled a dual submission is not possible...either is a single submission. It still bugs me that I could not get those simple lines of code to work as expected though. I gained a lot of Stripe knowledge the last few days. My cart system is coming along awesome. Great tutorial Larry, thanks.
  17. I am working through Larry's Stripe tutorial and have run into what seems like a simple issue, but is giving me fits. The problem is I keep getting a duplicate submission error. I am using the code verbatim from the tutorial download with just the addition of my added diagnostic conditionals. The conditional comparing the $_SESSION['token'] == $token always returns true even when it shouldn't. Here is the output from my conditionals: token = tok_102hNa23Z1ryxpC0EVh3z6aL SESSION[token] before comparing = tok_102hNU23Z1ryxpC0Vw4f922T SESSION[token] after comparing = tok_102hNa23Z1ryxpC0EVh3z6aL Here is the relevant code snippet: // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Just for developmental diagnostic purposes if(isset($_POST['stripeToken'])): echo 'token = ' . $_POST['stripeToken']; endif; //Just for developmental diagnostic purposes if(isset($_SESSION['token'])): echo '<br />SESSION[token] before comparing = ' . $_SESSION['token']; endif; // Stores errors: $errors = array(); // Need a payment token: if (isset($_POST['stripeToken'])) { $token = $_POST['stripeToken']; // Check for a duplicate submission, just in case: // Uses sessions, you could use a cookie instead. if (isset($_SESSION['token']) && ($_SESSION['token'] == $token)) { $errors['token'] = 'You have apparently resubmitted the form. Please do not do that.'; } else { // New submission. $_SESSION['token'] = $token; } } else { $errors['token'] = 'The order cannot be processed. Please make sure you have JavaScript enabled and try again.'; } //Just for developmental diagnostic purposes if(isset($_SESSION['token'])): echo '<br />SESSION[token] after comparing = ' . $_SESSION['token']; endif; I must be overlooking something very simple. I don't see where anybody else has had a problem with this code. Thanks for looking at it.
  18. Thank you very much for the reply Larry. I agree about the money part. If I boiled this down to how much per hour I made, well...the number would be pretty low. I was looking at it as you stated, gaining experience, gaining a clients trust, building a portfolio and oh yeah, getting some money too. In each of these scenarios the client and the situation were entirely different and required a different approach to the way I had to handle things. I am sure the next situation will be different in other ways or a blend of the two and will require yet a different approach. I will keep plugging along and keep learning the code and just as important learning the business side of all this. By the way, if I have not mentioned it before, your books have helped me launch a new career and a new professional life. Thanks for all you have done for me and others who have read your books and gained "marketable knowledge". I am choosing to use Stripe mainly because you took the job there and because I hate dealing with PayPal...lol. Thanks again.
  19. I hope this is the appropriate place to post this. I have two entirely different client projects in progress at the moment. One is a training website for an automotive manufacturer, but is being handled through a consulting company. The other project is a basic website turning into an e-commerce site. In both of these projects the clients were rather vague in what exactly they wanted for an end result. The training website started out as a request for a mobile app. At my initial meeting I suggested that what they really need is a web application that is accessible by all mobile devices. They agree because they didn't really know the difference between a mobile app and a web application. Their lack of knowing what they wanted, what is possible and what would work best for end users made it very difficult for me to write code for something I really can't see! After several meetings and rough draft rewrites, I finally designed a web app that will work great for them. I ended up eating a bunch of time because I wanted the gig and there may be a lot more work from this consulting firm if I "come through" for them. They are happy so far based on the checks they are sending me. The other project started as a basic website that I felt was a waste of money for the client. I suggested more of an e-commerce site and the client was very receptive to the idea. This is a project that keeps growing as the client learns what is possible. I actually spend two days a week at the clients location to "get a better feel" of his business operation. I have a lot of work yet on the site, but it is coming along and the client is very happy so far. Now, as my name states, I am another_noob that seems to be diving a little too far into the deep end. I am trying to use common sense, but as we all know sometimes that can get us in trouble. In these two scenarios, is this just the way the business works or am I flying a little too much by the seat of my pants due to a lack of experience? I am looking forward to some input from those who have been there done that and from those who get sweaty hands just reading this.
  20. Thank you HartleySan. That gives me something to work with. I will refactor my code and see if I can get a grip on this. I will post back my experience. I appreciate your time and your thorough explanation.
  21. In the past, I relied on inline event handlers to pass PHP variables to my javascript functions. I am trying to get away from that and I want to use the techniques in this book. I am struggling with the following trivial code example that passes a PHP variable that represents the record id of the row in a HTML table. For example, here is my HTML row with the inline handler: <tr id="part_row" onclick="getPartID(<?php echo $row['part_id'];?>)"> And here is the trivial javascript function that is called: function getPartID(id){ alert(id); } Pretty simple, click a row in the HTML table and get an alert with the record id of the corresponding part in the HTML table row. Progressive enhancement aside, how do I do this exact thing with "Modern Javascript"? If I missed something in the book that explains this, point me to the page number so I can digest it that way. If it is not explained (or something similar), could someone explain how this is done. Solving this trivial example will go a long way in me wrapping my brain around this new way of using javascript. Thanks.
  22. Yes, that would describe the environment pretty well. I am learning some good stuff, but have learned to filter some bad coding practices that are used out of shear arrogance. I am as surprised as you about the nonchalant attitude toward security. It is quite baffling really. I am going to continue to do my job as best as I possibly can and hope I opened some eyes in the programming war room.
  23. I have seen various security test suites available on line to test your sites security, but I have not tried any of them. I recently had a very interesting experience at my programming job. A "junior programmer" I guess would describe where I fit into the food chain at work. I mainly write MySQL data mining scripts and HTML/PHP scripts to display various business metrics reports for upper management. One week from rolling out this project that has taken 6 months to complete, I was asked to spend all my time searching for bugs in this web application. The first thing I did was test if the public pages were protected against SQL injection and XSS attacks. The XSS attack I launched disabled the application entirely. I could drop tables with a single line of code with my SQL injection test. The public log in page could be circumvented with 5 clicks of the mouse button and I could get in as "administrator" and delete clients, add bogus data, type in offensive garbage etc. If I did log in as a "legal" member, I could simply go to the address bar and change the user_id in the query string and suddenly be in someone else's account to do all the damage I wanted to do. The development team didn't mean for me to test security, they were looking for hidden bugs and UI issues in general. I do believe that the senior programmers were so focused on the guts of the web application and the looming roll out date that some very, very basic security issues were..well..overlooked? Test it yourself first. I would advise using the techniques in Larry's "PHP and MySQL for Dynamic Web Sites" for a start and google for more info on various attacks. That is what the hackers are doing..lol. Also, if you know a programmer you can trust, let them work with you and let them try to hack your site..before a major roll out. By the way, I learned all this from Larry's book. Whenever I would thumb though the book at work for a various technique, I could see the senior programmers rolling their eyes. Guess who is rolling their eyes now? The book saved some launch day embarrassment for the development team and made me look like a freakin' genius. Never underestimate a noob! Thanks Larry!
  24. Back to the original post, I found myself asking the same questions. The only experience I had was from the examples in Larry's books. What I did was built my own site on a local host server. I kept adding more complex functionality as I learned more. I ended up with a very robust site that was, and still is today, my "sandbox" for learning and adding new features that use different technolgies like ajax for example. The site is a members only ecommerce site for TV repair people to sell each other excess part inventory. The membership grows daily. I then used that site as my only "portfolio" site and approached some local artists about selling their stuff online. I had a taker that paid me good to build a basic ecommerce site with some basic content management functionality. He is happier with it than I am and that is all that matters I guess. What I mean is..it is easy to waste time adding bells and whistles the client didn't order, stay on track. I then answered an ad in my local area looking for a full time web developer. I sent a scant resume, got an interview and was hired at the interview. I now work full time in a team of three building a corporate extranet/intranet that is giving me an amazing amount of additional experience to apply to my freelance projects. Now it is easier for me to go into a project and answer all the questions that you posed based on my own experience, my own motivation and the learned discipline of staying on track with a project. All of this required me to step way, way out of my "introverted" comfort zone. At 53 years old, it all seemed impossible, but looking back over the last year at what it took to get to this point the main thing was putting myself "out there"...in the real world, not on-line. At the same time, all experience adds up to additional knowledge which is a confidence booster and money maker. Yeah, I am in it for the money.
  25. Ah, thanks Jonathon. I got a syntax error with that. I entered a slight variation of your suggestion and this is what worked: C:\xampp\yii-1-1-13\framework>php yiic.php webapp C:\xampp\htdocs\testdrive I had to preface yiic.php with "php". Thanks for your fast response, it is greatly appreciated! It answered the question very clearly.
×
×
  • Create New...