Back to BaseController class

Method createFileName

public static string
createFileName
(mixed $type, mixed $parts = array())
Create the filename for a resource.
Parameters
  • string $type The resource type to create the filename for.
  • array $parts An associative array of filename information. Optional.
Returns
  • string The filename.
Since
  • 3.0

Method createFileName - Source code

/**
 * Create the filename for a resource.
 *
 * @param   string  $type   The resource type to create the filename for.
 * @param   array   $parts  An associative array of filename information. Optional.
 *
 * @return  string  The filename.
 *
 * @since   3.0
 */
public static function createFileName($type, $parts = array())
{
    $filename = '';
    switch ($type) {
        case 'controller':
            if (!empty($parts['format'])) {
                if ($parts['format'] === 'html') {
                    $parts['format'] = '';
                } else {
                    $parts['format'] = '.' . $parts['format'];
                }
            } else {
                $parts['format'] = '';
            }
            $filename = strtolower($parts['name'] . $parts['format'] . '.php');
            break;
        case 'view':
            if (!empty($parts['type'])) {
                $parts['type'] = '.' . $parts['type'];
            } else {
                $parts['type'] = '';
            }
            $filename = strtolower($parts['name'] . '/view' . $parts['type'] . '.php');
            break;
    }
    return $filename;
}