A little help using Symfony
Can anyone link me to some Symfony resources, they are hard to find. I am having a little trouble understanding how to use it correctly. Like with CodeIgniter to use the security helper you would load it doing this:
$this->load->helper('security');
And you would use its functions you would do something like this:
$data = $this->input->xss_clean($data);
But with Smyfony to redirect someone to a 404 page, you need to use the sfAction class and the redirect404() api. So could anyone explain or link me a good 开发者_JAVA百科tutorial?
I would highly recommend you set aside a few hours and read through the Practical Symfony tutorial. It goes through all the basics from project start to end.
Symfony, although a great framework, has a steep learning curve. This tutorial really helps you understand how it works, from the basics to more advanced stuff.
http://www.symfony-project.org/book/1_2/06-Inside-the-Controller-Layer#chapter_06_sub_skipping_to_another_action (scroll down a few paragraphs)
Using
http://www.symfony-project.org/api/1_4/sfAction
You have access to a number of 404 redirection methods (redirect404, forward404, forward404If, forward404Unless) which are detailed on the link above. You have access to all of these methods from within your actions:
public function executeAction(sfWebRequest $request)
{
$this->forward404();
}
I would recommend using forward404 instead of redirect404 as the latter will push the redirection back to the browser and show your user the 404 page's URL instead of the URL they attempted to access.
Configuring
You can configure the module and action that should be executed when a 404 is triggered in your application's config/settings.yml
like this:
all:
.actions:
error_404_module: my_module # To be called when a 404 error is raised
error_404_action: my_action # Or when the requested URL doesn't match any route
Update:
For general information on Symfony check out the three books they have available online: http://www.symfony-project.org/doc/1_4/, 'Practical Symfony' being a great place to get started. There is also a complete API reference available: http://www.symfony-project.org/api/1_4/.
精彩评论