Download the PHP package truecastdesign/true without Composer
On this page you can find all versions of the php package truecastdesign/true. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download truecastdesign/true
More information about truecastdesign/true
Files in truecastdesign/true
Package true
Short Description This library provides the base classes for running the True framework.
License MIT
Informations about the package true
True - Base classes for True framework
These classes form the basic functionality of True framework.
Requires PHP 8.0 or newer.
Install
To install with composer:
.htaccess file for Apache
Table of Contents
App
Routing
Request
DataCleaner
Authentication
Authentication JWT
CSS Minify
Email SMTP
File Uploads
Miscellaneous Functions
Google Authenticator
Google Tag Manager
HTTP Client
Log Parser
Password Generator
SEO
Template Filling
Validator
Task Queue
Nonce Generator
Caching
Files Setup
/public_html/index.php
/init.php
Request object
The Router object creates an instance of the Request object and inserts that into any controller as $request.
The router also passes in the $request object to the routing closure as follows.
Working with uploaded images in the $request object
Check if files are uploaded
Resize Images
The keyword 'file' in the above code is the name of the file input field. Be sure to use not use hyphens (-) in the name as that will break the object reference. Just underscores or camelCase names. If you set one dimension the other will be calulated for you.
Cropping Images
The crop method allows you to crop the top, right, bottom, or left size off of images. The values passed in the array are in that clockwise order just like in CSS.
To crop the image square automatically
To crop the image square keeping the top part and removing just the bottom automatically, use the cropBottomSquare() method.
To crop the image square keeping the bottom part and removing just the top automatically, use the cropTopSquare() method.
After you crop the image or resize it, you will want to move it to a new location by using the move method and passing in the path and the filename. To use the uploaded file extension, use the $request->files->file->ext proterty.
Creating a Response for REST or Similar Responses
Example
Explained
$App->response('The body of the response', 'the type: json, html, xml', response code, array of raw headers);
You can still echo and print_r anything you need to and this will not overwrite it. Makes it nice for debugging.
There is a die() called at the end of the response method so it needs to be the last that you want to run. This allow for error responses followed by success response in your controller.
Using Controllers
Controllers should be .php files that live in the app/controllers directory. You can trigger them to run by a custom route like $App->get('/path', 'filename.php'); or if you are using the default route that comes with TrueFramework it handles controllers and views automatically. In that case you can match the path to the controller and view. If url is www.domain.com it will run the index.php controller and display the index.phtml view. You can skip the controller altogether because it is run using a @include which if the file is not available it just quietly skips it.
Controllers should be just simple PHP scripts not classes. One PHP file per route. Nest controlers in directories named the same as the parent controller.
Example: Path -> Controller /about -> about.php /about/staff -> about/staff.php /about/staff/john-doe -> about/staff/john-doe.php
Here is what the default route looks like. You can modify it as needed.
Controllers are passed the $App object and the $request object.
Using PHPView
In your init.php file or whereever you want to put it, make a new instance of the class.
If you are using it with True framework, it is best to set it to $App->view so you already have access to it and it is in a perdictable place. It can be used without if you like.
Set PHPView variables
Set global CSS files. Use a comma delimited list of paths and filenames from public root.
PHPView will combine all the CSS files together and minify the code for output in the $_css
variable in our template.
Set global JS files. Use a comma delimited list of paths and filenames from public root.
PHPView will combine all the JS files together and minify the code for output in the $_js
variable in our template. If the JS file path has http in it, like from a CDN or other source, it will not combine that resource into the combined and minified file. It will add it in as a separate resource.
Page browser caching
Set to true or false. Caching is on by default and set to expire in 1 week. Individual page caching can be controlled by the top of view meta data. Use the cache=false
in the view meta data to turn off caching for just that page.
Other variables
Output these in your template like the following.
Output CSS and JS to template
The css and js view variables are special in that to output a compressed and combined version to your page, you use a special variable rather than $App->view->css like you would all the other variables.
For CSS
The css output should go in your head tag.
For Javascript
The JS output should go right before the closing body tag.
There needs to be a cache folder in both of your CSS and JS folders.
PHPView will put a compressed, versioned, combined file in /assets/css/cache and /assets/js/cache respectfully. Be sure those directories are there for it to work right.
Custom variables
You can use your own custom variables now so you can pass the values to the base template for outputting in the header for example.
In the meta area of the view/.phtml file, add your custom variable like:
When you put that in the meta area of a file, then the base template will be able to access and check if it is available with the following.
Creating and Using View Files
View files need to be named {name}.phtml
They go in the /app/views directory
Urls with /name match the file /app/views/name.phtml Urls with /name/othername match the file /app/views/name/othername.phtml
There should be a base view that has all the site html tags that surround the main content of the page that comes from the page view files. It will insert the contents of, for example name.phtml, and insert it whereever <?=$_html?> is in the base view.
The second parameter is an array of variable that will be available to the page. In the above example, $var1
will be equel to 6. You can pass class objects this way as well.
Using a Custom Layout (header/footer code) to insert your view into.
Make a custom controller and in the controller put:
Render file that is not in the /app/views directory
Render an error page
Default error pages: 404-error.phtml 401-error.phtml 403-error.phtml error.phtml
For the error.phtml page, there is provided $errorCode and $errorText variables to display which error it is.
Set custom error page
Emailing
True has a builtin SMTP email class for sending out emails using a SMTP email account for better deliverability and features.
JWT Javascript Web Token
LogParser
SEO/OpenGraph LD+JSON
Use this method of the SEO class to output LD+JSON schema.org meta data.
Global site schema
Specific page schemas
Full list of available schemas
recipe article organization website webpage blogpost breadcrumbs store homeandconstructionbusiness product
See the files in /vendor/truecastdesign/true/src/schemaTypes for individual documentation of which array keys and values to pass for each one.
Google Tag Manager GA4 Javascript code generator
Use the below code and similar for different events
This will output the below JS code including script tags for you. The class does basic value validation and filtering. It auto adds in the currency as USD. If you need a different currency just pass it in with the key 'currency'.
Current event support is:
view_item add_to_cart view_cart begin_checkout login purchase
TESTING PHPUNIT
Tests are located in the tests folder.
List of tests and how to run them.
Usage
Build your website in the app folder using the available folder structure.
The app folder should be located beside the public folder. Assets, such as images, css, js, pdfs, etc., should be located in the assets folder inside the public folder.
Issues
When running on localhost, cookies for logging into admin area will not set using Chrome. They require a domain. Use Firefox or Safari to develop site.