Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Director::direct('SOME_URL') requires a model as second parameter...


Go to End


5 Posts   1434 Views

Avatar
bxxxxx

Community Member, 8 Posts

5 January 2014 at 6:15am

I try to redirect from one page to another and I get a Php-Notice about a missing model parameter

[Notice] Undefined variable: model
POST /home/UserDataForm

Line 145 in /srv/htdocs/framework/control/Director.php
 

I tried to add something like

$model = new Page();

but then, it outputs a blank screen.

I know, this is a Notice and almost invisible on production but it keeps me in Dev-Mode from having a clean output.

Is there another way to redirect a user from A to B?

Thank you very much in advance.

Best regards
Stefan

Avatar
dhensby

Community Member, 253 Posts

5 January 2014 at 8:34am

Director::direct() lsnt used for browser redirections.

You want redirect on a controller object or response object

Avatar
bxxxxx

Community Member, 8 Posts

5 January 2014 at 8:54am

Ok,

I think I found it.

I had in mind some SS 2.4 snippets

Director::redirect('SOME_URL');

but this is now:

$this->redirect('SOME_URL');

as long as I am in a Controller-Object.

Is that right?

Avatar
Bimble

Community Member, 16 Posts

8 January 2014 at 1:39am

What if you are not in a Controller object?

For example, I want to redirect after executing custom Gridfield row action?

Avatar
martimiz

Forum Moderator, 1391 Posts

8 January 2014 at 4:27am

Edited: 08/01/2014 4:28am

Afaik you are always 'in a controller', meaning there's always a Controller active, based on a URL, making sure the work gets done...

You can find the current controller by using Controller::curr()