Download the PHP package kit-cosovan/base-frame without Composer
On this page you can find all versions of the php package kit-cosovan/base-frame. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kit-cosovan/base-frame
More information about kit-cosovan/base-frame
Files in kit-cosovan/base-frame
Package base-frame
Short Description FrameworkPHP is a lightweight PHP framework designed for quickly building web applications. The framework provides simple and easy-to-use tools for working with routing, databases, templates and other aspects of web development.
License MIT
Homepage https://github.com/KitCosovan/frameworkPHP
Informations about the package base-frame
Base Frame
Base Frame is a lightweight and flexible PHP framework that provides all the necessary tools for rapid web application development. It comes pre-configured so you can start creating your own views, models, and controllers right away.
Installation
Using Composer
You can install Base Frame via Composer. Add the following line to the require
section of your composer.json
:
Then run:
Core Components
index.php
: This file already contains the basic framework setup and serves as the entry point for your application. You do not need to modify it to start development.app/Controllers
: Directory for storing your controllers.app/Models
: Directory for your models.app/Views
: Directory for your views, including folders for errors and templates.config
: Framework settings, including routes and initialization.core
: Core classes of the framework, such as Application, Controller, Database, and others.helpers
: Utility functions that can be used throughout your application.
Getting Started
- Create Controllers: Navigate to the
app/Controllers
directory and create new controller files to handle requests. - Create Models: Go to the
app/Models
directory and create models for interacting with the database. - Create Views: Head to the
app/Views
directory and create view files to display data. - Configure Routes: Edit the
config/routes.php
file to set up your application's routes.
Usage Examples
Methods of Application
Application has three main methods.
-
Method
run
: Starts the application. -
Method
get
: Allows you to get data from the container. It accepts two parametersget($key, $default)
. If the data does not exist by key, the value passed by the second parameter is returned, ornull
. - Method
set
: Allows you to put data into the container. It accepts two parametersset($key, $value)
. Sets the value of$value
by the$key
.
The get and set methods are useful for debugging and storing some data throughout the application.
Methods of Cache
Cache has three main methods.
-
Method
get
: Allows you to get data from the container. It accepts two parametersget($key, $default)
. If the data does not exist by key, the value passed by the second parameter is returned, ornull
. -
Method
set
: Caches data for a specific time, by default one hour. It accepts 3 parametersset($key, $data, $time)
. Sets data$data
under$key
to a time equal to$time
. - Method
forget
: Removes data from the cache. It takes one parameterforget($key)
. The key under which the data was written.
Methods of Controller
Controller has a method.
Method render
: Renders the view. Takes three parameters render($view, $data = [], $layout = '')
.
$view
- File name (without extension: home.php
= home
).
$data
- Data passed to the view.
$layout
- The page template used in the view. File name (without extension: default.php
= default
).
Methods of Database
Before working with the databases, remember to set up the configuration files. This is mandatory.
-
Method
query
: Allows you to query the database. Accepts two parametersquery($query, $params = [])
. The query itself and the parameters, if they are required for the query. The query method excludes the possibility of SQL injection. -
Method
get
: Returns all the rows in the query. -
Method
getOne
: Returns the row as requested. -
Method
findAll
: Returns all rows from the table. Accepts one parameterfindAll($tbl)
- table name. -
Method
findOne
: Returns a row from the table by id. Accepts two parametersfindOne($tbl, $id)
.$tbl
- table name,$id
- item id. -
Method
findOrFail
: Returns a row from the table by id. Accepts two parametersfindOrFail($tbl, $id)
.$tbl
- table name,$id
- item id. If the row was not found, it returns an error. -
Method
getInsertId
: Returns the id of the string. -
Method
rowCount
: Returns the number of rows affected by the last SQL. -
Method
getColumn
: Returns the data of the requested column. -
Method
getCount
: Returns the number of rows in the table. Accepts one parametergetCount($tbl)
- table name. - Method
getQueries
: Returns all used SQL queries on the page. Useful for debugging.
Methods of Model
When creating a model, there are several mandatory variables to create.
- Variable
$table
- name of the table to which the model refers. - Variable
$fillable
- an array of names of fields mandatory for filling. When working with forms. - Variable
$rules
- an array of validation rules for fields to be filled in.
Example of model creation:
The model has several validation rules.
- Rule
required
- mandatory field to be filled in.'required' => true
- Rule
int
- the field must be a number.'int' => true
- Rule
min
- minimum number of characters.'min' => 6
- Rule
max
- maximum number of characters.'max' => 100
- Rule
email
- the field must be of email type.'email' => true
- Rule
unique
- the field value must not occur in the table.'unique' => 'users:email'
- Rule
file
- the field accepting files must be filled in.'file' => true
- Rule
ext
- allowed extensions for files.'ext' => 'jpg|png'
- Rule
size
- allowed file size.'size' => 1_048_576
- Rule
match
- the field must match another field by value.'match' => 'password'
-
Method
save
: Thesave()
method saves the model data to the database and returns the id of the saved row. -
Method
update
: Theupdate()
method updates the data within the database. And returns the number of rows inside the table. -
Method
loadData
: TheloadData()
method loads the model data. Mandatory method when creating a model. -
Method
delete
: Thedelete($id)
method takes one argument - the id of the row to delete. Deletes the row from the database. And returns the number of rows inside the table. -
Method
validate
: Thevalidate($data = [], $rules = [])
method takes two arguments:$data
is an array of validated data,$rules
is an array of validation rules. By default, both parameters are equal to empty arrays. Returns true in case of successful validation and false in case of error. - Method
getErrors
: ThegetErrors()
method returns an array of errors. - Method
hasErrors
: ThehasErrors()
method checks for errors. - Method
listErrors
: ThelistErrors()
method renders a list of errors.
Methods of Pagination
The Pagination class outputs us pagination and is based on bootstrap classes. If you use your own custom styles - feel free to modify the source code of the styles.
When you create a class, you are required to enter three parameters:
- $page - valid page.
- $per_page - number of entities on one page.
- $total - total number of entities.
Example of creating pagination.
-
Method
getStart
: ThegetStart()
method returns the line number that starts the list of entities displayed on the page. -
Method
getHtml
: ThegetHtml()
method returns the basic bootstrap page number markup.- For more convenient rendering of markup I suggest to use the following construction:
- Method
__toString
: The__toString()
method converts the result returned by thegetHtml()
method into a string.
The Pagination class has several variables that you can use, or modify.
- $count_pages - number of pages.
- $current_page - the number of the current page.
- $uri - page url.
- $max_pages - the maximum number of pages at which each page number is displayed in pagination.
Methods of Request
-
Method
getPath
: ThegetPath()
method returns the url address of the current page. -
Method
isGet
: TheisGet()
method checks if the request method was get. It returnstrue
if there was a get request andfalse
otherwise. -
Method
isPost
: TheisPost()
method checks if the request method was post. It returnstrue
if there was a post request andfalse
otherwise. -
Method
get
: Theget($name, $default = null)
method returns the query data for the$name
key, if there is no data it returns the default value$default
. The query itself must be of get type. -
Method
post
: Thepost($name, $default = null)
method returns the query data for the$name
key, if there is no data it returns the default value$default
. The query itself must be of post type. -
Method
post
: Thepost($name, $default = null)
method returns the query data for the$name
key, if there is no data it returns the default value$default
. The query itself must be of post type. - Method
getData
: ThegetData()
method returns the request data as an array, where the key-value pair matches the global array$_GET
or$_POST
, depending on the type of request passed to the page.
Methods of Response
The Response class has two important methods.
-
Method
setResponceCode
: ThesetResponceCode($code)
method sets the response code from the server to the one you pass to it as an argument. - Method
redirect
: Theredirect($url = '')
method redirects the user to the page you pass as an argument.
Methods of Router
-
Method
getRoutes
: ThegetRoutes()
method returns all routes existing in the application. -
Method
add
: Theadd($uri, $callback, $method)
method allows your route to be processed by both the post method and the get method. The parameters passed are the url address of the route, the callback processing the route and the request method, or an array of methods. -
Method
get
: Theget($uri, $callback)
method allows your route to be processed by the get method. The url address of the route is passed as parameters, callback processing this route. -
Method
post
: Thepost($uri, $callback)
method allows your route to be processed by the post method. The url address of the route is passed as parameters, callback processing this route. - Method
only
: Theonly($middleware)
method allows your route to be available only to a specific type of user.
Methods of Session
-
Method
setFlash
: ThesetFlash($key, $value)
method sets the warning, which is subsequently rendered using standard bootstrap markup. -
Method
getFlash
: ThegetFlash($key)
method allows you to get the value set in the session under a specific key. It removes this value from the session. -
Method
set
: Theset($key, $value)
method sets a key-value pair to the global array$_SESSION
. -
Method
get
: Theget($key, $default = null)
method returns the value set to the global array$_SESSION
under a specific key. If the value was not found - returns the parameter$default
. -
Method
has
: Thehas($key)
method checks if the global array$_SESSION
is set to a value under the key$key
. - Method
forget
: Theforget($key)
method removes a$key
value from the$_SESSION
global array.
Methods of View
-
Method
render
: Therender($view, $data = [], $layout = '')
method renders the view and passes data to it. A third optional argument can be passed as a template. The third argument is initially defined as default and renders a file named default.php. - Method
renderPartial
: TherenderPartial($view, $data = [])
method renders only part of the view without reloading the entire page. It also takes in the data that is passed into the view.
Helpers functions
-
Function
view()
: Simplifies the work with the methodrender
method of theView
class. Takes the same arguments as therender
method. -
Function
request()
: Allows you not to create a copy of theRequest
class, but to use a convenience function that returns that very copy. -
Function
response()
: Simplifies the work with the methodsetResponceCode
method of theResponse
class. Takes the same arguments as thesetResponceCode
method. -
Function
router()
: Allows you not to create a copy of theRouter
class, but to use a convenience function that returns that very copy. -
Function
redirect()
: Simplifies the work with the methodredirect
method of theResponse
class. Takes the same arguments as theredirect
method. -
Function
db()
: Allows you not to create a copy of theDatabase
class, but to use a convenience function that returns that very copy. -
Function
base_url($path = '')
: Returns the url address as a string with the value passed into it. The output is a full address of the following type: www.yoursite.com/$path
- Function
html($str)
: A shortened version of the standardhtmlspecialchars
function. -
Function
old($fieldname)
: Useful for working with forms. Inserts the previous entered value into the field in case validation was not passed. -
Function
oldfFromSession($arr, $fieldname)
: If the form values are written to the$_SESSION
global array as an array, this function will help to retrieve the previous entered value from there. -
Function
selected($arr, $fieldname, $value, $data = [])
: Function for processing the values selected in the form. -
Function
get_errors($fieldname, $errors = [])
: Output of validation errors. -
Function
get_validation_class($fieldname, $errors = [])
: Highlighting a field that has passed/failed validation by standard bootstrap markup. -
Function
abort($error = '', $code = 404)
: Call the error page passed as the second argument. By default the 404 page is called, which is inside the framework. It is possible to pass the error text as the first argument. -
Function
session()
: Allows you not to create a copy of theSession
class, but to use a convenience function that returns that very copy. -
Function
cache()
: Allows you not to create a copy of theCache
class, but to use a convenience function that returns that very copy. -
Function
get_alerts()
: Renders the warnings recorded in the session. -
Function
get_file_ext($file_name)
: Gets the extension of the file. Takes the full name of the file as an argument. -
Function
upload_file($file, $i = false, $path = false)
: function takes three arguments. The file name, the iteration number if you are uploading several files at once in a loop, the path to the file if it already exists. The function creates a new folder, if it doesn't exist yet, in the format year/month/day, where it puts your file with the hashed name. Returns false, or the domain path to the file. -
Function
check_auth()
: function checks if user data is written to the session. It returns a boolean value. -
Function
check_auth()
: function checks if user data is written to the session. It returns a boolean value. - Function
send_mail(array $to, string $subject, string $body, array $attachments = [])
: function sends an email. It works on the basis of PHPMailer.
Note
It is also worth noting that this technology works with other libraries such as: phpmailer and symfony/var-dumper. The former allows you to work with e-mail conveniently, and the latter is used for debugging.