Download the PHP package piano/mvc without Composer
On this page you can find all versions of the php package piano/mvc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mvc
Piano MVC
This is not a micro/mini/whatever framework nor claims to be.
It's only a very simple MVC structure.
WARNING: This has been just like a lab. I don't update this project anymore. If you want to use it, the ball is on your court.
Creating the project structure
Controller
Redirecting
Redirecting with variables
Getting params by name
Getting all params
Methods from Piano\Mvc\Controller
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
.
Example:
View
Rendering a view
Rendering a view with variables
So, in the view code you can access the variable:
Disabling/Enabling the layout
Adding a partial
Adding a partial with variables
Loading CSS files
You can load CSS files on demand. It means you can define what CSS files are gonna be loaded when some specific view is rendered. Better than that, you can do this for each of your views.
You can use the addCss()
method.
Or you may want to use the setCss()
method.
PS: You must call
addCss()
orsetCss()
method before calling therender()
method. Otherwise it won't work.
Loading javascript files
You can load javascript files on demand. It means you can define what javascript files are gonna be loaded when some specific view is rendered. Better than that, you can do this for each of your views.
You can use the addJs()
method.
Or you may want to use the setJs()
method.
PS: You must call
addJs()
orsetJs()
method before calling therender()
method. Otherwise it won't work.
In order to load these CSS or JS files in your view/layout you can call the loadCss()
or loadJs()
method.
href links
Form action must be written by using a pre-defined route
Model
The DataAccessAbstract class.
The Piano\Mvc\DataAccessAbstract
abstract class provides us a few methods for handling data by accessing the database.
Attributes from Piano\Mvc\DataAccessAbstract
Table name for working.
If not null, it's used for fetching its model. Otherwise, it will use an associative array.
A PHP PDO instance.
Methods from Piano\Mvc\DataAccessAbstract
Create a record into database.
Parameters
data
Array data to insert into the database table.
dataBind
The bound values.
Return Values
Returns the last insert id on success or FALSE on failure.
Change a database record.
Parameters
data
Array data to insert into the database table.
where
Where clause.
dataBind
The bound values.
Return Values
Returns TRUE on success or FALSE on failure.
Delete a record from database.
Parameters
where
Where clause.
dataBind
The bound values.
Return Values
Returns TRUE on success or FALSE on failure.
Perform a query in order to return all database records.
Parameters
configData
The query configuration.
Example:
order
Like SQL ORDER.
Example:
count
Integer value used to make the query return a specific set of rows.
offset
Integer value used to make the query return a specific set of rows.
PS: When both count and offset are used, the query to be executed has LIMIT offset, count
Return Values
- When fetchClass parameter is true or omitted, it returns an array of model objects.
- When fetchClass parameter is false, it returns an associative array.
Perform a query in order to return all database records.
Parameters
configData
The query configuration.
Example:
order
Like SQL ORDER.
Example:
Return Values
- When fetchClass parameter is true or omitted, it returns a model object.
- When fetchClass parameter is false, it returns an associative array.
Examples:
insert()
update()
delete()
getAll()
getFirst()
Application
Getting module name
Getting controller name
Getting action name
Class Piano\Config\Ini
The Piano\Config\Ini
is a ini file parser. You must pass the ini path as an argument to its constructor.
Sample
Class Piano\Config\Pdo
The Piano\Config\Pdo
provide us an easier way to configure a \Pdo
connection. You must pass an config array as an argument to its constructor.
Sample
Class Piano\Router
The Piano\Router
is a route parser. It helps you to define the application's routes.
Sample
You're able to define all routes as an array or by using the Piano\Router
object notation.
Defining routes as array.
Defining routes as object.
You can also enable/disable SEF. (It's useful to disable it when developing)
It can be done by calling the method enableSearchEngineFriendly
If you want to get all routes or a particular one, you could do like this: