In short
No, you can't, but you could define your own view subclass if you want to wrap this functionality nicely.
Native Slim
I just checked out Slim's source code (which is really, really, .. Slim), and you are using its View object which wraps a Set object. Neither supplies this functionality, since the internal array isn't exposed and the all() and getData() methods don't return the internal array by reference, so this won't work:
$view->all()['auths'][] = 'newauth';
You can reach what you want directly with the following nasty one-liner:
$view->set('auths', array_merge($view->get('auths'), ['newauth']));
Roll your own View subclass
Much better would be to define your own custom view that makes this possible!
-
Define a custom view class
class CustomView extends \Slim\View
{
public function pushProperty($key, $value)
{
$array = $this->get($key);
$array[] = $value;
$this->set($key, $array);
}
}
Note: this method blindly assumes that the current value is an array. You will want to add some checks!
-
Assign it as the default view object in your Slim app when you create it.
$app = new Slim\Slim(array('view' => new CustomView()));
-
And start using it :)
$app->view->set("auths",["user","poweruser"]);
$app->view->pushProperty('auths','newauth'); // this will now work. Yay :)