Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Call to a member function AddCssFile() on null

Because I can not add the css style sheet:

class Widgets_Plugin extends Gdn_Plugin{

    public function assetModel_styleCss_handler ($sender) {
        $Sender->AddCssFile('widgets.css', 'plugins/Widgets');
    }


Fatal Error in Widgets_Plugin.assetModel_styleCss_handler();

Call to a member function AddCssFile() on null
The error occurred on or near: /home/vol11_5/byethost15.com/b15_20493697/tradersvzla.ml/htdocs/plugins/Widgets/default.php
25: class Widgets_Plugin extends Gdn_Plugin{
26: 
27: 
28:     public function assetModel_styleCss_handler ($sender) {
29:         $Sender->AddCssFile('widgets.css', 'plugins/Widgets');
30:     }
31:     
32:     public function base_render_before ($sender) {
33:   

@r_j @vrijvlinder

Regards,

Comments

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    missing closing } maybe ? check syntax coz that is what it looks like .

    I would use this to load css files

    public function base_render_before ($sender) {
     $Sender->AddCssFile('widgets.css', 'plugins/Widgets');
        }
    
  • Options
    edited September 2017
    public function base_render_before ($sender) {
        $Sender->AddCssFile('widgets.css', 'plugins/Widgets');
    
        $controllers = [
            // ControllerName => Modules for Name Controllers.
            'categoriescontroller'  => ['Twitter','Exchange'],
            'discussioncontroller'  => ['Twitter'],
            'discussionscontroller' => ['Dolartoday', 'Twitter']
        ];
    
        if (!array_key_exists($sender->ControllerName, $controllers)) {
            return;
        }
    
        $modules = [
            // Widgest => Class Module Name
            'Twitter'  => 'TwitterModule',
            'Exchange' => 'ExchangeModule',
            'Dolartoday' => 'DolartodayModule'
        ];
    
        $session = Gdn::session();
    
        foreach ($controllers[$sender->ControllerName] as $item) {
            //var_dump($item);
            // do the permission check with "Plugins.Whatever.{$moduleName}.View"
            // attach module with $module = new $modules[$moduleName]();
            if ($session->CheckPermission('Plugins.Widgets.{$item}.View')) {
                $module = new $modules[$item]();
                $sender->addModule($module);
            }
        }
    }
    

    Error Debug:

    Call to a member function AddCssFile() on null
    The error occurred on or near: 
    /home/vol11_5/byethost15.com/b15_20493697/tradersvzla.ml/htdocs/plugins/Widgets/default.php
    
    27:     public function __construct(){
    28:     }
    29:     
    30:     public function base_render_before ($sender) {
    31:         $Sender->AddCssFile('widgets.css', 'plugins/Widgets');
    32:         
    33:         $controllers = [
    34:             // ControllerName => Modules for Name Controllers.
    35:             'categoriescontroller'  => ['Twitter','Exchange'],
    Backtrace:
    

    No works,

    Regards,

  • Options

    jajajaja, that idiot apologize the post wrote sender with the first letter in capital letters,

    Thks,

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    That would not cause an issue as far as I know....

    $Sender is the same thing as $sender . It's a mater of style not function. Vanilla code now requires or at least suggests that it should be $sender . But it should not affect the php function as far as the meaning ...

  • Options

    @vrijvlinder said:
    That would not cause an issue as far as I know....

    $Sender is the same thing as $sender . It's a mater of style not function. Vanilla code now requires or at least suggests that it should be $sender . But it should not affect the php function as far as the meaning ...

    It actually does, since variables in PHP are case sensitive (only methods are case insensitive):

    This line defined an argument $sender

    @terabytefrelance said:
    public function assetModel_styleCss_handler ($sender) {

    And this line references a variable $Sender which !== $sender.

            $Sender->AddCssFile('widgets.css', 'plugins/Widgets');
    

    As long as you stay consistent you can use either $Sender or $sender as you said, but if you mix them bad things happen (as terabytefrelance figured out).

Sign In or Register to comment.