Buffistechnology 3: "Press Some Buttons, See What Happens."
Got a question about technology? Ask it here. Discussion of hardware, software, TiVos, multi-region DVDs, Windows, Macs, LINUX, hand-helds, iPods, anything tech related. Better than any helpdesk!
Okay. The sample code for an Angular2 based web application with a PHP backend connected to MySQL is going to live here: https://gitlab.com/welarson/noter
I'm still just setting up the project. As I have time, I'll copy over and adapt code from my main project which resides in a private repo. First will come the backend, then will come the frontend.
Pushed some code to the PHP backend. You can see the basic structure of the REST API now even though most of it isn't implemented.
If you want to start playing with it, you'll need to take a few steps. In the noter/back directory you'll need to run:
composer install
That will download the PHP libraries you need. You'll also need to set up MySQL (or another database) with a schema and user and edit the 'propel.yml' file to those settings. Don't worry about creating tables or anything, that will be done for you.
Once 'propel.yml' is configured, then run the following commands in the noter/back directory to set up your database and generate the model classes.
vendor/bin/propel sql:build
vendor/bin/propel sql:insert
vendor/bin/propel model:build
Then you need to create the PHP configuration that the application loads in the bootstrap.php file. That is just another propel command.
vendor/bin/propel config:convert
You'll also need to make sure that Apache is configured to point to the noter/back/public directory and that the mcrypt PHP module is installed and enabled.
The Postman Chrome extension is really handy for test REST APIs. I'd recommend getting it.
I haven't run this code at all, so there are probably problems. I'll be adding more when I get a chance. Once I put in authentication, I'll make sure to run it to work out bugs and configuration issues.
Ooh! Exciting! Thanks, Gud. It'll probably be a week before I get to start to dig into it, but I'm super amped.
Made a couple of little corrections and ran the code so it should actually work now. Also, I added an example apache configuration file under noter/back/apache. It's an apache 2.4 config, so it will need a little tweaking for older versions. On linux anyhow, installing the config is just a matter of copying it to /etc/apache2/sites-available and then creating a link to the config in /etc/apache2/sites-enabled and then restarting apache.
I'm using api.noter.local for the server name and added it to my hosts file.
Here's a reference screen shot of an example request in Postman for registering a user.
[link]
Cool cool. I'm home from my trip now, so I'm going to clean up the detritus that is my life as far as all the stuff that got left undone while I was gone, and then I'm going to sit down with it. Yay!
I threw in a bunch of code real quick and probably broke all the things. It's the stuff to do authentication.
Pfft. It wasn't all that broken. That adds support for registration and login. Logout will come later, I haven't implemented that yet for my wife's study, but all it will do is just delete the current session from the session table.
The cool thing is that the middleware layer in the Cerberus library (which I wrote real quick since I didn't like the library I found) will just take care of authenticating for the rest of the API and you don't have to worry about it. Another application-specific middleware layer will deal with updating the expiration time on the access token and the session so you don't need to deal with that either once it's in place.
One quick tip that can be confusing.
The $request and $response objects that you deal with in all the request controllers are immutable. So when you set something on them, you need to use the returned value. For example:
$response->withHeader('Content-type', 'application/json');
$value = $response->getHeader('Content-type');
Will result in $value being null.
You need to do this instead.
$response = $response->withHeader('Content-type', 'application/json');
$value = $response->getHeader('Content-type');
Which results in $value being 'application/json'
Another tip. To wipe out your database you can just run the command:
vendor/bin/propel sql:insert
from the noter/back directory. Which is handy since there is nothing that cleans out sessions yet.
I pushed a bit more code. There's now support for basic CRUD operations through the REST api with authentication. I also added a setup.sh script to do all the stuff needed to get dependencies and generate the database support. There's also some sample data in a couple of csv files and a python script for turning that into SQL.
./csv2sql.py -u user@email.com -c categories.csv -n notes.csv > file.sql
There's a pre-generated SQL file there that will work just fine, but it expects a registered user with the email: gunnar@dog.com
Anyone want a bargain smartphone with no contract?
$20 + free shipping, free minimal data talk and text.
[link]
My new phone is here! And it only took me four tries to enter the internet password correctly, even though I was staring right at it the whole time!