PHP for Xojo Programmers - 0001 - Hello World
Reposted from INN: https://ifnotnil.com/t/php-for-xojo-programmers-0001-hello-world/1726
This is the first post in a series about PHP from a Xojo perspective.
I'll be showing how I developed different parts in detail of Xanadu which is open source: https://github.com/campsoftware/xanadu
When I first used Xojo I did the same thing you probably did. I dragged out a button and when clicked it showed a message box that just said 'Hello World'.
Think about what Xojo might be doing to make this work.
- Define the page, even if blank
- Define and place a button
- Add a button onclick event that shows a dialog 'Hello World'.
Hello World - Without PHP
Define the page
That's it. We now have a blank page. The html and body tags are all you need at first. The files should be saved with an html extension like index.html or index.htm.
Define and place a button
<html><body> <button type="button">Hello</button> </body></html>
Buttons are just another tag, but have attributes or properties. Note [type="button"] and a button label [Hello]
Add a button onclick event that shows a dialog 'Hello World'
<html><body> <button type="button" onclick="alert('Hello World!');">Hello</button> </body></html>
Hello World - With PHP
<?php // This is a comment ?> <html><body> <button type="button" onclick="alert('Hello World!');">Hello</button> </body></html>
Now we have a PHP tag with a comment, but it doesn't do anything yet. The file extension should be changed to php like index.php.
Add a Variable
<?php $message = 'Hello World'; ?> <html><body> <button type="button" onclick="alert('<?= $message ?>');">Hello</button> </body></html>
<?php echo $message; ?>
<?php $buttonLabel = 'Hello'; $buttonJS = "alert('Hello World!');"; ?> <html><body> <button type="button" onclick="<?= $buttonJS ?>"><?= $buttonLabel ?></button> </body></html>
Ask questions below. Some questions might end up being answered in another post. :)
CampSoftware Blog: https://campsoftware.com/blog/
Xanadu Info: https://campsoftware.com/products/xanadu.php
Xanadu Download: https://github.com/campsoftware/xanadu