phpizi / framework
MVC framework for PHP based on ASP MVC features
This package is auto-updated.
Last update: 2024-12-26 06:25:58 UTC
README
- Dowload this framework.
- Rename 'easyflow' to your project name.
- Working in the App folder (Ignoring Core).
app ├── config ├── controllers ├── libs ├── models ├── public ├── views └── main.php
How to work with easyflow?
you have to follow a series of naming rules to work with easyflow.
Files
-
Controllers: Point nomenclature and in lower case, all must end in '.controller'.
-
Models: Point nomenclature and in lower case, all must end in '.model'.
-
Views: Create a folder for each controller and within all the actions|functions that the controller has defined:
app ├── controllers │ └── articles.controller.php ├── models │ └── articles.model.php ├── views │ └── articles │ └── index.php │ └── news.php ├── ...
Classes
- Controllers: UpperCamelCase, all must end in 'Controller'.
class ArticlesController extends Controller { }
- Models class name: UpperCamelCase, all must end in 'Model'.
class ArticlesModel extends Model { }
NOTE: When we reference a controller or model from the code, we do so without its prefixes.
Automatic creation
You can create the files manually following these naming rules but we have failed a .bat that allows you to create controllers, models and views in an autonomous way thus avoiding errors.
Controller, Model and View
.bat articles
Only Controller and Model
.bat articles -true -false
Only Controller
.bat articles -false -false
View variables
You can access these variables in any view.
echo $PROJECT_PATH; echo $BASE_URL; echo $CONTROLLER; echo $ACTION;
Config pattern
You can config a default pattern in the main.php file.
DefaultUrl::$pattern = "{articles}/{index}/{1}";
Actions
view()
you can display a view like this:
class ArticlesController extends Controller { function index(): View { return view(); } }
json()
You can respond with a json like this:
class ArticlesController extends Controller { function index(): Json { return json("Hello world!"); } }
redirectToAction()
you can redirect to a controller action like this:
class ArticlesController extends Controller { function index(): Redirect { return redirectToAction('index', 'Login'); } }
redirectToUrl()
you can redirect to a web url like this:
class ArticlesController extends Controller { function index(): Redirect { return redirectToUrl('https://www.youtube.com/'); } }
Prefix
For app
you can set a url prefix at application level like this:
DefaultUrl::$pattern = "application/{articles}/{index}/{1}";
For controller
you can set a url prefix at controller level like this:
class ArticlesController extends Controller { function __construct() { prefix("statistics"); } ... }
Specify view and data
You can speciy the view name and the data name.
View variables
You can access these variables in any view: $CONTROLLER, $ACTION, $BASE_URL.
Use params
You can send parameters to a certain action We can obtain the parameters as follows.
- articles/index/1
- articles/index/1/Yordii
Template (shared folder)
There will always be files 'footer' and 'header', these will wrap all views. You can add other components like 'menu' etc and add them to any part of your template stored in your 'shared' folder.
Omit template
You can omit the template that wraps the view with a third parameter.
Connect to Mysql
- In the config file you can set your connection data.
- You will have to load your database in your model, the load is not automatic because not all models can obtain data from a database, so resources are saved.
- Finally in your controller you can use your model and access your data as follows.
Contributions
Your contributions are welcome! If you want to collaborate in this project, please follow the steps below:
- Fork this repository and clone your own copy to your local machine.
- Create a new branch to make your changes:
git checkout -b additional
. - Make changes and improvements to the code.
- Make sure your changes follow the style guides and best practices of the project.
- Commit your changes:
git commit -m "Description of changes"
. - Push your changes to your remote repository:
git push origin additional
. - Open a Pull Request to this main repository and describe the changes you have made.
- Wait for your changes to be reviewed and merged.
Contact
If you have any questions or suggestions related to this project, feel free to contact me. You can find me at yokdy360@gmail.com.
License
This project is licensed under the MIT License. If you use this code, please include the LICENSE file in your project.