I recently wanted to explore developing for Parse.com using PHP. My webdev skills are quite rusty but it wasn’t too tough. I made some notes and thought I’d share them.
I used MAMP which makes the foundational setup quick and easy. Here’s the steps…
1. Install MAMP – http://www.mamp.info/en/index.html – download, double click, not much more too it (I avoided ‘Pro’ aspects b/c I’m skeered)
2. Download Parse.com PHP Library – https://github.com/apotropaic/parse.com-php-library
3. Create parseConfig.php where the PHP library unpacks – see SETUP at:
https://github.com/apotropaic/parse.com-php-library/blob/master/README.md#setup
– Get values (app id, Master key, REST key) for your app at: https://parse.com/apps/<YOUR APP NAME>/edit#app_keys
(I didn’t have to change the PARSEURL value)
4. Copy PHP library files into MAMP
– create /Applications/MAMP/htdocs/parse
– copy PHP library files into /Applications/MAMP/htdocs/parse (OR rename the unpacked parent dir and move it to …/htdocs)
4b. Turn off Cache
– edit /Applications/MAMP/conf/php5.5.3/php.ini
– comment out the OPcache section
5. Start MAMP app and start servers – use MAMP UI
6. Go to http://localhost:8888/parse/ and select test.php
– This will run all tests, but if you don’t have push setup correct, that will fail.
– Edit test.php to select which tests to run for example…
— uncomment out line 6: include_once ‘tests/parseObjectTest.php’;
— comment out line 12: \Enhance\Core::discoverTests(‘tests/’);
(line 12 causes all tests to run)
7. Check data on Parse.com for ‘test’ objects – https://parse.com/apps/<YOUR APP NAME>/collections#class/test
—
Then I Created Parse.com login/signup test script. At the bottom, it fetches and displays some data from Parse.com as a test.
NOTES: I’m still new to this so I think I’m doing the session wrong – but when I didn’t pass the session id in, it created a new session upon form submission and I lost the values.
<html> <?PHP include_once 'parse.php'; $sessionID = $_POST['PHPSESSID']; echo 'Hello!<br> Session id passed in: ' . $sessionID; if (!empty($sessionID)) { session_id($sessionID); } session_start(); echo '<br>Stored Token: ' . $_SESSION['sessionToken']; echo '<br>SID: ' . session_id(); #$qs = 'Query String: ' . $_SERVER['QUERY_STRING']; $action = $_POST["action"]; if (empty($_SESSION['sessionToken']) && !empty($action) && empty($sessionToken)) { $username = $_POST["username"]; echo '<br>Username: ' . $username; $password = $_POST["password"]; echo '<br>Password: ' . $password; if(!empty($username) && !empty($password)) { $pUser = new parseUser; $pUser->username = $username; $pUser->password = $password; if ($action == "login") { echo '<br>Login call...'; try { $loginResult = $pUser->login(); echo '<br>Login Result: ' . $loginResult->sessionToken; $_SESSION['sessionToken'] = $loginResult->sessionToken; echo '<br>Token: ' . $_SESSION['sessionToken']; } catch (Exception $e) { echo '<br>Login failed.'; } } else if ($action == "signup") { echo '<br>Sign Up call...'; try { $signupResult = $pUser->signup(); echo '<br>Signup Result: ' . $signupResult->sessionToken; } catch (Exception $e) { echo '<br>Signup failed.'; } } } else { echo '<br>Missing username/password'; } } session_write_close(); ?> <body> <form method=POST> <input type="text" name=username> <br> <input type="password" name=password> <br> <input type="submit" value="Login"> <input type="hidden" value="login" name="action"> <input type="hidden" value="<? echo session_id() ?>" name="PHPSESSID"> </form> <form method=POST> <input type="text" name=username> <br> <input type="text" name=email> <br> <input type="password" name=password> <br> <input type="password2" name=password2> <br> <input type="submit" value="Sign Up"> <input type="hidden" value="signup" name="action"> </form> <?PHP $parseQuery = new parseQuery('test'); # $parseQuery->where('testfield1','test1'); $result = $parseQuery->find(); echo "<br><br>RESULT: "; print_r($result->results[0]); ?> </bod> </html>
Here’s a couple example apps I found that I thought might be useful:
Todo List example w/ PHP, MySQL and jQuery:
http://tutorialzine.com/2010/03/ajax-todo-list-jquery-php-mysql-css/
Another: http://www.mytinytodo.net
I’ve since started exploring CodeIgniter and Laravel and hope to post on them soon.
Pingback: CodeIgniter Research | Brainwash Inc.
Pingback: Laravel on MAMP Setup | Brainwash Inc.
Pingback: CodeIgniter Research | Brainwash Inc. | Crazy CoM BD
Comments are closed.