Angel's lame. His hair goes straight up, and he's bloody stupid!

Buffybot ,'Dirty Girls'


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!


Gudanov - Feb 24, 2016 4:50:02 am PST #24776 of 25496
Coding and Sleeping

Still not regretting my switch to Ubuntu.


Liese S. - Feb 24, 2016 10:39:20 pm PST #24777 of 25496
"Faded like the lilac, he thought."

No worries, Gud. I'm not anywhere close myself. I am at an event this week with my songwriting prof and bunch of writers, so I'm going to try to do some requirements gathering, though.


omnis_audis - Mar 04, 2016 3:16:15 pm PST #24778 of 25496
omnis, pursue. That's an order from a shy woman who can use M-16. - Shir

On my work browser (Firefox 44.0.2), while cruising the Amazon website, anytime I open a product (versus seeing search results), I get a script error that says:

Warning: Unresponsive Script
A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.

It then gives a "script: [web address of product]

I click the "stop script" and "don't ask me again", but since each product is a different script, it always pops up. I wrote to Amazon, and their response was

I'd suggest clicking the "Help" link at the top of your window (above the browser commands) for browser-specific troubleshooting tips. If that doesn't solve the issue, you may need to contact your Internet service provider directly.

But the help menu had nothing about unresponsive scripts that I could find.

Is anyone else having this issue? Does anyone know a solution?

TIA.


Gudanov - Mar 05, 2016 6:28:37 am PST #24779 of 25496
Coding and Sleeping

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.


Gudanov - Mar 05, 2016 5:32:19 pm PST #24780 of 25496
Coding and Sleeping

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.


Liese S. - Mar 06, 2016 7:13:54 am PST #24781 of 25496
"Faded like the lilac, he thought."

Ooh! Exciting! Thanks, Gud. It'll probably be a week before I get to start to dig into it, but I'm super amped.


Gudanov - Mar 08, 2016 6:17:24 pm PST #24782 of 25496
Coding and Sleeping

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]


Liese S. - Mar 09, 2016 8:02:30 am PST #24783 of 25496
"Faded like the lilac, he thought."

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!


Gudanov - Mar 09, 2016 5:23:12 pm PST #24784 of 25496
Coding and Sleeping

I threw in a bunch of code real quick and probably broke all the things. It's the stuff to do authentication.


Gudanov - Mar 09, 2016 5:56:54 pm PST #24785 of 25496
Coding and Sleeping

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.