pceuropa / yii2-menu

Menu menager, dynamic Yii2 widget. Active menu items
https://pceuropa.net/yii2-extensions/yii2-menu
MIT License
27 stars 17 forks source link

Getting menu by humanized name #6

Closed rgen3 closed 7 years ago

rgen3 commented 7 years ago

Adds the possibility to get the meny not only by id, but also by name

pceuropa commented 7 years ago

Next good idea and good work. I'm ready to merge these commits.

Action view generate little bug. $_GET['variable'] every time is string, and condition is_int($id) in Model::findModel($id) have problem. First simple solution, change

public function actionView($id){ $m =Model::findModel($id);`

for this

$m = Model::find($id)->one();

About Exception, I'll think later.

rgen3 commented 7 years ago

Action view generate little bug. $_GET['variable'] every time is string

I've thought about that today we can fix it by checking the $id by regex

public static function findModel($id){ if (is_int($id)) { $where = ['menu_id' => $id]; }

replacing by

public static function findModel($id){ if (preg_match('#[\d]+#'$id)) { $where = ['menu_id' => $id]; }

I think it fixes the bug

rgen3 commented 7 years ago

Wow! You've merged all my commits - thanks ))

pceuropa commented 7 years ago

Why not :)

You implement a lot of interesting changes. It now I plans to change a little. (maybe you already it did)

  1. Change the class and file names migration. (I did it c8143e4 bug until first migration see )
  2. In version 2.1.0 i hide the icons select until as: a) option icons - the last in the list, under input the url. hide icons in LINE DIVIDER b) icons will not break the dropmenu | encode html glyficon in creator/view | more space between link and icon CSS c) in update item section -> will be able to change the icon - it seems to me that another column in the table is needed
  3. possibility change name of menu | input menu_name above section drop to edit/trash | unique attribute menu_name in model

And by the way, why You use preg_match('#\d+#', $id) ? Not preg_match('/\d+/', $id) <- standard. I think, it depends on the preference of language, keyboard

rgen3 commented 7 years ago

Yes, 1,2,3 are good ideas

I used to use # in regex 'cause sometimes it is easier to read regex when you are not schielding slashes

i.e

/http:\/\/example.com\/some\/route\/path /

http://example.com/some/route/path