php - Yii 2 - using custom helpers -


i'm trying use custom helper class create under frontend/components/helper (helper.php)

the content of file like:

<?php namespace frontend\components\helper;  class helper {      public static function helpergreetings() {         echo("hello helper");     } } ?> 

and on sitecontroller.php have following:

use frontend\components\helper;  class sitecontroller extends controller {     public function actionindex()     {         helper::helpergreetings();         return $this->render('index');     } } 

what should have working?

btw, error unknown class – yii\base\unknownclassexception

unable find 'frontend\components\helper' in file: /users/foo/sites/bar.dev/frontend/components/helper.php. namespace missing? 

change namespace in helper class

namespace frontend\components\helper; 

to

namespace frontend\components; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -