How to use Menu UI without creating a layout object first?


Currently, I’m using Menu UI like this

$app = new \atk4\ui\App();
$m = $layout->add('Menu');
$m->addItem('foo', 'foo.php');

Is it possible to use the Menu object directly without creating a layout first?

$m = new \atk4\ui\Menu();
$m->addItem('foo', 'foo.php');
$m->add(['Dropdown', 'huhhuh', 'js'=>['on'=>'hover']])->setSource(['a', 'b', 'c']);

Above returns “member function addClass undefined” error.



Fixed above by init the Dropdown object instead with the following.

use \atk4\ui\Dropdown;
$m->add(new Dropdown(['huhhuh', 'js'=>['on'=>'hover']]))->setSource(['a', 'b', 'c']);

However, the following now returns the exactly the same error

$gr = $m->addGroup('Products');


Fatal error: Uncaught Error: Call to a member function addClass() on array in /Library/WebServer/Documents/agiletoolkit/vendor/atk4/ui/src/Menu.php:102 Stack trace: #0

And there isn’t a Group class. Any pointers please?



I haven’t tried but you should be able to use any component without App/Layout by simply calling it’s init().

$menu = new Menu();

For basic objects you can leave init() to be called by render().


also the way you pass [‘js’] is unusual, it might cause problems. After you call init() you can use js(),


Thank you @romaninsh, init() worked. Should’ve read the docs more carefully.

I’m trying to integrate Agile UI components (only) with other PHP framework (Laravel and Symfony), so did not need the rest of Agile framework.

I wonder if there’s any drawback with the UI components only approach? The documentation didn’t go in-depth.




There is no drawback really. UI relies on models as it implements large portion of the logic. I’d really love to see integration with Laravel, please do share your project. You can also look into

Agile UI draws a lot of benefits from integration with Agile Data, here is excerpt form the doc:

Usage with Model

A most common use of form is if you have a working Model (

// Form will automatically add a new user and save into the database
$form = $app->add('Form');
$form->setModel(new User($db));

The basic 2-line syntax will extract all the required logic from the Model including:

You can probably build bridge with Eloquent, but there are simply too many things that Eloquent cannot do. Here is comparison:

Laravel gives you a choice, so you can use Agile UI + Agile Data + Rest of Laravel, which I think is the best use case.

if you need any help, give me a shout at


Thank you, you’ve been very helpful! So far I’m only playing with the components, will consider more serious use with the framework as I’m getting familiar with it.