Getting Started with Quanta
Ready to start using Quanta for your projects? Excellent choice! This guide will walk you through everything you need to know, from setting up your environment to creating advanced features. Whether you’re a beginner exploring the basics or an experienced developer seeking advanced tips, this guide is here to help.
1. Installing Quanta
Quanta is best installed via Composer. Run the following command in your terminal to add Quanta to your project dependencies:
composer require andy16823/quanta
Once installed, initialize Quanta by including the autoloader and creating an instance:
require 'vendor/autoload.php';
use Quanta\Quanta;
use Quanta\Core\Component;
$quanta = new Quanta();
2. Configuring Your Host
To use Quanta effectively, ensure your host is configured for clean URLs. Set up URL rewriting to direct all requests to the file where Quanta is initialized. This allows your application to handle routes seamlessly.
3. Creating Your First Component
Components are the building blocks of your application. Here’s how to create a basic component that loads and renders an HTML template:
class LearnComponent extends Component {
public function render($quanta, $data) {
$template = $quanta->loadTemplate("templates/learn.php");
return $template;
}
}
$quanta->componentHandler->addComponent(new LearnComponent("learn"));
4. Defining Routes
Routes map URLs to specific components. Quanta provides predefined route classes, but you can also create custom
route logic. Here’s an example of using the CleanRoute
class to define a route:
$quanta->routeHandler->addRoute(new CleanRoute("home", ["/", "/home", "/home/"], "home"));
In this example, the CleanRoute
maps the URLs /
, /home
, and
/home/
to the "home" component.
5. Outputting Routes
To process and display routes within your application, use the following code in the relevant section of your layout:
$quanta->processRouting();
Next Steps
Now that you’ve set up your first component and route, you’re ready to explore Quanta’s advanced features. Dive into the documentation to learn about templating, middleware, and more!