I create my own blog engine to learn Symfony, and I have a question:
In the generated admin pages for the blog post, I have a drop-down list of authors to specify author_id.
I would like to hide this drop-down list and set the author_id identifier to the identifier of the current user in the system when the message is created (but not when it is being edited).
How can i do this?
Edit I tried:
$request->setParameter(sprintf("%s[%s]", $this->form->getName(), "author_id"), $this->getUser()->getAttribute("user_id")); $request->setParameter("content[author_id]", $this->getUser()->getAttribute("user_id")); $request->setParameter("author_id", $this->getUser()->getAttribute("user_id")); $request->setParameter("author_id", 2); $request->setParameter("content[author_id]", 2); $request->setParameter("author_id", "2"); $request->setParameter("content[author_id]", "2");
In processForm () and executeCreate ()
Solved!
End Code:
public function executeCreate(sfWebRequest $request) { $form = $this->configuration->getForm(); $params = $request->getParameter($form->getName()); $params["author_id"] = $this->getUser()->getGuardUser()->getId();; $request->setParameter($form->getName(), $params); parent::executeCreate($request); }
source share