Symfony Apps Part II
Yesterday we have try to build a simple application based on symfony, now we’ll try to make those apps more usable what we have left now is user management
the sequence if users want to make a movie reviews is
- user login to the apps
- user pick which movie he / she want to review
- he / she put some review on it
- he can see the reviews.
in the previous sample, we’ve only build the CRUD application, which base of almost every application. To make it simple, we will use a plugin for symfony called sfGuardPlugin. It’s a plugin to ease the pain of user management and save a lot of our time.
first of all you’ve to download the plugin sfGuardPlugin
and follow the instruction found in http://trac.symfony-project.com/attachment/wiki/sfGuardPlugin/
if you succeeded installed the plugin, you should see the login screen when you trying to access your module.
but the page is a plain one, let’s try to change it a little bit first of all you have to create a folder called sfGuardAuth in your module folder, the module folder it self is on the apps/samples
inside of the sfGuardAuth, create a new folder named templates. Now fire up your favorite editor and create a new PHP file, we have to name it signinSuccess.php and secureSuccess.php
let’s create it like this
";
echo input_tag('username', $sf_data->get('sf_params')->get('username'));
echo "
";
?>
";
echo input_password_tag('password');
echo "
";
?>
";
echo link_to(__('Forgot your password?'), '@sf_guard_password', array('id' => 'sf_guard_auth_forgot_password'))
?>
that’s for the login page, now what we want is user pick the movie and then give their review of the movie.
first of all let’s change the listSuccess.php inside in apps/samples/modules/movie/template, the default identifier from the CRUD generator is ID. So if you click on id, it will go to show page, so we’ll gonna change the listSuccess.php so instead of ID user click on the Movie name.
movie
Movie name
Movie synopsis
Movie released
Movie produsen
Movie director
getMovieName(), 'movie/show?id='.$movie->getId()) ?>
getMovieSynopsis() ?>
getMovieReleased() ?>
getMovieProdusen() ?>
getMovieDirector() ?>
those are the new listSuccess.php, and we should change a little bit file editSuccess.php,we need to create an hidden field contained user_id add this line below
next is to change the showSuccess.php and this is a new one code snippet.
getId()) ?>
Critic 1): ?>s
Posted by getsfGuardUser()->getUserName() ?> On getCreatedAt()) ?>
getReviews()) ?>
getId())
?>
OK we just need to do a little more work in code. let’s edit the action.class.php, this file is inside of apps/samples/movie/action. Edit the function executeShow() to the following
public function executeShow()
{
$this->movie = MoviePeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($this->movie);
$c = new Criteria();
$c->add(ReviewsPeer::MOVIE_ID,$this->getRequestParameter('id'));
$c->addAscendingOrderByColumn(ReviewsPeer::CREATED_AT);
$this->reviews= ReviewsPeer:
oSelect($c);
}
okay, that would be the last file we need to edit in movie directory. what we need to edit is another action.class.php located in app/samples/module/review and make a little bit change in function executeUpdate() so the function will look like
public function executeUpdate()
{
if (!$this->getRequestParameter('id'))
{
$reviews= new Reviews();
}
else
{
$reviews= ReviewsPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($reviews);
}
$reviews->setId($this->getRequestParameter('id'));
$reviews->setMovieId($this->getRequestParameter('movie_id') ? $this->getRequestParameter('movie_id') : null);
$reviews->setReviews($this->getRequestParameter('reviews'));
$reviews->setRating($this->getRequestParameter('rating'));
$reviews->setUserId($this->getUser()->getGuardUser()->getId());
$reviews->save();
return $this->redirect('movie/show?id='.$reviews->getMovieId());
}
now we’ve done, but the application still need a lot of improvement but i do hope that will give you a hint of how easy is to customize symfony
Update :
for live example you can try it here or you can download here
the username and password is “admin” without quote
PERTAMAX!!
*
*komen dulu baru nyoba
[...] Symfony Apps Part II [...]