Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Content Count

    1084
  • Joined

  • Last visited

  • Days Won

    126

Antonio Conte last won the day on August 26 2016

Antonio Conte had the most liked content!

Community Reputation

426 Excellent

About Antonio Conte

  • Rank
    Advanced Member
  1. Antonio Conte

    My Project Diary

    Glad you are improving Edward. Making things work is always the most important point. Refactoring can happen later and bit by bit.
  2. Soap was very nice some time ago, but most web services are luckily going RESTful these days. I suggest you look into building a rest Api rather than work with Soap.
  3. This error occurs when you try to call a method on something that is not an object. In this case, the variable that should hold an object is actually a boolean. Make sure you actually create an object. An example can be the MySQLi functions.If you look at MySQLi::query(), the function returns either false (on error) or an object of the type mysql_result. A bad SQL query will make the query fail and the function to return false. The next call to $result->fetch_all(); would therefor return the error above. In you case, the error occurs when you try to call setFetchMode. It probably means your PDO query failed. Try something like this to reveal the error: $query = "..."; // Your current query $sth = $dbh->prepare($query); $sth->execute(); // Get error array $errors = $sth->errorInfo(); print_r($errors);
  4. Antonio Conte

    Closures

    Just like an array is traversable a closure is callable. The traversable part is why you can foreach an array, as foreach expects something implementing Traversable. You can actually implement Traversable directly on any object and foreach it directly. The same principle applies to anonymous functions. It's just another type of structure PHP provides you with. Functions in PHP normally provides you encapsulation and execution of a set of logic. A closure is a reference to a function's definition, and behaves more like objects in PHP. When you have a closure, you can do stuff to it, just like you would an object. // A reference to a callable function $callable = function($text) { echo $text; }; // Perform an operation with a callable $callable("I'm running now, guys!"); // Output happens here call_user_func() and usort() are some of the functions that expects a callable. usort is probably the easiest to get. // Define a normaly compare function function compare($a, $ { if ($a == $ { return 0; } return ($a < $ ? -1 : 1; } // Use the function normally var_dump(compare(1, 1)); // Returns 0, they are equal // Define an array to sort $values = array(3, 1, 2); // Sort the array using the "compare" function. This probably used call_user_func() // behind the scene to get a callable. usort($values, "compare"); // So, let's do that directly instead usort($values, function ($a, $ { if ($a == $ { return 0; } return ($a < $ ? -1 : 1; }); Hope that helps.
  5. I can really recommend PuPHPet. It takes most of the work out of server configuration.
  6. Antonio Conte

    What Language Should I Learn?

    To add to that, .NET just went open source and is available for UNIX systems. That happend very recently. My advance is to look at Jobs in your community. Also, keep in mind that programming pilars such as algorithms and data structures is appliable to any language. Learn that. Also, learn HTTP if you want to work with the web.
  7. Antonio Conte

    Rest Authentication

    What are your needs here? If this is a read-only (only GET-operations) API, you don't need strict authentication or might not need it at all. Tokens can be used to make sure only those with a valid key can fetch data, you can throttle their calls and build statistics. You could also consider leaving it out completly. If the API is read only, a simple token emailed to users are enough. You can add this token to a GET param or insert into a header in your calls. 1. Seems like a good idea. That way you can also retract tokens. 2. Probably. How important is security? The tokens generated should take this into account. 3. You should require users to pass the token upon every request. As you said, there's no state here. 4. Sounds reasonable.
  8. Antonio Conte

    Organization For Rest

    It's quite normal to build the REST api alongside your site. It seems api.domain.com or domain.com/api/ are pretty normalt structures. While that is the most common, I myself prefer the sort of structure Rails use. This has the added benefit of allowing you to build everything once only. I don't know how easy this is to do with YII, but that's how I build in Symfony. Looking quickly at YII, the same should be possible there. Some of the reason why this is so easy are some incredible bundles like the FOSRestBundle and JMSSerilizerBundle. By defining core configuration for you app, you're controllers can be configured by annotations only. Here's an example of that incredible power: /** * Class MatchController * @package JCN\Bundle\ApiBundle\Controller * * @Route("/match", name="api-match") */ class MatchController extends FOSRestController { ... /** * @Route("/next", name="api-match-next") * @View(templateVar="match") * @Template */ public function nextAction() { $em = $this->getDoctrine()->getManager(); $next = array_pop($em->getRepository('JCNApiBundle:Fixture')->nextMatch()); return array("match" => $next); } ... } Try the following Curl calls in the command line: curl -i -H "Accept: application/json" http://jcn.juvenorge.com/api/match/next curl -i -H "Accept: application/html" http://jcn.juvenorge.com/api/match/next xmllint --format | curl -i -H "Accept: application/xml" http://jcn.juvenorge.com/api/match/next To explain some of the magic here, those annotations gets parsed. When that is done, real objects are created behind the. scene, and does all the magic of handling format parsing, view rendering and routing. I can't really explain how much I love Symfony. Edit: I want to add that this structure is not without it's drawback. If you publish your API and want other people using it, this kind of structure is terrible. Then it's more maintanable to offer api.domain.com/v1/action so BC are not broken every time you change something. This API will be for internal use in my own application.
  9. The biggest issue I had was understanding "the flow" of git. If you have get an error, you are doing something wrong. Some typical error cases: 1. You try a git pull origin master (or similar) and get an error. Your local branch is probably not clean. Do a "git status". If you have any changes, do one of two things. - If you don't care about saving your changes, you can do something like "git checkout .". That will remove any changes to tracked files. (git checkout file/to/checkout will remove single files) If you've added files using 'git add file/to/add", you can unstage them by doing "git reset file/to/unstage" or all by git reset .". Once the files are unstaged, do a "git checkout ." again. You should now be able to pull. 2. You can't perform a git push origin master. (or similar) - You are probably behing the remote. Commit you changes first, do a git pull origin master, then a git pull push origin master. One of the things that took me a while to understand that comitting and pushing doesn't need to happen right after another. You can always commit changes, but you might not be able to push them to another users commits. When you pull a branch like in the second example, you might get something called a merge conflict. You'll see those as "both added" when doing a git status. Open the file and look at the git merge conflict code. You'll see code like this: <<<<<<< HEAD nine ten ======= eight twelve >>>>>>> branch-a If you want to keep 'nine', remove everything but 'nine'. If you want to keep nine and twelve, remove everything but those lines. Conflicts might look a lot more complicated than this, but the same principle applies. Git has become a trusted friend during the last eight months, and I'm really loving it. It is hard to understand and even harder to master, though. When you get the basics, it works like a dream. I had lots of git problems in the start, but they are all gone now. Good luck, Jonathon. Git is really worth learning.
  10. Apply some debugging. If you look at your source code, you'll see that the data you try to echo to var date is not correct. Creating JSON out of $_POST will never get you a date. You are looking for a date on the form "YYYY-MM-DD". To get that, you'll need something more like this: var date = "<?php echo $_POST['date_looking']; ?>"; Some tips. Check you source HTML code and use the Firefox/Chrome debug console to catch any errors.
  11. Antonio Conte

    Digital Ocean

    We use Git Flow on our projects. We also use post-receive hooks and deploy the same way as Larry does. The big difference is that the master branch only have published released, and is thus always stable. We branch out of develop using feature-branches, and merge with develop, perform staging and then goes live when our customers accept new functionality. The stage-enviroment is therefor based on develop, not master. This means we can very easily rollback to a working version if anything stops working and master is always stable. The actual development is performed on our development server that's not visable for the customers. Additional benefits of using git bare-repos is that can perform additional actions. We must likely need to purge cache, restart varnish and similar. All these steps can be done inside the post-receive script.
  12. Antonio Conte

    Yii Elasticsearch

    Yeah, I've both used and installed Solr at work the last few months. It's pretty amazing. Happy holliday to you, Edward.
  13. Perform a new query. Query for the new info you need and limit the result to a single result.
  14. Because IE is shit... On the more serious side, that sounds more like an header issue. I know IE can be a bit weird about headers, so that is nothing new. I experienced the same kind of problem you got a couple of weeks ago. You can find some info here: http://stackoverflow.com/questions/1218925/php-script-to-download-file-not-working-in-ie If that doesn't work, keep searching Stack Overflow. I used the google term "pdf download php internet explorer". Good luck and merry Christmas to you guys.
  15. Possibly an PHP error/warning? Try setting PHP error_reporting to off and set display_errors to false.
×