Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 165 | All time: 8,913 This week: 45 |
Version | License | PHP version | Categories | |||
define-mvc-php-8 1 | GNU General Publi... | 8 | HTTP, Libraries, Design Patterns, PHP 8 |
Description | Author | |
This package provides a framework to route requests via a front controller. |
<?php |
Define MVC is a *Front Controller* based light weight MVC framework for developing web based applications. It is an open source and will remain always.
First release of Define MVC supports PHP 5.3 to PHP 7.2. You can get it from <a href="https://github.com/niteshapte/define-mvc/">*HERE*</a>.
Please feel free to contribute. But try to keep the implementation simple so that a developer working for first time shouldn't find it difficult to understand and use it.
PHP 8.0+
While developing I created a virtual host for this framework. Request you guys to do the same. Probably it will not work if you try to access it like _htt<area>p://localhost/define-mvc-php-8/_.
Add below line in /etc/apache2/apache2.conf
<br>
Include vhost.conf
Create a file vhost.conf
in /etc/apache2/
folder and add below lines -
<pre>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin admin@define.mvc
ServerName define.mvc
ServerAlias www.define.mvc
DocumentRoot /var/www/html/define-mvc-php-8/
<Directory "/var/www/html/define-mvc-php-8">
AllowOverride All
</Directory>
DirectoryIndex bootstrap.php
</VirtualHost> </pre>
Add below line in /etc/hosts
file - <br>
127.0.0.1 www.define.mvc
Run below command on terminal to restart apache - <br>
service apache2 restart
_Please note above configurations were done in my linux machine. You must do according to your setup._
Define MVC is a front controller based MVC framework just like any other MVC framework. So, all the request are redirected to bootstrap.php page. Please have a look at .htaccess
file.
Please don't skip this section. Go through the below folder structure to understand how Define MVC and project / application classes and files will be organized.
define-mvc-php-8
| - README.md
| - bootstrap.php // Front controller file. All request are redirected to this file. Redirect configuration is in .htaccess
| - .htaccess
???? application // project / application files
| ???? controller // controller files
| ???? dto // DTOs related to project
| ???? exceptions // Exceptions related to projects.
| ???? i18n // Internationalization / Localization
| ???? repository // DAO classes of project
| ???? service // Service classes of project
| ???? view // view / html / html + php files
???? configuration
| - application.php // configuration for project
| - define.php // configuration for framework
???? docs // contains configuration files for both application and framework
???? lib
| ???? define // DEFINE MVC files
| | ???? core // Framework's core classes
| | ???? dbdrivers // Database Driver classes
| | ???? exceptions // Exceptions for framework
| | ???? traits // Traits for frameork
| | ???? utilities // Utility classes for framework
| ???? vendors // vendor libraries
| ???? phpmailer
| ???? json-object-mapper
| ???? etc.
???? logs // logs generated by logger
???? scripts (optional) // Scripts like DB scripts or shell scripts
???? db
???? shell
All the files related to your project will be inside 'application' folder. However, you can change the configurations defined in configuration/define.php
.
By default, Define MVC follow below URL pattern:
_http<area>://www<area>.domain.com/controller/action/param1-param2/_
For example, if the URL is htt<area>p://www<area>.example.com/user/profile/33-90/, or you want to create this url, then craete UserController
class in application/controller
with below code.
<pre> class UserController extends ApplicationController {
public function profileAction(string $param1, string $param2) {
// logic goes here
}
}
</pre>
Check IndexController inside application/controller
to get more details.
All the view files will be inside application/view/
folder.
You can add display value in view by using View object. For example:
<pre> class UserController extends ApplicationController {
public function profileAction($param1, $param2) {
$this->view->addObject("msg", "I am the value to be displayed.");
$this->view->render('user');
}
} </pre>
In application/view/
folder, create a file named user.php
, and add the following code:
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8"/>
<title>Define MVC Index Controller with Index View</title>
<body>
<?php echo $msg ?? "No value set";?>
</body>
</html>
Refer to application/repository/IndexRepository
class to get an idea how to query and fetch result from a database. Please note DB config should be set in bootstrap.php
file.
As a good practice, call repository classes from service classes.
Refer to application/service/IndexService
class to get an idea how to call a repository class or do other things.
After setting up define-mvc-php-8 in your local server, try accessing the following:
http://www.define.mvc
http://www.define.mvc/index/
http://www.define.mvc/index/default/me-you/
http://www.define.mvc/index/test-from-service/
Define MVC is completely configurable.
For example, you want your UserController to be UserXYZ go to configuration/define.php
and change CONTROLLER_SUFFIX to XYZ. Similarly, you can change other configuration properties.
Write unit tests
Files (61) |
File | Role | Description | ||
---|---|---|---|---|
application (6 directories) | ||||
configuration (2 files) | ||||
docs (1 file) | ||||
lib (2 directories) | ||||
logs (1 file) | ||||
scripts (2 directories) | ||||
.htaccess | Data | Auxiliary data | ||
bootstrap.php | Example | Example script | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (61) | / | application |
File | Role | Description | ||
---|---|---|---|---|
controller (3 files) | ||||
exceptions (1 file) | ||||
i18n (1 directory) | ||||
repository (2 files) | ||||
service (2 files) | ||||
view (2 files) |
Files (61) | / | application | / | controller |
File | Role | Description |
---|---|---|
ApplicationController.php | Class | Class source |
ErrorController.php | Class | Class source |
IndexController.php | Class | Class source |
Files (61) | / | application | / | exceptions |
File | Role | Description |
---|---|---|
ApplicationException.php | Class | Class source |
Files (61) | / | application | / | repository |
File | Role | Description |
---|---|---|
ApplicationRepository.php | Class | Class source |
IndexRepository.php | Class | Class source |
Files (61) | / | application | / | service |
File | Role | Description |
---|---|---|
ApplicationService.php | Class | Class source |
IndexService.php | Class | Class source |
Files (61) | / | application | / | view |
Files (61) | / | configuration |
File | Role | Description |
---|---|---|
application.php | Aux. | Auxiliary script |
define.php | Aux. | Auxiliary script |
Files (61) | / | lib | / | define |
File | Role | Description | ||
---|---|---|---|---|
core (15 files) | ||||
dbdrivers (9 files) | ||||
exceptions (7 files) | ||||
traits (1 file) | ||||
utilities (7 files) |
Files (61) | / | lib | / | define | / | core |
File | Role | Description |
---|---|---|
BaseController.php | Class | Class source |
BaseDAO.php | Class | Class source |
BaseModel.php | Class | Class source |
BaseService.php | Class | Class source |
Framework.php | Class | Class source |
IBaseDAO.php | Class | Class source |
IBaseModel.php | Class | Class source |
IBaseService.php | Class | Class source |
IDefine.php | Class | Class source |
IRouter.php | Class | Class source |
IView.php | Class | Class source |
RegisterObject.php | Class | Class source |
Router.php | Class | Class source |
Session.php | Class | Class source |
View.php | Class | Class source |
Files (61) | / | lib | / | define | / | dbdrivers |
File | Role | Description |
---|---|---|
DatabaseBean.php | Class | Class source |
DatabaseFactory.php | Class | Class source |
IDatabase.php | Class | Class source |
MariaDBDriver.php | Class | Class source |
MySQLiDBDriver.php | Class | Class source |
OracleDBDriver.php | Class | Class source |
PDODBDriver.php | Class | Class source |
PostgresDBDriver.php | Class | Class source |
SQLiteDBDriver.php | Class | Class source |
Files (61) | / | lib | / | define | / | exceptions |
File | Role | Description |
---|---|---|
CloneNotSupportedException.php | Class | Class source |
FileNotFoundException.php | Class | Class source |
FrameworkException.php | Class | Class source |
IException.php | Class | Class source |
NotSerializableException.php | Class | Class source |
NullPointerException.php | Class | Class source |
RuntimeException.php | Class | Class source |
Files (61) | / | lib | / | define | / | utilities |
File | Role | Description |
---|---|---|
ErrorCodes.php | Aux. | Auxiliary script |
ErrorExceptionHandler.php | Class | Class source |
ExceptionCodes.php | Aux. | Auxiliary script |
IErrorExceptionHandler.php | Class | Class source |
IUtilities.php | Class | Class source |
Localization.php | Class | Class source |
Logger.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.