I have a ProjectsController that works fine with the usual add/edit/view/index.
I can successfully view a project with /projects/view/$id.
Each project has also a unique name, and I would like to refer to each project even with a url like /projects/$name.
I thought about extending the AppError on the missingAction and do the required operations (code in the "footer" of the mail).
requestAction retrieve successfully the project detail with the right thtml but no layout is rendered.
How can I render the correct page without doing a redirect?
Another question: is it possible to specify a different ErrorHandler for a controller? So it could be possible to avoid ugly switch. Something like setting the errorHandler variable inside the controller.
Thanks a lot Davide
<?php /* * app/error.php */ class AppError extends ErrorHandler{ function missingAction($params){ switch($params["className"]){ case "ProjectsController": loadModel("Project"); $model = new Project(); $data = $model->findByName($params["action"]); echo $this->requestAction("/projects/view/".$data["Project"]["id"], array("return")); break; default: parent::missingAction($params); break; }
}
}
?>
-- Live life like you're gonna die. Because you're gonna. William Shatner
> I wrote a code (at the bottom) that in case of missingAction will search
> in the database and if found then render the proper view.
> Everything works fine except when I turn DEBUG=0 (production setup). Now
> cake always render the 404 without entering the AppError::missingAction().
> On Apr 28, 10:31 am, "Davide" <d...@linux.it> wrote:
> > I wrote a code (at the bottom) that in case of missingAction will search
> > in the database and if found then render the proper view.
> > Everything works fine except when I turn DEBUG=0 (production setup). Now
> > cake always render the 404 without entering the AppError::missingAction().
Joel Perras wrote: > ... > For that, use: > (app/config/routes.php) > Router::connect('/projects/:name', array('action'=>'view', > 'name'=>null)); > ...
Thanks Joel,
unfortunly Router::connect() seems not to work for me. Cake 1.1.18. It's simply ignored. But you gave me a hint and using $Route->connect(...) I can achieve my goal.
However I have to add a $Route->connect() for each action and it's not beautiful and subject to errors. I'm thinking in a workaround solution. I will post it here.
Thanks for the hint. Davide
-- Live life like you're gonna die. Because you're gonna. William Shatner
Davide wrote: > unfortunly Router::connect() seems not to work for me. Cake > 1.1.18. It's simply ignored. But you gave me a hint and using > $Route->connect(...) I can achieve my goal.
> However I have to add a $Route->connect() for each action and it's not > beautiful and subject to errors. I'm thinking in a workaround > solution. I will post it here.
Worked a bit on it, but it took too much time for achieving a good solution so I finally opted for mapping each action in routes.php and managing the alias in the view action. So finally here is the code[1].
Now I'm asking myself about the utility of AppError if it's disabled in a production environment. Can someone answer me maybe with a scenario?