Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @@ schema
- sf_guard_user_profile:
- columns:
- id: { type: integer, primary: true }
- name: { type: string(255) }
- country: { type: string(2) }
- email: { type: string(255), email: true }
- email_hidden: { type: boolean, default: true }
- signature: { type: string(255) }
- relations:
- sfGuardUser: { local: id, foreign: id, foreignAlias: profile, type: one, foreignType: one }
- @@ Action
- public function executeEditProfile(sfWebRequest $request) {
- $this->form = new profileForm($this->getUser()->getGuardUser());
- if ($request->isMethod('post')) {
- $this->form->bind(
- $request->getParameter($this->form->getName()),
- $request->getFiles($this->form->getName())
- );
- if ($this->form->isValid()) {
- $this->form->save();
- $this->getUser()->setFlash('notice', 'Je profiel is opgeslagen!');
- }
- else {
- $this->getUser()->setFlash('error', 'Je profiel is niet opgeslagen. Kijk hieronder wat er fout zou kunnen zijn gegaan');
- }
- }
- }
- @@ Form class
- class sf_guard_user_profileForm extends Basesf_guard_user_profileForm
- {
- public function configure()
- {
- unset($this['id']);
- $this->widgetSchema['country'] = new sfWidgetFormI18nChoiceCountry();
- $this->setDefault('country', 'NL');
- $this->widgetSchema['signature'] = new sfWidgetFormTextarea();
- $this->widgetSchema['avatar'] = new sfWidgetFormInputFile();
- $this->validatorSchema['name'] = new sfValidatorString(array('required' => false, 'max_length' => 40));
- $this->validatorSchema['signature'] = new sfValidatorString(array('required' => false, 'max_length' => 120));
- $this->validatorSchema['avatar'] = new sfValidatorFile(array(
- 'required' => false,
- 'path' => sfConfig::get('sf_upload_dir').'/avatars',
- 'mime_types' => 'web_images',
- ));
- $this->widgetSchema->setLabels(array(
- 'email' => 'E-mailadres',
- 'email_hidden' => 'E-mailadres verbergen voor andere gebruikers',
- 'name' => "Naam",
- 'country' => "Land",
- ));
- }
- }
- @@ Template
- <h2>Profiel bewerken:</h2>
- <form method="post" action="<?php echo url_for('edit_my_profile') ?>" />
- <?php include_partial('profile_form', array('form' => $form))?>
- <input type='submit' value='Opslaan' />
- </form>
- @@ Partial 'profile_form'
- <?php
- echo $form->renderGlobalErrors();
- ?>
- <h3>Inloggegevens</h3>
- <table style='width: auto'>
- <tr>
- <th>Gebruikersnaam</th>
- <td><?php echo $form->getObject()->getUsername() ?></td>
- </tr>
- <tr>
- <th><?php echo $form['password']->renderLabel(); ?></th>
- <td><?php echo $form['password']->renderError() . $form['password']; ?></td>
- <td rowspan="2">Leeg laten indien ongewijzigd</td>
- </tr>
- <?php echo $form['password_confirmation']->renderRow(); ?>
- <tr>
- <th><?php echo $form['profile']['email']->renderLabel(); ?></th>
- <td><?php echo $form['profile']['email']->renderError() . $form['profile']['email']; ?></td>
- <td><?php echo $form['profile']['email_hidden'] . $form['profile']['email_hidden']->renderLabel(); ?></td>
- </tr>
- </table>
- <h3>Persoonlijke gegevens</h3>
- <?php echo $form['profile']->renderError(); ?>
- <table style='width: auto'>
- <?php echo $form['profile']['name']->renderRow(); ?>
- <?php echo $form['profile']['country']->renderRow(); ?>
- </table>
- <h3>Foruminstellingen</h3>
- <table style='width: auto'>
- <?php echo $form['profile']['signature']->renderRow(); ?>
- <tr>
- <th><?php echo $form['profile']['avatar']->renderLabel(); ?></th>
- <td>
- <div><?php if ($avatar = $form->getObject()->getProfile()->getAvatar()) { echo $avatar; } else { echo 'Nog geen avatar geüpload'; } ?></div>
- <div><?php echo $form['profile']['avatar']->renderError() . $form['profile']['avatar']; ?></div>
- </td>
- </tr>
- </table>
- <?php echo $form->renderHiddenFields(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement