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
Post a Comment