Skip to content

JeanGoncalves/Piano

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installing

composer require piano/mvc

Creating a basic project structure

composer create-project piano/mvc project-name dev-project

Controller

Redirecting

$this->redirect('/module/controller/action');

Redirecting with variables

$this->redirect(
    '/module/controller/action',
    [
        'firstName' => 'Diogo',
        'lastName' => 'Cavilha',
    ]
);

Getting params by name

$id = $this->getParam('id');

Getting all params

$params = $this->getParams();

Methods:

initialize()

If you need to create a constructor method for your controller, you can do this by creating a method called initialize() instead of __construct(). The __construct() method is already being used by Piano\Mvc\Controller.

<?php

namespace app\modules\application\controllers;

class IndexController extends Piano\Mvc\Controller
{
    protected function initialize()
    {
        // Do some action before executing any other code of your controller.
    }
}

View

Rendering a view

$this->view->render('view-name');

Rendering a view with variables

$this->view->render('view-name', ['name' => 'Diogo']);

Disabling/Enabling the layout

$this->view->disableLayout(); // disabling
$this->view->disableLayout(true); // disabling
$this->view->disableLayout(false); // enabling

Adding a partial

$this->partial('/path/to/file');

Adding a partial with variables

$this->partial('/path/to/file', ['title' => '']);

writing href links

<a href="<?php echo $this->url('route_name'); ?>">Text</a>

Form action must be written with a pre-defined route

<form action="<?php echo $this->url('contact'); ?>" method="post">
    Name: <input type="text" name="name">
    Email: <input type="text" name="email">
    <input type="submit" name="Send">
</form>

Application

Getting module name

$this->getApplication()->getModuleName();

Getting controller name

$this->getApplication()->getControllerName();

Getting action name

$this->getApplication()->getActionName();

About

A very simple MVC and routing application.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%