Jump to content
Larry Ullman's Book Forums

rob

Members
  • Posts

    143
  • Joined

  • Last visited

  • Days Won

    16

Posts posted by rob

  1. For select (drop-down list) you can preset a selection using "selected":



    <select name="colours">
      <option value="blue" selected>blue</option>
    </select>


    For radio buttons you can preset a value using "checked":



    <input type="radio" name="status" value="on" checked>On


    So you need to compare the value you have stored, against the value of each option and then include selected or checked in the html for that element.

  2. The first thing you need to do is place the instantiation of the SoapClient object within a try catch block. This will help you problem solve the issue you’re having with your script.

     

    There is a lot of information online about writing services using PHP. I have no idea where you are in terms of you level of PHP knowledge/learning and I could be doing you a huge disservice by stating get good at searching for information/tutorials online.

     

    I had a quick search on google and I got a huge number of useful resources for tutorials; sitepoint seems to have a pretty good 2 part series: creating web services using SOAP and PHP.

     

    However, services using SOAP kind of went out of favour back in the day and most developers use REST these days.

     

    Personally, I think it’s always good to work through Larry’s books, but after you’ve finished with SOAP I would recommend having a look at creating REST APIs using PHP. There is a tonne of information online.

  3. One of the concerns for me was how could you ensure the stability of your DB. I did like that in XAMPP you could turn it on or off so it didn't use a load of resources. If I destroyed the vagrant environment, I would lose the data, tables and everything in there. 

     

    Yeah, this was tedious when I first started using vagrant, until I found that you could suspend a guest machine:
     
     
    vagrant global-status is also really handy to manage/see all the guest machines.
     
  4. Every coder should be striving to write the most legible code they can, for both themselves and others. Ask yourself how easily and quickly could you read and understand what the code does if you came back to it in 6 months. My view is, always use curly braces.

     

    Also, understand that projects often have their own code style rules. I have my own preferences but I’ve found myself having to write code differently because I wanted to contribute to certain open-source projects.

     

    I’d recommend having a look at PSR http://www.php-fig.org/psr/psr-1/

     

     

    “Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.”

    — Martin Golding

  5. I'm having trouble understanding/linking the code example to the diagram and definition for the Factory Pattern.
     

    21bsq35.png

    abstract class Shape { ... }
    class Rectangle extends Shape { ... }
    class Triangle extends Shape { ... }
    
    
    abstract class ShapeFactory {
    
    
        static function Create($type, array $sizes) {
    
    
            switch ($type) {
                case 'rectangle':
                    return new Rectangle($sizes[0], $sizes[1]);
                    break;
                case 'triangle':
                    return new Triangle($sizes[0], $sizes[1], $sizes[2]);
                    break;
            }
        }
    }
    
    
    $obj = ShapeFactory::Create($_GET['shape'], $_GET['dimensions']);

    Must be having an off day because I'm not seeing how the abstract factory class is being extended in the code example.

     

    I was unable to find any information in the book explaining the solid arrows or the term concrete, can anyone point me to the right pages, I must be going blind :/

     

    Any help greatly appreciated.

     

     

    edit: ok I think I understand why there was confusion. The UML diagram used in the book is representative of the second reason/example given for using the factory pattern (where a base factory class is extended) but the code example references the first reason given for using a factory class and there is no UML diagram for this. 

  6. The id you want to store in the db is not being submitted with your form. You need to include a hidden form field within your form, with the id value:

     



    <form ... >

    <input type="hidden" name="id" value="<? echo $id; ?>">

    </form>


     


    You'll then need to assign the $_POST['id'] value to $id within your if ($_SERVER['REQUEST_METHOD'] == 'POST') { ... } conditional and before the db insert query.

     



    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
      $id = $_POST['id'];
      # db query
    }


     


    Plus, what margaux said ;)

  7. You need to set the default timezone, the error message explains what you need to do:

     

    An error occurred in script 'D:\xampp\htdocs\includes\form_functions.inc.php' on line 64:

    date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '5.5/no DST' instead

    • Upvote 1
  8. This is really basic HTML CSS, wildman. If you're not comfortable with it I would recommend you pick up a good book or follow an online tutorial to learn the basics.

     

    As for your question, one div element should go around <a href="... > <img src="... > </a>, but you're not even doing inline css styling correctly:

     

    <div style="width: 33%; float: left;">
    

  9. Yeah, the removal of latest topics/comments on the main forum page for non-logged-in members or visitors now forces users to sign up and log in to get that functionality.

    Personally, I don't want to have to log in unless I'm actually starting a topic or posting a comment; I doubt I'm unique in this.

×
×
  • Create New...