Code Monkey home page Code Monkey logo

silexcms's Introduction

SilexCMS

About

This project aims to provide a minimal toolset helping to create corporate websites. Using Silex as primary framework, it includes multiple shorthand classes.

Version

0.1.0

Examples

We use SilexCMS for our coroporate website. You could see it live at wisembly.com and have a look to github.com/wisembly/wisembly

Documentation

Pages

There is two kind of web pages : statics and dynamics.

Static pages does not rely on anything else than their templates. Dynamic ones take parameters in their urls, fetch a table, then render the specified template, storing the resulting objects in an accessible variable.

Static Page

$app->register(new SilexCMS\Page\StaticPage('/', 'home.html.twig'));

Dynamic Page

$app->register(new SilexCMS\Page\DynamicPage('/product/{slug}', 'product.html.twig'));
{% if app.set not none %}
    Our product is called {{ app.set.name }} :)
{% else %}
    Product not found :(
{% endif %}

DataSets

Datasets are an easy and handy way to retrieve database data directly in your Twig templates. First, register your available DataSets for your application:

$app->register(new DataSet('twig_name', 'table_name'));
$app->register(new DataSet('users', 'user'));

Then, use them in your Twig templates:

{# Tell in your template that you will need users DataSet loaded in app #}
{% bloc users %}{% endbloc %}

{# Then use it freely in your template in app var #}
First user name: {{ app.users[0].name }}

Users emails:
{% for user in app.users %}
  email: {{ user.email }}
{% endfor %}

KeyValueSets

KeyValueSets are an easy and handy way to retrieve from your database key => values sets in your Twig templates. They work like DataSets above, but allows to access values differently in your templates.

$app->register(new DataSet('twig_name', 'table_name', 'key_name'));
$app->register(new DataSet('messages', 'messages', 'key'));

For the following set:

| key | value |
| foo | bar   |
| bar | baz   |

In your template you could then use:

{% bloc messages %}{% endbloc %}

{# will output "bar" #}
foo value is: {{ app.messages.foo }}

Foreign Twig extension

SilexCMS provides a Twig Extension to retrieve easily a particular object by id reference inside a DataSet

First, load Foreign Key Extension

$app['twig']->addExtension(new \SilexCMS\Twig\Extension\ForeignKeyExtension($app));

Then, use it that way in your Twig Templates:

{% block books %}{% endblock %}
{% block categories %}{% endblock %}
{% set category = foreign(app.categories, app.books[0].category_id) %}
The 1rst book category is: {{ category.name }}

Security

The security classes give a very simple way to identifying some users.

When instanciating a Firewall, you will only have to provide a name and an array containing your users authentification infos (where the key will be their usernames and values are plain text passwords). A logger instance will be automagically created in the app[name] variable.

From then, you can use this logger to check current user state or change it.

Manual example

$app->register(new SilexCMS\Security\Firewall('main', array('user' => 'pass')));

var_dump($app['main']->getUsername()); // null
$app['main']->bindUsername('user');
var_dump($app['main']->getUsername()); // "user"

Request example

You can also bind requests if they have at least two parameters : _username and _password.

startup.php
$app->register(new SilexCMS\Security\Firewall('security', array('user' => 'pass')));

$app->register(new SilexCMS\Page\StaticPage('/login', 'login.html.twig'));
$app->register(new SilexCMS\Page\StaticPage('/login/success', 'login/success.html.twig'));
$app->register(new SilexCMS\Page\StaticPage('/login/failure', 'login/failure.html.twig'));

$app->post('/post', function (Application $app, Request $req) {
    $security = $app['security'];

    if ($security->bindSession()->getUserName() || $security->bindRequest($req)->getUserName()) {
        return $app->redirect('login/success');
    } else {
        return $app->redirect('login/failure');
    }
});
login.html.twig
<form action="/login" method="post">
    <input type="text" name="_password" /><br />
    <input type="password" name="_password" /><br />
    <input type="submit" />
</form>

License

SilexCMS is licensed under the MIT license.

silexcms's People

Contributors

guillaumepotier avatar arcanis avatar taluu avatar

Watchers

James Cloos avatar Alexandre Cyro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.