S
S
sawa42016-11-16 09:59:40
Laravel
sawa4, 2016-11-16 09:59:40

Why does the view not see the controller method if the controller is in a variable. ErrorException in UrlGenerator.php?

Hello guys!
There is this piece of code:

//где то в котроллере 
$controllerName = get_class($this);
//во view
<a href="{{ action ($controllerName.'@getPart',  array($obj->id, 'main')) }}">

It does not work, although it sees the controller class and there is clearly this method:

ErrorException in UrlGenerator.php line 609:
Action App\Http\Controllers\App\Http\Controllers\[email protected] not defined. (View: ...

And if you write like this:
<a href="{{ action ('[email protected]',  array($obj->id, 'main')) }}">

That all works.
Has anyone experienced this? Any ideas?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Semenko, 2016-11-16
@abler98

Because get_class returns the fully qualified class name (along with namespace). And why do it at all?

S
Stanislav Pochepko, 2016-11-16
@DJZT

Pay attention to this

Action App\Http\Controllers\App\Http\Controllers\[email protected]

A
Alexander, 2016-11-16
@xpert13

Any ideas?

Yes - do not call controller methods from views. The way you want to do it is not the "MVC way".
If I understand your code correctly, then you need to use route instead of action and pass the name of the route accordingly to get the link.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question