Reputation: 13
I have subfolders "agent" and "admin" in controllers folder in Yii2.
When I type localhost/projectname/agent/dashboard
, it runs fine, where "dashboard" is a controller in "agent" folder.
But when I type localhost/projectname/agent
it says page not found. What is the solution to this? I also know this type of work should be handled in modules.
Upvotes: 0
Views: 1212
Reputation: 1153
Yii is looking for an AgentController
in the main controllers directory with that second URL ("http://localhost/projectname/agent").
You can use custom URL rules to ensure it hits the AgentController
in your "agent" folder instead. http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#url-rules
Something like:
"agent" => "agent/index"
should do the trick. Make sure to change "index" to something else if you want a differently-named action to be called for that URL.
Upvotes: 2