Welcome Guest, Not a member yet? Register   Sign In
Define/include "globally available" arrays and functions
#18

(This post was last modified: 06-07-2021, 12:03 PM by tomsenner.)

app/_own_vars_functions.php
PHP Code:
<?php

function mkTabName($txt){
    $txt explode(".",$txt);
    $txt str_replace("_and_"," &amp; ",$txt[0]);
    return ucFirst(str_replace("_"," ",$txt));
}

?>

app/Controllers/Test.php

PHP Code:
<?php

namespace App\Controllers;

class 
Test extends BaseController
{

    public function 
test()
    {

            return 
view("Home/index.php");

    }



app/Views/Home/index.php
PHP Code:
<?= $this->extend("_layouts/default"?>

<?= $this->section("title"?>Home<?= $this->endSection() ?>

<?= $this->section("test"?>

    <h1>Home</h1>

Test <?= mkTabName("Test.php-name"?>

<?= $this->endSection() ?>

app/Config/Autoload.php
PHP Code:
<?php

namespace Config;

use 
CodeIgniter\Config\AutoloadConfig;

/**
 * -------------------------------------------------------------------
 * AUTO-LOADER
 * -------------------------------------------------------------------
 *
 * This file defines the namespaces and class maps so the Autoloader
 * can find the files as needed.
 *
 * NOTE: If you use an identical key in $psr4 or $classmap, then
 * the values in this file will overwrite the framework's values.
 */
class Autoload extends AutoloadConfig
{
    
/**
     * -------------------------------------------------------------------
     * Namespaces
     * -------------------------------------------------------------------
     * This maps the locations of any namespaces in your application to
     * their location on the file system. These are used by the autoloader
     * to locate files the first time they have been instantiated.
     *
     * The '/app' and '/system' directories are already mapped for you.
     * you may change the name of the 'App' namespace if you wish,
     * but this should be done prior to creating any namespaced classes,
     * else you will need to modify all of those classes for this to work.
     *
     * Prototype:
     *
     *   $psr4 = [
     *       'CodeIgniter' => SYSTEMPATH,
     *       'App'           => APPPATH
     *   ];
     *
     * @var array<string, string>
     */
    
public $psr4 = [
        
APP_NAMESPACE => APPPATH// For custom app namespace
        
'Config'      => APPPATH 'Config',
    ];

    
/**
     * -------------------------------------------------------------------
     * Class Map
     * -------------------------------------------------------------------
     * The class map provides a map of class names and their exact
     * location on the drive. Classes loaded in this manner will have
     * slightly faster performance because they will not have to be
     * searched for within one or more directories as they would if they
     * were being autoloaded through a namespace.
     *
     * Prototype:
     *
     *   $classmap = [
     *       'MyClass'   => '/path/to/class/file.php'
     *   ];
     *
     * @var array<string, string>
     */
    
public $classmap = [];


    public 
$files = [ ROOTPATH 'app/_own_vars_functions.php' ]; 


Reply


Messages In This Thread
RE: Define/include "globally available" arrays and functions - by tomsenner - 06-07-2021, 12:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB