hramenko / php-vanilla-htmx

Example of using HTMX with PHP without any framework or dependency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP no framework HTMX example

This is a simple example of using HTMX with PHP and no framework. It uses the HTMX library to make AJAX requests and update the page with HTML over the wire. It has some basic error handling and exception handling. We can also parse the HX-request header and render content without template. See register_shutdown_function(). In the /about page I also included an example of how one can work with a SQLite database.

I'm also using TailwindCSS, download the CLI (it is not checked in here), place it in /project and run it in watch mode with this command:

./tailwind -i ./app/source.css -o ./public/css/style.css --watch

I'm running this locally on my mac by using https://www.mamp.info/en/mamp/mac/ with a nginx controller that is routing like so:

	server {
		listen 8999;
		server_name simple.local;

		root  "/Applications/MAMP/htdocs/project";

		location / {
			try_files $uri /app/index.php?$query_string;
		}

		location ~ ^/(public/)?.*\.(css|js)$ {
			try_files $uri =404;
			autoindex on;
		}

		location ~ \.php$ {
			try_files        $uri =404;
			fastcgi_pass     unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI.sock;
			fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include          fastcgi_params;
		}

		location ~ /\. {
			deny all;
		}
	}

Apache/httpd or other web servers should also work. Have fun!

About

Example of using HTMX with PHP without any framework or dependency


Languages

Language:PHP 90.5%Language:JavaScript 4.8%Language:Hack 2.8%Language:CSS 1.9%