File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /vendor /
2+ composer.lock
Original file line number Diff line number Diff line change 1+ # Really Simple Gallery Example
2+ This is a really simple example which searches characters and display the thumbnails of the results.
3+
4+ ## Install dependencies
5+ ``` sh
6+ cd examples/gallery
7+ composer install
8+ ```
9+
10+ ## Run PHP web server
11+ ``` sh
12+ php -S localhost:8888 . -t index.php
13+ ```
14+ ## Open the example in browser
15+ [ http://localhost:8888 ] ( http://localhost:8888 )
Original file line number Diff line number Diff line change 1+ {
2+ "require" : {
3+ "chadicus/marvel-api-client" : " ^3.0"
4+ }
5+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ require_once __DIR__ . '/vendor/autoload.php ' ;
4+
5+ use Chadicus \Marvel \Api \Client ;
6+ use Chadicus \Marvel \Api \Entities \ImageVariant ;
7+ use DominionEnterprises \Util \Arrays ;
8+
9+ $ nameStartsWith = Arrays::get ($ _POST , 'nameStartsWith ' );
10+ ?>
11+
12+ <html>
13+ <head>
14+ <style>
15+ label { display: inline-block; width: 140px; text-align: right; }
16+ img { max-width:800px; }
17+ </style>
18+ </head>
19+ <body>
20+ <form method="POST" action="/">
21+ <fieldset>
22+ <legend>Search Characters</legend>
23+ <br />
24+ <label for="nameStartsWith">Name</label>
25+ <input type="text" name="nameStartsWith" size="32" value="<?= $ nameStartsWith?> " />
26+ <br />
27+ <input type="Submit" value="Search" />
28+ </fieldset>
29+ </form>
30+ <?php if ($ _SERVER ['REQUEST_METHOD ' ] === 'POST ' ): ?>
31+ <?php
32+ $ client = new Client (getenv ('PRIVATE_KEY ' ), getenv ('PUBLIC_KEY ' ));
33+ $ dataWrapper = $ client ->search ('characters ' , ['nameStartsWith ' => $ nameStartsWith ]);
34+ $ count = 0 ;
35+ ?>
36+ <h3><?= $ dataWrapper ->getData ()->getTotal ()?> characters found</h3>
37+ <table border="1">
38+ <tbody>
39+ <tr>
40+ <?php foreach ($ dataWrapper ->getData ()->getResults () as $ character ): ?>
41+ <?php if ($ count ++ % 5 === 0 ): ?>
42+ </tr><tr>
43+ <?php endif ; ?>
44+ <td>
45+ <p><?= $ character ->getName ()?> </p>
46+ <a href="<?= $ character ->getUrls ()[0 ]->getUrl ()?> ">
47+ <img src="<?= $ character ->getThumbnail ()->getUrl (ImageVariant::PORTRAIT_XLARGE ())?> " />
48+ </a>
49+ </td>
50+ <?php endforeach ; ?>
51+ </tr>
52+ </tbody>
53+ </table>
54+ <center><?= $ dataWrapper ->getAttributionHTML ()?> </center>
55+ <?php endif ; ?>
56+ </body>
57+ </html>
You can’t perform that action at this time.
0 commit comments