symfony1 - Reusing actions in symfony -


let's have article model , comment model.

article:   columns:     body: text  comment:   columns:     article_id: integer     message: text   relations:     article:       local: article_id       foreign: id       foreignalias: comments 

and generate 2 models based on "article" , "comment" route collections:

article:   class: sfdoctrineroutecollection   options:     module: article     model: article  comment:   class: sfdoctrineroutecollection   options:     module: comment     model: comment 

so, have 2 cruds each model. now, in article's show action display article, it's related comments , form add comment.

class articleactions extends sfactions {   public function executeshow(sfwebrequest $request)   {     $this->article = $this->getroute()->getobject();     $this->comments = doctrine::gettable('comment')->findallbyarticleid ($this->article->getid());     $this->form = new commentform();    } } 

the question how can reuse comment/new , comment/create actions when posting comments in article/show action? right way organise code?

if want reuse actions, possible need component. component similar partials, use component when have add logic (like code use in action of comment/new or comment/create).

a component action, except it's faster. logic of component kept in class inheriting sfcomponents, located in actions/components.class.php file. presentation kept in partial.

check here docs of symfony :

the docs symfony 1.2, use in symfony 1.4 without problems

i sure component looking for.


Comments