This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

bj.payne10844
bj.payne10844

I am trying to create my own bootstrap class where I will pull in several other classes e.g. the php curl class. This needs to be accessed inside a template so I need to have a use statement in the PHP section of the template. I have a plugin that is namespaced however I keep getting an exception that the class cannot be found.

My directory structure looks like this:

.plugins

|-- npb

|--|-- intranet

|--|--|-- classes

|--|--|--|--Bootstrap.php

|--|--|-- Plugin.php

Plugin.php file

<?php namespace Npb\Intranet;

use Backend;
use System\Classes\PluginBase;

class Plugin extends PluginBase
{
    public function pluginDetails()
    {
        return [
            'name' => 'Intranet Bootstrap Classes',
            'description' => 'Provides bootstrap Classes for Intranet Functionality in the CMS.',
            'author' => 'Web Development Team',
            'icon' => 'npb-icon'
        ];
    }
}

Bootstrap.php file

<?php namespace Npb\Intranet\Classes;

class Bootstrap
{
    public static function getRate()
    {
        return '1.125%';
    }
}

PHP section of template

<?php

use Npb\Intranet\Classes\Bootstrap;

function onStart()
{
    $user = Db::select("SELECT * FROM employee WHERE id = ?", [1]);

    $this['firstName'] = $user[0]->name;

    $this['rates'] = Bootstrap::getRate();

    header('X-UA-Compatible: IE=edge,chrome=1');

}
?>

Let me know if someone wants the stack trace.

Thanks! Ben

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.