ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
A syntax error means that I/you made a typo/forgot to add something in the code. I'll need to see your code to help you! Don't pardon yourself for newbieness, if you don't understand something just say so and ask to clarify. try { $gateway = new CampusBooksAPI_Gateway('api-key-here'); $bookList = $gateway->search($_GET['query']); echo '<table><tr><th>Title</th><th>Author</th></tr>'; foreach($bookList as $book) { echo '<tr><td>', $book->getTitle(), '</td></tr><tr><td>', $book->getAuthor(), '</td></tr>'; } echo '</table>'; } catch(CampusBooksAPIException $e) { echo $e->getMessage(); } Possible implementation: function search($query) { $bookList = new BookList(); $response = $this->_getResponseXML('search', array('title' => $query, 'author' => $query, 'keyword' => $query)); foreach($response->page->results->book as $book) { $data = array('isbn' => $book->isbn13, 'title' => $book->title, 'author' => $book->author, 'binding' => $book->binding, 'price' => $book->msrp, 'pages' => $book->pages, 'publisher' => $book->publisher, 'published_date' => $book->published_date, 'edition' => $book->edition, 'description' => $book->description); $bookList->add(new Book($data)); } return $bookList; }
-
The class once you have implemented the necessary code would be used like: try { $campusBooksAPI = new CampusBooksGateway('api-key-here'); $books = $campusBooksAPI->getPrices($_GET['ISBN']); foreach($books as $book) echo $book->getAuthor(), "<br>\r\n"; } catch (CampusBooksAPIException $e) { echo $e->getMessage(); } I highly recommend you use domain classes that know of the format (SimpleXMLElement) used by CampusBooksGateway like a BookList class of some sort this will make your program more flexible then if you would use the SimpleXMLElement object directly in your client (not to mention that you would break encapsulation, whatever that's worth to you!
-
The reason I didn't include any code is because I do not know how you will handle/use it or in what way you would like to see it Object, array, ..?
-
Wrap the campusbooks api into a class like so: class CampusBooksAPIException extends Exception {} class CampusBooksGateway { private $apiKey; private $apiVersion = '11'; private $apiURL = 'http://api.campusbooks.com'; private $apiProtocol = 'rest'; function __construct($apiKey, $apiVersion = '11') { $this->apiKey = $apiKey; $this->apiVersion = $apiVersion; } function getPrices($isbn) { $simpleXML = $this->_query('prices', array('key' => $this->apiKey, 'isbn' => $isbn)); } function getBookInfo($isbn) { $simpleXML = $this->_query('bookinfo', array('key' => $this->apiKey, 'isbn' => $isbn)); } function searchByAuthor($author, $page, $imageWidth = 50, $imageHeight = 50) {} function searchByTitle($title, $page, $imageWidth = 50, $imageHeight = 50) {} function searchByKeyword($keyword, $page, $imageWidth = 50, $imageHeight = 50) {} function searchAll($input, $page, $imageWidth = 50, $imageHeight = 50) {} function getBookPrices($isbn) {} function getBuybackPrices($isbn) {} function getMerchantsAll() {} function getMerchantsBuy() {} function getMerchantsBuyback() {} private function _query($method, array $options) { $simpleXML = simplexml_load_file($this->_formatURL($method, $options)); if($simpleXML === false) throw new CampbusBooksAPIException('Campus Books API not available or invalid format.'); if($simpleXML->attributes()->status != 'ok') throw new CampbusBooksAPIException($simpleXML->errors->error); return $simpleXML; } private function _formatURL($method, array $options) { return $this->apiURL.'/'. $this->apiVersion.'/'. $this->apiProtocol.'/'. $method.'?'.http_build_query($options); } } Write the missing code and use this interface to communicate with the API you will have to visit each URL though to look at the response it generates to write the code to handle it.
-
You will have to show us the code from: Z:\www\cms\includes\functions.php
-
string similarity algorithm. any suggestions?
ignace replied to daydreamer's topic in PHP Coding Help
"People who bought this item also bought.." is probably what you are looking for. You also could add tags to each product and find products which have the most similar tags that should be easily doable. -
return $allBooks = $this->getBookList([$title]); You probably are referring to: return $this->getBookList()[$title]; And no you can't do that in PHP neither can you do: (new Object())->method(); Few things I liked about Java.
-
IMO should those links 1) be always visible or 2) visible only when they are on the parent page. Besides as they ain't much content (not sure how much you are going to put in there you may as well keep it all on one page.)
-
You can solve that by using the hash part of the URL. The blip you see is due to you first display: none all and then show it again while it is already being shown. Skip over the one that should be active. PS All your links being dependent on JS is not a good idea, a slight parsing error will take your entire website down.
-
By a pop-out I actually meant something like an Accordion sub-items that only become visible when you clicked the parent although it would be best if they all appeared no matter which element was clicked, the accordion would just show the hierarchy. This will work well IMO especially because you have a low amount of links.
-
They thought it was pointless to add the feature as they already had a design in place.
-
Using MVC for the reason "it doesnt clutter ur code" will turn around and haunt you. You use an approach because it best suits the project and CakePHP and CodeIgniter are PHP4 which "died" a few years ago. Suggested frameworks would be: Symfony, Zend framework, or Kohana but I prefer the former 2.
-
1) I fail to see why you would need 2 classes because this actually should be 1 class. 2) Since you want to support multiple formats (ASX, M3U8, PLS, ..) I would write a class for each. Create a common interface for these classes to implement and declare a function render() in your interface. This class will return what you currently echo() depending on each type. 3) If you tell us more about what you want done we may be able to help you further.
-
Why is it bad to implement someone else's code? You don't have to explicitly state that they are links, people still recognize navigation menu's when they see one. I would only add some style so a user is able to see on which page he is. I would pop-out the sub-menu instead of inline showing/hiding. Nor @ or %40 will protect you from spam.
-
I would remove the jumping on your menu both vertically and horizontally. I would also encode or use a contact form for the Webmaster part otherwise you'll be in for some serious SPAM. I would change your text on the Contact page to: Voor contact met onze chiro kan u <a href="mailto:info@chirotremelo.be">rechtstreeks mailen</a> (opgepast Outlook zal worden gestart). Although it would be more convenient if you added a contact form instead with a reCAPTCHA. Also check the website for typo's should be on your checklist before you put it into production:
-
3 books on Programing Theory, but where to start?
ignace replied to atrum's topic in Application Design
3 followed by 1 and then 2 -
1. The News boxes are too big and your main content looks squished 2. Make it more clear which link you are clicking in your navigation
-
I like it too. It promotes the use of directories as a layering mechanism, it will make people start to think about their design when they are creating their n-th directory, and it eases auto-loading (no complex auto-loading schemes and more and more frameworks are adopting it).
-
You can go much further then your suggestion, something like: foreach($questions as $question) { foreach($question->getPossibleAnswers() as $answer) { echo '<li>', $answer->getLabel(), ' ', $answer->render($question->getUniqueID()), '</li>'; } } But depending on your requirements this design may become more complex.
-
Trying to get property of non-object, simplexml question.
ignace replied to Jerred121's topic in PHP Coding Help
In the case of SimpleXML you would have been able to omit the error's (and future error's) if you used a Proxy or wrapper, like: class SimpleXMLElementWrapper implements ArrayAccess { private $simpleXML; function __construct(SimpleXMLElement $simplexml = null) { $this->simpleXML = $simpleXML; } function __get($offset) { if($this->simpleXML && property_exists($offset, $this->simpleXML)) { $value = $this->simpleXML->$offset; if($value instanceof SimpleXMLElement) { return new self($value); } else { return $value; } } return new self(); } function __call($method, $args) { if($this->simpleXML && method_exists($method, $this->simpleXML)) { return call_user_method_array(array($this->simpleXML, $method), $args); } return array(); } function __toString() { return ''.$this->simpleXML; } } This is a mere example that is not guaranteed to work but shows you how you can omit the nasty exceptions SimpleXML throws for your current and future projects. A usage example would be: $simplexml = new SimpleXMLElementWrapper(new SimpleXMLElement('file.xml')); $simplexml->foo->bar->baz; Although foo bar and baz don't exist it won't throw any exceptions. It should be noted that it's not advised to use this code everytime you use SimpleXMLElement just to omit the problems you can encounter because it makes your code impossible to debug although you could resolve this by passing an extra paramter to SimpleXMLElementWrapper ($throwException) that changes wether or not it shall throw an exception when it can't find an offset. I'm telling you this because for a current project I had to run through an XML that may or may not contain some tags and instead of writing a bunch of isset() statements I wrote a wrapper that returned an empty string instead. -
Trying to get property of non-object, simplexml question.
ignace replied to Jerred121's topic in PHP Coding Help
property_exists -
1. I can't click the login link in your nav because I have JS disabled 2. "Only: A-Za-z0-9" as a description will not suffice, a programmer will create a username that matches that pattern: 'A', 'a', or '0'. A customer will enter "A-Za-z0-9"
-
$hx = bin2hex('a'); is wrong bin2hex() expects a binary string not a hex one however hex2bin() doesn't exist quite possibly because it's easy to create: A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1111 echo base_convert($hx, 16, 2); makes no sense converting from base16 to base16
-
Code execution at destruction of session variable.
ignace replied to habib009pk's topic in PHP Coding Help
http://php.net/manual/en/function.session-set-save-handler.php -
AmberSoft Media - Quality Puzzles for Print Publications
ignace replied to charles724's topic in Website Critique
Indicate in your links if it points to a PDF like: Home | About Us | Sample (PDF, .. MB) | Order Puzzles | Account | Free Weekly Puzzle (PDF, .. MB) | Contact Us I find it really annoying if I click a link and something unexpectedly happens especially firing up the PDF plugin within my browser. I like the idea, have you thought about how you will bring it to market?