Backend\Core\Engine\Model::getURL PHP Method

getURL() public static method

Get URL for a given pageId
public static getURL ( integer $pageId, string $language = null ) : string
$pageId integer The id of the page to get the URL for.
$language string The language to use, if not provided we will use the working language.
return string
    public static function getURL($pageId, $language = null)
    {
        $pageId = (int) $pageId;
        $language = $language !== null ? (string) $language : BackendLanguage::getWorkingLanguage();
        // init URL
        $url = self::getContainer()->getParameter('site.multilanguage') ? '/' . $language . '/' : '/';
        // get the menuItems
        $keys = self::getKeys($language);
        // get the URL, if it doesn't exist return 404
        if (!isset($keys[$pageId])) {
            return self::getURL(404, $language);
        } else {
            $url .= $keys[$pageId];
        }
        // return the unique URL!
        return urldecode($url);
    }

Usage Example

 public function execute()
 {
     parent::execute();
     try {
         $id = Uuid::fromString($this->getParameter('id', 'string'));
         $teamMember = $this->get('team_repository')->find($id);
     } catch (\Exception $e) {
         return $this->redirect(Model::createURLForAction('Index') . '&error=non-existing');
     }
     $form = new TeamType('edit', $teamMember);
     if ($form->handle()) {
         $teamMember = $form->getData();
         $this->get('team_repository')->save($teamMember);
         return $this->redirect(Model::createURLForAction('Index') . '&report=edited' . '&highlight=row-' . $teamMember->getId());
     }
     // assign the detail url to the template if available
     $url = Model::getURLForBlock($this->URL->getModule(), 'Detail');
     if (Model::getURL(404) != $url) {
         $this->tpl->assign('detailURL', SITE_URL . $url);
     }
     $form->parse($this->tpl);
     $this->tpl->assign('teamMember', $teamMember->toArray());
     $this->parse();
     $this->display();
 }
All Usage Examples Of Backend\Core\Engine\Model::getURL