Witam.

Otóż chciałbym napisać backend po swojemu, nie lubię wygenerowanego. I tutaj moje błędy:

1. Gdy chcę zedytować kategorię, to wyrzuca mi : (problem jest, tylko w przypadku kliknięcia w submit)

  1. <?php
  2. Fatal error: Call to undefined method sfRoute::getObject()
  3. ?>


Mój kod:
  1. <?php
  2. public function executeEdit(sfWebRequest $request)
  3.      {
  4.          $this->category = $this->getRoute()->getObject();
  5.          $this->form = new CategoryForm($this->category);
  6.          
  7.          if ($request->isMethod('post'))
  8.          {
  9.              $this->form->bind($request->getParameter('category'));
  10.              
  11.              if ($this->form->isValid())
  12.              {
  13.                  $this->form->save();
  14.              }
  15.          }
  16.      }
  17. ?>

  1. <?php
  2. category_edit:
  3.  url:      /category/edit/:slug
  4.  class:    sfPropelRoute
  5.  param:    { module: category, action: edit }
  6.  options:  { model: Category, type: object }
  7. ?>


2. Podczas edytowania kategorii , jest pole select z main_id. Chodzi mi tutaj o subkategorie w tym przypadku. Lecz, gdy przekazuję

  1. <?php
  2. $this->category = $this->getRoute()->getObject();
  3.          $this->form = new CategoryForm($this->category);
  4. ?>


To w selectcie wyświetla mi również aktualnie edytowaną kategorię, mój form:

  1. <?php
  2. public function configure()
  3.     {
  4.          $this->setWidgets(array(
  5.              'id'      => new sfWidgetFormInputHidden(),
  6.              'main_id' => new sfWidgetFormPropelChoice(array('model' => 'Category', 'add_empty' => true)),
  7.              'name'    => new sfWidgetFormInput(),
  8.           ));
  9.          
  10.           $this->setValidators(array(
  11.            'id'      => new sfValidatorPropelChoice(array('model' => 'Category', 'column' => 'id', 'required' => false)),
  12.            'main_id' => new sfValidatorPropelChoice(array('model' => 'Category', 'column' => 'id', 'required' => false)),
  13.            'name'    => new sfValidatorString(array('min_length' => 3, 'max_length' => 255), array(
  14.                   'min_length' => 'Nazwa "%value%" jest zbyt krótka. Wymagane jest minimum %min_length% znaków.',
  15.                   'required' => 'Nazwa jest wymagana.',
  16.                   'max_length' => 'Nazwa jest zbyt długa. Wymagane jest maksimum %max_length% znaków.'
  17.               )),
  18.           ));
  19.        
  20.        $this->widgetSchema->setNameFormat('category[%s]');
  21.        
  22.        $this->widgetSchema->setLabels(array(
  23.            'name' => 'Nazwa',
  24.            'main_id' => 'Główna kategoria'
  25.        ));
  26.        
  27.        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  28.      }
  29. ?>


Z góry dziękuję za pomoc.