Get support for mnapoli/MniPagesBundle
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
mnapoli/MniPagesBundle
MniPagesBundle
Much awesomeness, very good, coming soon.
What is this?
Typical PHP web frameworks are using controllers and actions:
- a request for a web page leads to an action in a controller
- an AJAX request leads to an action in a controller
- a form post leads to an action in a controller
This pattern is easy to understand, because every request just calls a controller action. But this model doesn't feel natural: even though they all are HTTP requests, at a higher level a web page and an AJAX request are not the same thing.
There is another way: component-based architecture. This pattern introduces the concept of Page, Component and Action.
- a Page returns an HTML web page (wow!)
- a page can be composed of several reusable Components (that returns HTML fragments)
- you can call Actions on pages or components (through an AJAX request or form post)
A small example
Pages
A page is a class:
class HomePage extends Page
{
protected $title = 'Hello!';
protected $pageCountComponent;
public function __construct()
{
$this->pageCountComponent = new PageCountComponent();
}
}
and a template:
{% extends '::layout.html.twig' %}
{% block content %}
<h1>{{ title }}</h1>
{{ component(pageCount) }}
{% endblock %}
Each property of the page is accessible in the template.
Components
A component is a class too:
class PageCountComponent extends Component
{
protected $count;
public function __construct()
{
$this->count = $this->get('session')->get('pageCount', 0);
}
}
and a template:
<p>
Page count: {{ count }}.
</p>
Actions
Let's add an action that resets the page count and refresh the component (not the page!):
<p>
Page count: {{ count }}.
<button type="button" data-component-action="reset" data-component-refresh>Reset</button>
</p>
class PageCountComponent extends Component
{
protected $count;
public function __construct()
{
$this->count = $this->get('session')->get('pageCount', 0);
}
public function reset()
{
$this->count = 0;
$this->get('session')->set('pageCount', 0);
}
}
Easy! The Javascript library already takes care of AJAX requests and refreshing components.
Getting started
Requirements
- jQuery
Installation
- install via composer:
{
"require": {
"mnapoli/pages-bundle": "*"
}
}
- add the bundle to your
AppKernel.php
:
public function registerBundles()
{
return array(
// ...
new Mni\PagesBundle\MniPagesBundle(),
);
}
- import the Javascript files in the layout:
{% javascripts
'@MniPagesBundle/Resources/public/js/*' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
Documentation
Demo
The demo is in the demo/
folder. It's a standard Symfony app, you can get it working easily:
$ cd demo/
$ composer install
$ app/console server:run
License
MniPagesBundle is licensed under the MIT license. See the LICENSE file for more informations.
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2