<?php

class sfMyActions extends sfActions
{
  public function renderComponent($moduleName, $componentName, $vars = array()) {
    sfLoader::loadHelpers('Partial');
    return $this->renderText(get_component($moduleName, $componentName, $vars));
  }

  public function renderModalbox($message, $url = null) {
    sfLoader::loadHelpers(array('Url', 'Tag', 'ModalBox'));
    return $this->renderText('<center><h2>'.$message.'</h2><p>'.m_finish('Đóng', $url).'</p></center>');
  }

  public function setRequestError($name, $message) {
    $this->getRequest()->setError($name, $message);
    return sfView::SUCCESS;
  }

  public function execute() {
    try {
      return parent::execute();
    } catch (sfError404Exception $e) {
      $message = $e->getMessage();
      if ($this->getRequestParameter('modalbox') == 1) {
        if ($message == '') return $this->renderText('<script>Modalbox.hide();</script>');
        return $this->renderText('<center><font color="red"><h2>Lỗi 404: '.$message.'</h2></font><p><a href="#" onclick="Modalbox.hide();return false;">Đóng</a></p></center>');
      }
      $this->getRequest()->setError('message404', $message);
      $this->forward404($message);
    }
  }
}
