i have recently update to php 7.0.14 in freeBSD 11 and i get error about :
PHP Deprecated Warning – yii\base\ErrorException Non-static method common\models\Menus::getMenu() should not be called statically
And
PHP Deprecated Warning – yii\base\ErrorException Non-static method common\models\Menus::getRoute() should not be called statically
here is the part of code :
public function getMenu()
{
$menu = Menus::find()
//->andWhere(['<>','parent',0])
->orderBy('order')
->all();
$data=[];
foreach($menu as $menus)
{
if (isset($menus->parent)) {
$submenu[$menus->id]=['label' => ($menus['menu_path'])?
Html::img(Yii::$app->glide->createSignedUrl([
'glide/index',
'path' => $menus['menu_path'],
'w' => 50
], true),['title' =>$menus['name']]) :
$menus['name'],'url'=>$menus['route'], 'options' => [
['class' => 'nav nav-pills nav-stacked'],
['class' => 'nav nav-second-level'],
['class' => 'nav nav-third-level']
],
];
$data[$menus->parent]['items']=$submenu;
}else {
# menu
$data[$menus->id]= ['label' => ($menus['menu_path'])?
Html::img(Yii::$app->glide->createSignedUrl([
'glide/index',
'path' => $menus['menu_path'],
'w' => 50
], true),['title' =>$menus['name']]) : $menus['name']
,'url'=>$menus['route']
];
}
}
return $data;
}
and
public function getRoutes()
{
$controllerlist = [];
if ($handle = opendir('../controllers')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && substr($file, strrpos($file, '.') - 10) == 'Controller.php') {
$controllerlist[] = $file;
}
}
closedir($handle);
}
asort($controllerlist);
$fulllist = [];
foreach ($controllerlist as $controller):
$handle = fopen('../controllers/' . $controller, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (preg_match('/public function action(.*?)\(/', $line, $display)):
if (strlen($display[1]) > 2):
$r1 = str_replace('Controller','',$controller);
$rs = str_replace('.php','',$r1);
$fulllist[strtolower($rs)][] = strtolower($rs.'/'.$display[1]);
endif;
endif;
}
}
fclose($handle);
endforeach;
$routes=[];
foreach($fulllist as $row)
{
foreach($row as $r){
$routes[] = $r;
}
}
return $routes;
}
Alternatively, i've declare them to be static function by changing
public function getRoute and public static function getMenu
to
public static function getRoute and public static function getMenu
in the model function, However this will affect other places were the functions are called.