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

  1. user login to the apps
  2. user pick which movie he / she want to review
  3. he / she put some review on it
  4. 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

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

<?php echo form_error('username'); echo "

"; echo label_for('username', __('username:')); echo "
"; echo input_tag('username', $sf_data->get('sf_params')->get('username')); echo "

"; ?>
<?php echo form_error('password'); echo "

"; echo label_for('password', __('password:')); echo "
"; echo input_password_tag('password'); echo "

"; ?>
<?php echo submit_tag(__('Sign in')); 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 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'));

    $c  = new Criteria();
    $this->reviews= ReviewsPeer::doSelect($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();
      $reviews= ReviewsPeer::retrieveByPk($this->getRequestParameter('id'));

    $reviews->setMovieId($this->getRequestParameter('movie_id') ? $this->getRequestParameter('movie_id') : null);


    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


2 thoughts on “Symfony Apps Part II

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s