### Temporal Model Setup
Source: https://fuelphp.com/docs/packages/orm/model/temporal.html
Example of how to set up a model to use the Temporal Model, including primary key and temporal column configurations.
```APIDOC
## Temporal Model Setup
### Description
Configure a model to utilize the Temporal Model by defining the primary key and temporal columns.
### Method
N/A (Configuration)
### Endpoint
N/A (Model Configuration)
### Parameters
#### Model Properties
- **`static $_primary_key** (array) - Required - Must be a compound key including the entity ID and temporal timestamps.
- **`static $_temporal** (array) - Required - Configuration for temporal properties.
- **`start_column`** (string) - Required - The name of the column containing the row's valid start time.
- **`end_column`** (string) - Required - The name of the column containing the row's valid end time.
- **`mysql_timestamp`** (boolean) - Optional - If true, uses MySQL timestamps; otherwise, uses Unix timestamps. Defaults to false.
### Request Example
```php
class Model_MyTemporal extends Orm\Model_Temporal
{
protected static $_primary_key = array('id', 'temporal_start', 'temporal_end');
protected static $_temporal = array(
'start_column' => 'temporal_start',
'end_column' => 'temporal_end',
'mysql_timestamp' => false,
);
}
```
### Response
N/A (Configuration)
### Response Example
N/A (Configuration)
```
--------------------------------
### Auth Configuration File Example
Source: https://fuelphp.com/docs/packages/auth/intro.html
Example structure for the config/auth.php file.
```php
array('Simpleauth'),
// Set to true to allow multiple logins
'verify_multiple_logins' => true,
// Use your own salt for security reasons
'salt' => 'Th1s=mY0Wn_$@|+',
);
```
--------------------------------
### Install Oil Quick Installer
Source: https://fuelphp.com/docs/installation/instructions.html
Run this command to install the Oil quick installer script. It simplifies project creation and oil commands.
```bash
$ curl -L https://get.fuelphp.com/oil | sh
```
--------------------------------
### Full Many-to-Many Configuration Example
Source: https://fuelphp.com/docs/packages/orm/relations/many_many.html
Illustrates a comprehensive configuration for a many-to-many relationship, specifying keys, the through table, and cascade options. Useful for non-standard setups.
```php
// in a Model_Post which has and belongs to many Users
// = multiple posts per user and multiple users (authors) per post
protected static $_many_many = array(
'users' => array(
'key_from' => 'id',
'key_through_from' => 'post_id', // column 1 from the table in between, should match a posts.id
'table_through' => 'posts_users', // both models plural without prefix in alphabetical order
'key_through_to' => 'user_id', // column 2 from the table in between, should match a users.id
'model_to' => 'Model_User',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => false,
)
);
```
--------------------------------
### Install Package Directly (ZIP)
Source: https://fuelphp.com/docs/packages/oil/package.html
Installs a package by directly downloading and unzipping a ZIP file. Use this if Git is not installed or if the --direct flag is provided.
```bash
$ php oil package install test-package --direct
Downloading package: http://github.com/philsturgeon/fuel-test-package/zipball/master
DOCROOT/fuel/packages/test-package/LICENSE.txt
DOCROOT/fuel/packages/test-package/README
DOCROOT/fuel/packages/test-package/classes/association.php
DOCROOT/fuel/packages/test-package/classes/belongsto.php
DOCROOT/fuel/packages/test-package/classes/exception.php
DOCROOT/fuel/packages/test-package/classes/hasmany.php
DOCROOT/fuel/packages/test-package/classes/hasone.php
DOCROOT/fuel/packages/test-package/classes/model.php
```
--------------------------------
### Example Theme Configuration
Source: https://fuelphp.com/docs/classes/theme/introduction.html
An example of a complete theme configuration file (app/config/theme.php) showing how to set various theme options.
```php
// Inside app/config/theme.php
return array(
'active' => 'default',
'fallback' => 'default',
'paths' => array( // theme files are outside the DOCROOT here
APPPATH.'themes',
),
'assets_folder' => 'themes', // so this implies /public/themes/...
'view_ext' => '.html',
'info_file_name' => 'themeinfo.ini',
'require_info_file' => false,
'use_modules' => true,
);
```
--------------------------------
### MySQLi Database Configuration Example
Source: https://fuelphp.com/docs/classes/database/introduction.html
Example configuration for a MySQLi database connection in the 'development' environment. Ensure 'type' is set to 'mysqli' for this driver.
```php
// a MySQL driver configuration
'development' => array(
'type' => 'mysqli',
'connection' => array(
'hostname' => 'localhost',
'port' => '3306',
'database' => 'fuel_db',
'username' => 'your_username',
'password' => 'y0uR_p@ssW0rd',
'persistent' => false,
'compress' => false,
),
'identifier' => '`',
'table_prefix' => '',
'charset' => 'utf8',
'enable_cache' => true,
'profiling' => false,
'readonly' => false,
),
```
--------------------------------
### Call a FuelPHP Task
Source: https://fuelphp.com/docs/general/tasks.html
Example command to execute a FuelPHP task named 'example' with an argument. The `run()` method is invoked by default.
```bash
$ php oil refine example "Good morning"
```
--------------------------------
### Install Package with Git
Source: https://fuelphp.com/docs/packages/oil/package.html
Installs a package using Git if available. This method allows for easier updates and tracking of changes.
```bash
$ php oil package install test-package
Downloading package: git://github.com/philsturgeon/fuel-test-package.git
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 13 (delta 3), reused 0 (delta 0)
Receiving objects: 100% (13/13), 10.85 KiB, done.
Resolving deltas: 3/3, done.
Cloning into /Users/phil/Sites/fuel/fuel/packages/test-package...
```
--------------------------------
### Protected Method and Property Example
Source: https://fuelphp.com/docs/general/coding_standards.html
This example demonstrates the declaration of protected methods and properties, adhering to naming conventions.
```php
class View
{
// Array of global view data
protected static $_global_data = array();
protected static function capture($view_filename, array $view_data)
{
// Some code here
}
}
```
--------------------------------
### Start FuelPHP Server
Source: https://fuelphp.com/docs/packages/oil/server.html
Use this command to start the built-in development server. Ensure you are in the project's root directory. The server will listen on http://localhost:8000 by default, with the document root set to the 'public/' directory. Press Ctrl-C to stop.
```bash
$ php oil server
Listening on http://localhost:8000
Document root is public/
Press Ctrl-C to quit.
```
--------------------------------
### PHP Config File Example
Source: https://fuelphp.com/docs/classes/config.html
A basic PHP configuration file should return an array structure.
```php
return array('key' => 'value');
```
--------------------------------
### Language File Formats
Source: https://fuelphp.com/docs/classes/lang.html
Examples of supported language file structures.
```php
return array('key' => 'value');
```
```ini
[group]
key=value
```
```yaml
group:
key: value
```
```json
{
"group" :
{
"key": "value"
}
}
```
```sql
CREATE TABLE IF NOT EXISTS `lang` (
`identifier` char(100) NOT NULL,
`language` char(10) NOT NULL,
`lang` longtext NOT NULL,
`hash` char(13) NOT NULL,
PRIMARY KEY (`identifier`, `language`)
)
```
--------------------------------
### Num Configuration Examples
Source: https://fuelphp.com/docs/classes/num.html
Configuration settings for phone, smart phone, credit card, and expiration date formatting.
```php
'(000) 000-0000'
```
```php
array(
7 => '000-0000',
10 => '(000) 000-0000',
11 => '0 (000) 000-0000',
),
```
```php
'00-00'
```
```php
'00-00'
```
--------------------------------
### JSON Config File Example
Source: https://fuelphp.com/docs/classes/config.html
Configuration values can be stored in JSON file format.
```json
{
"group" :
{
"key": "value"
}
}
```
--------------------------------
### Indentation Example
Source: https://fuelphp.com/docs/general/coding_standards.html
Use real tabs for indentation and spaces for aligning code within a line. This example shows proper indentation and alignment.
```php
// indented 2 tabs
$var = 'something'; // indented with tabs and aligned value & comments
$variable = 'else'; // with those above/below using spaces
```
--------------------------------
### Logging Usage Examples
Source: https://fuelphp.com/docs/classes/log.html
Demonstrates how to use the Log class to write entries with different levels and custom methods.
```php
// Write a log entry with the level "Info" to the log file for the current day
$var = 1;
Log::info('Application started (with $var = '.$var.')', 'my_init_function()');
// Save the new value of $var to the log file, without the $method parameter
$var = 5;
Log::debug('$var is now '.$var);
// Send a warning log entry
if($var !== 1) Log::warning('Although $var has been changed, we will keep going.');
// Send an error log entry
if($var !== 1) Log::error('We cannot keep going, $var has been changed! :o');
// Finally, try to make a log entry with a custom $level
Log::write('Link', 'More info on https://fuelphp.com/');
```
--------------------------------
### Basic Template Controller Example
Source: https://fuelphp.com/docs/general/controllers/template.html
A simple example of a controller extending Controller_Template. By default, all methods will use the template.
```php
class Controller_Example extends Controller_Template
{
public function action_index()
{
$data = array();
$this->template->title = 'Example Page';
$this->template->content = View::forge('test/index', $data);
}
}
```
--------------------------------
### Email Package Installation
Source: https://fuelphp.com/docs/packages/email/introduction.html
Instructions on how to install and load the Email package in FuelPHP.
```APIDOC
## Email Package Installation
The Email package is part of the official download (since version 1.1). You will have to enable the package either in the app config or include it on the fly.
### Configuration
**Enable in app/config/config.php:**
```php
array(
'email',
),
);
?>
```
**Or load on the fly in a controller:**
```php
\Package::load('email');
```
```
--------------------------------
### Default Email Setup Configuration
Source: https://fuelphp.com/docs/packages/email/introduction.html
Configuration for the default email setup group. Add or modify your own setup groups here.
```php
array(
'default' => array(),
)
```
--------------------------------
### YAML Config File Example
Source: https://fuelphp.com/docs/classes/config.html
Configuration values can be stored in YAML file format.
```yaml
group:
key: value
```
--------------------------------
### Set Default Writable Directories with PHP Oil
Source: https://fuelphp.com/docs/installation/instructions.html
If Oil is not installed globally, you can run the `refine install` task using `php` from the installation root directory. This makes essential directories writable.
```bash
cd /where/ever/your/virtualhost/root/is
php oil refine install
Made writable: APPPATH/cache
Made writable: APPPATH/logs
Made writable: APPPATH/tmp
Made writable: APPPATH/config
```
--------------------------------
### Verify Oil Installation
Source: https://fuelphp.com/docs/packages/oil/intro.html
Check the current version of the Oil utility to ensure it is correctly installed and accessible.
```bash
$ cd Sites/fuel
$ php oil -v
Fuel: 1.2
```
--------------------------------
### Quick Install FuelPHP
Source: https://fuelphp.com/docs/index.html
Use this command to quickly install the oil tool from the web using curl. This is followed by creating a new FuelPHP application.
```bash
# quick install oil from the web
$ curl https://get.fuelphp.com/oil | sh
# now that oil is installed, create a blog project in a directory called Sites
$ cd Sites/
$ oil create blog
```
--------------------------------
### Start a database transaction
Source: https://fuelphp.com/docs/classes/database/db.html
Initiates a new transaction on the database instance.
```php
DB::start_transaction();
```
--------------------------------
### INI Config File Example
Source: https://fuelphp.com/docs/classes/config.html
Configuration values can be stored in INI file format.
```ini
[group]
key=value
```
--------------------------------
### Cookie Driver Configuration Example
Source: https://fuelphp.com/docs/classes/session/config.html
Specific configuration for cookie based sessions.
```php
array(
'cookie_name' => 'fuelcid',
'write_on_set' => true
)
```
--------------------------------
### Install FuelPHP via Composer (Clone Latest Release)
Source: https://fuelphp.com/docs/installation/instructions.html
Clone the latest release of FuelPHP from GitHub and install dependencies using Composer. Ensure you are in your virtual host root directory. The trailing dot is crucial.
```bash
cd /where/ever/your/virtualhost/root/is
git clone git://github.com/fuel/fuel.git .
composer install --prefer-dist
```
--------------------------------
### Class Declaration Example
Source: https://fuelphp.com/docs/general/coding_standards.html
Class names should use underscores to separate words, with each word starting with a capital letter. This example shows a basic class declaration.
```php
namespace Fuel\Core;
class Session
{
}
```
--------------------------------
### Example Generated Controller
Source: https://fuelphp.com/docs/packages/oil/generate.html
The resulting controller class structure after running the controller generation command.
```php
class Controller_Posts extends Controller_Template
{
public function action_action1()
{
$this->template->title = 'Posts » Action1';
$this->template->content = View::forge('posts/action1');
}
public function action_action2()
{
$this->template->title = 'Posts » Action2';
$this->template->content = View::forge('posts/action2');
}
public function action_action3()
{
$this->template->title = 'Posts » Action3';
$this->template->content = View::forge('posts/action3');
}
}
/* End of file posts.php */
```
--------------------------------
### Readonly Slave Database Configuration Example
Source: https://fuelphp.com/docs/classes/database/introduction.html
Configuration for a read-only slave database connection, intended for use in a master/slave setup. Multiple slave configurations can be defined.
```php
'slave1' => array(
// configuration of the first production readonly slave db
),
'slave2' => array(
// configuration of the second production readonly slave db
),
'slave3' => array(
// configuration of the third production readonly slave db
),
```
--------------------------------
### Get Nested Configuration Item
Source: https://fuelphp.com/docs/classes/config.html
Accesses a specific configuration value within a nested structure using dot notation. This example retrieves the active database connection setting.
```php
$active_db = Config::get('db.active');
```
--------------------------------
### Log File Output Format
Source: https://fuelphp.com/docs/classes/log.html
Example of the content written to a log file.
```text
INFO - 2011-01-03 18:44:45 --> my_init_function() - Application started (with $var = 1)
DEBUG - 2011-01-03 18:44:45 --> $var is now 5
WARNING - 2011-01-03 18:44:45 --> Although $var has been changed, we will keep going.
ERROR - 2011-01-03 18:44:45 --> We cannot keep going, $var has been changed! :o
NOTICE - 2011-01-03 18:44:45 --> More info on https://fuelphp.com/
```
--------------------------------
### Get Deeply Nested Configuration Item
Source: https://fuelphp.com/docs/classes/config.html
Retrieves a configuration value from multiple levels deep within the configuration array using dot notation. This example fetches the hostname for the 'dev' database group.
```php
$dev_host = Config::get('db.dev.connection.hostname');
```
--------------------------------
### Install Parser Dependencies
Source: https://fuelphp.com/docs/packages/parser/intro.html
Add required template engine libraries to your project's composer.json file.
```json
{
"require": {
"dwoo/dwoo" : "*",
"mustache/mustache" : "*",
"smarty/smarty" : "*",
"twig/twig" : "*",
"mthaml/mthaml": "*",
"pyrocms/lex": "*"
}
}
```
--------------------------------
### Fixing 404 on Index Page with .htaccess
Source: https://fuelphp.com/docs/installation/troubleshooting.html
When the index page returns a 404 error, it may be necessary to add a question mark after index.php in the _.htaccess_ file. This configuration is sometimes required for specific PHP installations or FastCGI setups.
```apache
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# If fuel is not a level up
# RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# Notice the ? after index.php
```
```apache
RewriteRule ^(.*)$ index.php?$1 [L]
# Notice the fact that the slash has been removed after the ?
```
```apache
#Other possible setups:
RewriteRule ^(.*)$ /index.php/$1 [L]
# Notice the leading slash added before index.php
```
--------------------------------
### Configure Auth Drivers
Source: https://fuelphp.com/docs/packages/auth/drivers.html
Configuration examples for the auth.php config file. Shows how to add a new custom driver or replace an existing one in the driver array.
```php
// Inside config/auth.php array
// Add it as a second driver
'driver' => array('Simpleauth', 'Mydriver'),
// or replace the existing driver
'driver' => array('Mydriver'),
```
--------------------------------
### Initialize Cache Instance
Source: https://fuelphp.com/docs/classes/cache/advanced.html
Create a new cache instance using specific configuration options.
```php
$options = array(...); //These are the same as in the cache config file.
$cache = Cache::forge('my_cache', $options)
```
--------------------------------
### Log::info Method Usage
Source: https://fuelphp.com/docs/classes/log.html
Example of using the info method with a null default for the method parameter.
```php
null
```
```php
$var = 1;
Log::info('Application started (with $var = '.$var.')', 'my_init_function()');
```
--------------------------------
### Run Auth Migrations
Source: https://fuelphp.com/docs/packages/auth/ormauth/intro.html
Use this command to create the necessary database tables for the Auth package.
```bash
oil refine migrate --packages=auth
```
--------------------------------
### Get Main Request Instance
Source: https://fuelphp.com/docs/classes/request/request.html
Returns the initial request instance created by the page load.
```php
$main = Request::main();
```
--------------------------------
### Define Environment-Specific Configuration Directory Structure
Source: https://fuelphp.com/docs/general/environments.html
Example directory structure showing how environment-specific configuration files are organized within the app/config directory.
```text
app/
config/
auth.php
db.php
development/
db.php
staging/
email.php
mike_dev/
db.php
email.php
production/
db.php
```
--------------------------------
### Get Fieldset Input
Source: https://fuelphp.com/docs/classes/fieldset/fieldset.html
Retrieves validated input values from POST or GET data.
```php
$input_values = $article_form->input();
```
--------------------------------
### Load Language Files
Source: https://fuelphp.com/docs/classes/lang.html
Demonstrates loading language files with groups, namespaces, and specific language overrides.
```php
// Example of a language file:
return array(
'hello' => 'Hello :name',
'something'=> 'something :name!',
'test'=> array('hello' => 'Hello', 'something' => 'Plop') // Group
);
// Loads example.php.
// Note: If no language is set in the config, it will fallback to English.
Lang::load('example');
// Will load the given file into the 'test' group.
Lang::load('example', 'test');
// Outputs Plop
$this->output = Lang::get('test.test.something');
// Will load the example language file from the module 'foo' into the 'bar' group.
Lang::load('foo::example', 'bar');
// Will load the example language file in italian.
// If that doesn't exist, it will load the configured language
Lang::load('foo::example', 'bar', 'it');
```
--------------------------------
### List PHP configuration with Debug::phpini
Source: https://fuelphp.com/docs/classes/debug.html
Prints all configuration settings read from the php.ini file.
```php
Debug::phpini();
```
--------------------------------
### Public Static Method Example
Source: https://fuelphp.com/docs/general/coding_standards.html
Method names should be all lower case and use underscores to separate words. Visibility must be included. This shows a public static method.
```php
class Session
{
public static function get_flash($name, $data)
{
// Some code here
}
}
```
--------------------------------
### Default Email Configuration Array
Source: https://fuelphp.com/docs/packages/email/introduction.html
Default configuration array for email setups. Overwrite these values in your specific setup group.
```php
array( /* default config array */ )
```
--------------------------------
### Inherited Class Declaration Example
Source: https://fuelphp.com/docs/general/coding_standards.html
This example demonstrates a class declaration that extends another class, following the naming conventions.
```php
namespace Fuel\Core;
class Session_Cookie extends Session_Driver
{
}
```
--------------------------------
### Access Oil Help Documentation
Source: https://fuelphp.com/docs/packages/oil/intro.html
Display the general help menu or specific command documentation for the Oil utility.
```bash
$ php oil help
Usage:
php oil [cell|console|generate|package|refine|help|server|test]
Runtime options:
-f, [--force] # Overwrite files that already exist
-s, [--skip] # Skip files that already exist
-q, [--quiet] # Supress status output
-t, [--speak] # Speak errors in a robot voice
Description:
The 'oil' command can be used in several ways to facilitate quick development, help with
testing your application and for running Tasks.
Environment:
If you want to specify a specific environment oil has to run in, overload the environment
variable on the commandline: FUEL_ENV=staging php oil
More information:
You can pass the parameter "help" to each of the defined command to get information
about that specific command: php oil package help
Documentation:
http://docs.fuelphp.com/packages/oil/intro.html
```
```bash
$ php oil generate help
```
--------------------------------
### Instantiate Classes with Namespaces
Source: https://fuelphp.com/docs/general/packages.html
Demonstrates how to instantiate classes from a package, depending on whether the package namespace is aliased to the global scope. If not aliased, the full namespace must be provided.
```php
// If aliased to global just use
$instance = new Myclass;
// When not aliased to global
$instance = new Mynamespace\Myclass;
```
--------------------------------
### Accessing Task Help
Source: https://fuelphp.com/docs/packages/oil/refine.html
Use these commands to display help information for a specific task.
```bash
$ php oil refine :help
```
```bash
$ php oil refine from('my@email.me', 'My Name');
// Set the to address
$email->to('receiver@elsewhere.co.uk', 'Johny Squid');
// Set a subject
$email->subject('This is the subject');
// Set multiple to addresses
$email->to(array(
'example@mail.com',
'another@mail.com' => 'With a Name',
));
// And set the body.
$email->body('This is my message');
```
--------------------------------
### Template Controller with Before and After Methods
Source: https://fuelphp.com/docs/general/controllers/template.html
Demonstrates using before() and after() methods within a Template Controller. Ensure parent::before() is called to initialize templating, and after() accepts a response object.
```php
class Controller_Example extends Controller_Template
{
/**
* Your before method
*/
public function before()
{
parent::before(); // Without this line, templating won't work!
// do stuff
}
/**
* Make after() compatible with Controller_Template by adding $response as a parameter
*/
public function after($response)
{
$response = parent::after($response); // not needed if you create your own response object
// do stuff
return $response; // make sure after() returns the response object
}
public function action_index()
{
$data = array();
$this->template->title = 'Example Page';
$this->template->content = View::forge('test/index', $data);
}
}
```
--------------------------------
### Get Pagination Configuration Item
Source: https://fuelphp.com/docs/classes/pagination.html
Use the static get method to retrieve a configuration item from the default Pagination instance. This is an alias for direct property access.
```php
// fetch the current page number
$page_number = Pagination::get('current_page');
// this is an alias of
$page_number = Pagination::instance()->current_page;
```
--------------------------------
### Image Class Presets Configuration
Source: https://fuelphp.com/docs/classes/image.html
Define a set of image manipulation actions in the configuration file to be called later as a preset. This example sets background color, output type, quality, and defines actions for cropping, watermarking, and output format.
```php
/**
* These presets allow you to call controlled manipulations.
*/
'presets' => array(
'mypreset' => array(
'bgcolor' => '#f00', // Set the background color red
'filetype' => 'jpg', // Output as jpeg.
'quality' => 75,
'actions' => array(
array('crop_resize', 200, 200),
array('watermark', '$1'), // Note the $1 is a variable.
array('output', 'png')
)
)
)
```
--------------------------------
### Get Root Node
Source: https://fuelphp.com/docs/packages/orm/model/nestedset.html
Retrieves the root node of the tree the current object belongs to. Can also be used to get the root of a specific tree by setting the tree ID.
```php
// get the root of the tree $henry belongs to
$root = $henry->root()->get_one();
// echos 'true'
echo $root == $bill ? 'true' : 'false';
// get the root of a specific tree
$root = Model_Tree::forge()->set_tree_id($mytreeid)->root()->get_one();
```
--------------------------------
### Get or Set Response Body
Source: https://fuelphp.com/docs/classes/response.html
The body method can be used to get the current response body or set a new one. If no value is provided, it returns the current body.
```php
$response = new Response();
$response->body('This is the response body');
// returns 'This is the response body'
$body = $response->body();
```
--------------------------------
### Defining Asset Paths
Source: https://fuelphp.com/docs/classes/asset/config.html
Examples of how to resolve asset paths using global search paths or individual asset search folders.
```php
// assuming:
// - your URL is "http://example.org/"
// - your global search path is "assets/"
// - your img_dir is "img/"
// this would return
echo Asset::img('icons/myicon.png');
```
```php
// if this is your config
// 'folders' => array(
// 'css' => array('assets/css'),
// 'js' => array('assets/js', 'global/js/'),
// 'img' => array('assets/img/', 'assets/icons'),
// ),
// and your icons are in 'assets/icons',
// this would return
echo Asset::img('myicon.png');
```
--------------------------------
### Install FuelPHP via Composer (Clone Development Branch)
Source: https://fuelphp.com/docs/installation/instructions.html
Clone the latest development branch of FuelPHP from GitHub and install dependencies. Use this for the most recent features. The trailing dot is important.
```bash
cd /where/ever/your/virtualhost/root/is
git clone git://github.com/fuel/fuel.git -b 1.9/develop .
composer install
```
--------------------------------
### Request_Soap Class Initialization
Source: https://fuelphp.com/docs/classes/request/soap.html
Demonstrates how to create an instance of the Request_Soap class using Request::forge().
```APIDOC
## Request_Soap Class Initialization
### Description
Creates an instance of the `Request_Soap` class to process SOAP requests.
### Method
`Request::forge(string $url, string $type = 'soap')`
### Endpoint
N/A (This is a class instantiation method)
### Parameters
- **url** (string) - Required - The URL of the SOAP service.
- **type** (string) - Optional - Defaults to 'soap'. Specifies the request type.
### Request Example
```php
// create a Request_Soap object
$soap = Request::forge('http://soap.example.org/api/v1/this/info', 'soap');
// note that this only creates the object, it does not execute the request!
```
```
--------------------------------
### Create New FuelPHP Project with Oil
Source: https://fuelphp.com/docs/installation/instructions.html
Use the installed Oil script to create a new FuelPHP project. This command also runs `oil refine install` and `composer update`.
```bash
$ oil create
```
--------------------------------
### Configure and Set Active Theme
Source: https://fuelphp.com/docs/classes/theme/advanced.html
Demonstrates standard and advanced usage for setting an active theme. Advanced usage involves loading configuration, overriding settings, and passing a theme definition array.
```php
// standard usage: create an instance and set the active theme
$theme =
Theme::forge();
$theme->active('darkglow');
```
```php
// advanced usage
Config::load('theme', true, false, true);
$config =
Config::get('theme', false);
// override a config value
$config['info_file_name'] = 'setupinfo.yaml';
// create the theme instance
$theme =
Theme::forge($config);
```
```php
// set the active theme
$theme->active(
array(
'name' => 'darkglow',
'path' => APPPATH.'themes'.DS.'darkglow'.DS,
'asset_base' => '/themes/darkglow/assets/',
'find_file' => true,
)
);
```
--------------------------------
### PDO PostgreSQL Database Configuration Example
Source: https://fuelphp.com/docs/classes/database/introduction.html
Example configuration for a PDO database connection using PostgreSQL in the 'production' environment. The 'type' must be set to 'pdo' and a 'dsn' string is required.
```php
// a PDO driver configuration, using PostgreSQL
'production' => array(
'type' => 'pdo',
'connection' => array(
'dsn' => 'pgsql:host=localhost;dbname=fuel_db',
'username' => 'your_username',
'password' => 'y0uR_p@ssW0rd',
'persistent' => false,
'compress' => false,
),
'identifier' => '"',
'table_prefix' => '',
'charset' => 'utf8',
'enable_cache' => true,
'profiling' => false,
'readonly' => array('slave1', 'slave2', 'slave3'),
),
```
--------------------------------
### Get Profile Fields
Source: https://fuelphp.com/docs/packages/auth/ormauth/usage.html
Retrieves one or all stored profile fields for the logged-in user. Specify a field name to get a single field, or provide a default value if the field does not exist.
```php
// get all profile fields defined
$profile = Auth::get_profile_fields();
// get a specific profile fields defined
$fullname = Auth::get_profile_fields('fullname', 'Unknown');
// will return null, as username is not part of the metadata
$fullname = Auth::get_profile_fields('username', 'Unknown username');
```
--------------------------------
### Set Default Writable Directories with Oil
Source: https://fuelphp.com/docs/installation/instructions.html
Run this Oil task after installation to set the necessary directories (cache, logs, tmp, config) to be writable by the framework.
```bash
$ oil refine install
Made writable: APPPATH/cache
Made writable: APPPATH/logs
Made writable: APPPATH/tmp
Made writable: APPPATH/config
```
--------------------------------
### Implement get_user_id Function (Simpleauth Example)
Source: https://fuelphp.com/docs/packages/auth/drivers.html
Example implementation of the get_user_id function from the Simpleauth driver. It returns an array containing the driver's ID and the user's ID, or false if the user is not logged in.
```php
/**
* Get the user's ID
*
* @return Array containing this driver's ID & the user's ID
*/
public function get_user_id()
{
if (empty($this->user))
{
return false;
}
return array($this->id, (int) $this->user['id']);
}
```
--------------------------------
### Generate Package Skeleton
Source: https://fuelphp.com/docs/packages/oil/generate.html
Creates a basic package structure in `PKGPATH` with default classes, configuration, and bootstrap files. You can specify a custom path using `--path`.
```bash
$ php oil g package sample
Creating file: PKGPATH/sample/classes/sample.php
Creating file: PKGPATH/sample/config/sample.php
Creating file: PKGPATH/sample/bootstrap.php
```
--------------------------------
### Instantiate a View Object
Source: https://fuelphp.com/docs/classes/view.html
Create a new View instance by providing the file path and an optional array of data.
```php
$view = new View('path/to/view', array(
'menu' => $menu,
'articles' => $articles,
'footer_links' => $footer_links,
));
```
--------------------------------
### body
Source: https://fuelphp.com/docs/classes/response.html
Gets or sets the current response body.
```APIDOC
## body($value = false)
### Description
The body method allows getting the current response body, or setting a new one.
### Parameters
- **$value** (mixed) - Optional - Response body to set. If not given, the current response body is returned.
### Returns
- **Mixed** - Current response body, or the current response object for chaining.
```
--------------------------------
### Get To Addresses
Source: https://fuelphp.com/docs/packages/email/methods.html
Retrieves all configured 'to' email addresses.
```APIDOC
## GET /api/email/to
### Description
Returns the configured 'to' addresses.
### Method
GET
### Endpoint
/api/email/to
### Parameters
_None_
### Response
#### Success Response (200)
- **array** - An array of 'to' email addresses.
#### Response Example
```json
{
"to_addresses": [
"recipient1@example.com",
"recipient2@example.com"
]
}
```
```
--------------------------------
### Generate Basic Config File
Source: https://fuelphp.com/docs/packages/oil/generate.html
Creates a new configuration file with a simple key-value pair. The file is created in `APPPATH/config/`.
```bash
$ php oil g config sample hello:world
Created config: APPPATH/config/sample.php
```
```php
return array (
'hello' => 'world',
);
/* End of file sample.php */
```
--------------------------------
### Run Migration Commands
Source: https://fuelphp.com/docs/packages/oil/generate.html
Commands for managing and executing database migrations via the refine task.
```bash
$ php oil refine migrate
Currently on migration: 5.
$ php oil refine migrate --version=4
Migrated to version: 4.
$ php oil refine migrate --version=5
Migrated to version: 5.
$ php oil refine migrate:down
Migrated to version: 4.
$ php oil refine migrate:up
Migrated to version: 5.
```
--------------------------------
### Get From Address
Source: https://fuelphp.com/docs/packages/email/methods.html
Retrieves the configured 'from' email address.
```APIDOC
## GET /api/email/from
### Description
Returns the configured 'from' address.
### Method
GET
### Endpoint
/api/email/from
### Parameters
_None_
### Response
#### Success Response (200)
- **string** - The 'from' email address.
#### Response Example
```json
{
"from_address": "sender@example.com"
}
```
```
--------------------------------
### Load a Package
Source: https://fuelphp.com/docs/classes/package.html
Use this method to load one or more packages at runtime. A PackageNotFoundException is thrown if the package cannot be found. You can specify a custom path for the package.
```php
Package::load('orm');
```
```php
Package::load('parser', '/path/to/packages/dir/');
```
```php
Package::load( array('First' => PKGPATH.'my'.DS.'first'.DS, 'Last' => PKGPATH.'my'.DS.'last'.DS) );
```
```php
Package::load('awesome'); // Throws a PackageNotFoundException
```
--------------------------------
### Create Database
Source: https://fuelphp.com/docs/classes/database/dbutil.html
Creates a new database. Optionally specify a charset and whether to use IF NOT EXISTS. Throws Database_Exception on failure.
```php
// Create a database named `my_database`
DBUtil::create_database('my_database');
// Catch the exception
try
{
DBUtil::create_database('my_database');
}
catch(\\\Database_Exception $e)
{
// Creation failed...
}
// You can also set a default charset.
// CREATE DATABASE IF NOT EXISTS `new_database` DEFAULT CHARACTER SET 'utf8'
DBUtil::create_database('new_database', 'utf8');
// CREATE DATABASE IF NOT EXISTS `new_database` DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'
DBUtil::create_database('new_database', 'utf8_unicode_ci');
```
--------------------------------
### Get BCC Addresses
Source: https://fuelphp.com/docs/packages/email/methods.html
Retrieves all configured 'bcc' email addresses.
```APIDOC
## GET /api/email/bcc
### Description
Returns the configured 'bcc' addresses.
### Method
GET
### Endpoint
/api/email/bcc
### Parameters
_None_
### Response
#### Success Response (200)
- **array** - An array of 'bcc' email addresses.
#### Response Example
```json
{
"bcc_addresses": [
"bcc1@example.com",
"bcc2@example.com"
]
}
```
```
--------------------------------
### Get CC Addresses
Source: https://fuelphp.com/docs/packages/email/methods.html
Retrieves all configured 'cc' email addresses.
```APIDOC
## GET /api/email/cc
### Description
Returns the configured 'cc' addresses.
### Method
GET
### Endpoint
/api/email/cc
### Parameters
_None_
### Response
#### Success Response (200)
- **array** - An array of 'cc' email addresses.
#### Response Example
```json
{
"cc_addresses": [
"cc1@example.com",
"cc2@example.com"
]
}
```
```
--------------------------------
### Accept Command Line Options
Source: https://fuelphp.com/docs/classes/cli.html
The option method retrieves command-line options. It accepts the option name and an optional default value if the option is not provided.
```bash
$ php index.php user -v --v -name=John --name=John
```
--------------------------------
### Get Email To Addresses
Source: https://fuelphp.com/docs/packages/email/methods.html
Retrieves all configured 'to' email addresses.
```php
// returns the addresses set by to()
$to = $email->get_to();
```
--------------------------------
### Create a database table with DBUtil
Source: https://fuelphp.com/docs/classes/database/dbutil.html
Creates a new table with specified fields, primary keys, and foreign key constraints. The second example demonstrates using DB::expr to prevent escaping of default values.
```php
\DBUtil::create_table(
'users',
array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'name' => array('type' => 'text'),
'email' => array('constraint' => 50, 'type' => 'varchar'),
'title' => array('constraint' => 50, 'type' => 'varchar', 'default' => 'mr.'),
'password' => array('constraint' => 125, 'type' => 'varchar'),
),
array('id'), false, 'InnoDB', 'utf8_unicode_ci',
array(
array(
'constraint' => 'constraintA',
'key' => 'keyA',
'reference' => array(
'table' => 'table',
'column' => 'field',
),
'on_update' => 'CASCADE',
'on_delete' => 'RESTRICT'
),
array(
'key' => 'keyB',
'reference' => array(
'table' => 'table',
'column' => array(
'fieldA',
'fieldB'
),
),
),
),
);
```
```php
\DBUtil::create_table('users', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'name' => array('type' => 'text'),
'email' => array('constraint' => 50, 'type' => 'varchar'),
'title' => array('constraint' => 50, 'type' => 'varchar', 'default' => 'mr.'),
'created' => array('type' => 'timestamp', 'default' => \DB::expr('CURRENT_TIMESTAMP')),
'password' => array('constraint' => 125, 'type' => 'varchar'),
), array('id'));
```
--------------------------------
### Create Response with Status and Headers
Source: https://fuelphp.com/docs/classes/response.html
Instantiate a Response object with a body, HTTP status code, and custom headers.
```php
$headers = array (
'Cache-Control' => 'no-cache, no-store, max-age=0, must-revalidate',
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Pragma' => 'no-cache',
);
$response = new Response($body, 404, $headers);
```
--------------------------------
### Get Email From Address
Source: https://fuelphp.com/docs/packages/email/methods.html
Retrieves the configured 'from' email address.
```php
// returns the address set by from()
$from = $email->get_from();
```
--------------------------------
### Get Validation Errors
Source: https://fuelphp.com/docs/classes/fieldset/fieldset.html
Retrieves input values that failed validation.
```php
$errors = $article_form->error();
```
--------------------------------
### Scaffold MVC with Migrations
Source: https://fuelphp.com/docs/packages/oil/generate.html
Generate a full MVC stack (Model, Views, Controller) along with a database migration using the 'scaffold' command. This is useful for quickly setting up new features.
```bash
$ php oil g scaffold monkey name:string description:text
Created model: APPPATH/classes/model/monkey.php
Created migration: APPPATH/migrations/003_create_monkeys.php
Created controller: APPPATH/classes/controller/monkeys.php
Created view: APPPATH/views/monkeys/index.php
Created view: APPPATH/views/monkeys/view.php
Created view: APPPATH/views/monkeys/create.php
Created view: APPPATH/views/monkeys/edit.php
Created view: APPPATH/views/monkeys/_form.php
```
--------------------------------
### Get Fieldset configuration
Source: https://fuelphp.com/docs/classes/fieldset/fieldset.html
Retrieves the current configuration settings for the Fieldset.
```php
$config = $article_form->get_config();
```
--------------------------------
### Get Request Method
Source: https://fuelphp.com/docs/classes/request/request.html
Retrieves the HTTP method associated with the request.
```php
// Get the request method on a forged request
$method = Request::main()->get_method();
```
--------------------------------
### Response Class Initialization
Source: https://fuelphp.com/docs/classes/response.html
Demonstrates how to create a new Response object with a body, status code, and headers.
```APIDOC
## Response Class Initialization
### Description
Instantiate the Response class with a body, status code, and optional headers.
### Method
Constructor
### Endpoint
N/A (Class instantiation)
### Request Example
```php
// With body and status
$response = new Response($body, 404);
// With body, status, and headers
$headers = array (
'Cache-Control' => 'no-cache, no-store, max-age=0, must-revalidate',
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
'Pragma' => 'no-cache',
);
$response = new Response($body, 404, $headers);
```
### Response
#### Success Response (200)
- **Response object** (object) - A new instance of the Response class.
#### Response Example
```php
// Example of a Response object instantiation
$response = new Response('Page not found', 404);
```
```
--------------------------------
### dump_tree()
Source: https://fuelphp.com/docs/packages/orm/model/nestedset.html
Returns the entire tree structure starting from the current object.
```APIDOC
## dump_tree()
### Description
The dump_tree method returns the entire tree, using the current object as root node into a multi-dimensional array.
### Parameters
- **$as_object** (boolean) - Optional - Default: false. If true, returns a hierarchical tree of objects.
- **$children** (string) - Optional - Default: 'children'. Property or array key name for child nodes.
- **$path** (string) - Optional - Default: 'path'. Property name for the path to the node.
- **$pathuri** (string) - Optional - Default: null. Creates a property prefixed with 'path_' containing the URI path.
### Returns
- **Mixed** - Multi-dimensional array or the current object with added children.
```
--------------------------------
### Create and Configure Pagination Instance
Source: https://fuelphp.com/docs/classes/pagination.html
Use the forge method to create a new pagination instance with custom configuration. Specify the instance name and an array of configuration options.
```php
Pagination::forge('mypagination', array(
'pagination_url' => 'http://docs.fuelphp.com/',
'uri_segment' => 2,
'total_items' => 10,
'per_page' => 20,
));
```
--------------------------------
### Install Mailgun Driver
Source: https://fuelphp.com/docs/packages/email/usage.html
Add the Mailgun dependency to composer.json and update the project.
```json
"mailgun/mailgun-php": "1.6"
```
```bash
$ composer update
```
--------------------------------
### Define Migration Schema
Source: https://fuelphp.com/docs/general/migrations.html
Example of a migration file defining table creation and deletion. Ensure the prefix is incremental and unique.
```php
namespace Fuel\Migrations;
class Example
{
function up()
{
\DBUtil::create_table('posts', array(
'id' => array('type' => 'int', 'constraint' => 5),
'title' => array('type' => 'varchar', 'constraint' => 100),
'body' => array('type' => 'text'),
), array('id'));
}
function down()
{
\DBUtil::drop_table('posts');
}
}
```
--------------------------------
### Example Generated Migration
Source: https://fuelphp.com/docs/packages/oil/generate.html
The migration file created automatically alongside the model.
```php
namespace Fuel\Migrations;
class Create_posts
{
public function up()
{
\DBUtil::create_table('posts', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'title' => array('constraint' => 50, 'type' => 'varchar'),
'body' => array('type' => 'text'),
'user_id' => array('constraint' => 11, 'type' => 'int'),
'created_at' => array('type' => 'datetime'),
), array('id'));
}
public function down()
{
\DBUtil::drop_table('posts');
}
}
```
--------------------------------
### Load configuration files
Source: https://fuelphp.com/docs/classes/config.html
Reads configuration files into the system with options for grouping, reloading, and overwriting.
```php
// This merges the "custom" config file in with the root config.
Config::load('custom');
// This loads the "custom" config file in a group named "custom".
Config::load('custom', true);
// This loads the "custom.ini" config file in a group named "custom".
Config::load('custom.ini', true);
// This loads the "custom" config file in a group named "foo".
Config::load('custom', 'foo');
// This loads the "custom" config from a module called foo in a group named "bar"
Config::load('foo::custom', 'bar');
```