Skip to main content
deleted 1529 characters in body
Source Link
Tom
  • 43
  • 4

Update 2

After trying every possible way I could imagine I finally found the solution and I've been pretty close with the version I mentioned in this post.

class BookstoreRouter extends JComponentRouterView
{
    public function __construct($app = null, $menu = null)
    {
        $books = new JComponentRouterViewconfiguration('books');
        $this->registerView($books);

        $book = new JComponentRouterViewconfiguration('book');
        $book->setKey('id')->setParent($books);
        $this->registerView($book);

        parent::__construct($app, $menu);

        $this->attachRule(new JComponentRouterRulesMenu($this));
        $this->attachRule(new JComponentRouterRulesStandard($this));
        $this->attachRule(new JComponentRouterRulesNomenu($this));
    }

    public function getBookSegment($id, $query)
    {
        if (strpos($query['id'], ':') === false) {
            $db = JFactory::getDbo();
            $dbquery = $db->getQuery(true);
            $dbquery->select($db->quoteName('alias'))
                ->from($db->quoteName('#__bookstore_books'))
                ->where('id = ' . $db->quote($id));
            $db->setQuery($dbquery);

            $id .= ':' . $db->loadResult();
        }

        return array((int)$id => $id);
    }

    public function getBookId($segment, $query)
    {
        return (int)$segment;
    }
}

In my understanding Nestable was necessary for Parent. Seems I got it all wrong. Works like a charm now.

Update 2

After trying every possible way I could imagine I finally found the solution and I've been pretty close with the version I mentioned in this post.

class BookstoreRouter extends JComponentRouterView
{
    public function __construct($app = null, $menu = null)
    {
        $books = new JComponentRouterViewconfiguration('books');
        $this->registerView($books);

        $book = new JComponentRouterViewconfiguration('book');
        $book->setKey('id')->setParent($books);
        $this->registerView($book);

        parent::__construct($app, $menu);

        $this->attachRule(new JComponentRouterRulesMenu($this));
        $this->attachRule(new JComponentRouterRulesStandard($this));
        $this->attachRule(new JComponentRouterRulesNomenu($this));
    }

    public function getBookSegment($id, $query)
    {
        if (strpos($query['id'], ':') === false) {
            $db = JFactory::getDbo();
            $dbquery = $db->getQuery(true);
            $dbquery->select($db->quoteName('alias'))
                ->from($db->quoteName('#__bookstore_books'))
                ->where('id = ' . $db->quote($id));
            $db->setQuery($dbquery);

            $id .= ':' . $db->loadResult();
        }

        return array((int)$id => $id);
    }

    public function getBookId($segment, $query)
    {
        return (int)$segment;
    }
}

In my understanding Nestable was necessary for Parent. Seems I got it all wrong. Works like a charm now.

added 1529 characters in body
Source Link
Tom
  • 43
  • 4

Update 2

After trying every possible way I could imagine I finally found the solution and I've been pretty close with the version I mentioned in this post.

class BookstoreRouter extends JComponentRouterView
{
    public function __construct($app = null, $menu = null)
    {
        $books = new JComponentRouterViewconfiguration('books');
        $this->registerView($books);

        $book = new JComponentRouterViewconfiguration('book');
        $book->setKey('id')->setParent($books);
        $this->registerView($book);

        parent::__construct($app, $menu);

        $this->attachRule(new JComponentRouterRulesMenu($this));
        $this->attachRule(new JComponentRouterRulesStandard($this));
        $this->attachRule(new JComponentRouterRulesNomenu($this));
    }

    public function getBookSegment($id, $query)
    {
        if (strpos($query['id'], ':') === false) {
            $db = JFactory::getDbo();
            $dbquery = $db->getQuery(true);
            $dbquery->select($db->quoteName('alias'))
                ->from($db->quoteName('#__bookstore_books'))
                ->where('id = ' . $db->quote($id));
            $db->setQuery($dbquery);

            $id .= ':' . $db->loadResult();
        }

        return array((int)$id => $id);
    }

    public function getBookId($segment, $query)
    {
        return (int)$segment;
    }
}

In my understanding Nestable was necessary for Parent. Seems I got it all wrong. Works like a charm now.

Update 2

After trying every possible way I could imagine I finally found the solution and I've been pretty close with the version I mentioned in this post.

class BookstoreRouter extends JComponentRouterView
{
    public function __construct($app = null, $menu = null)
    {
        $books = new JComponentRouterViewconfiguration('books');
        $this->registerView($books);

        $book = new JComponentRouterViewconfiguration('book');
        $book->setKey('id')->setParent($books);
        $this->registerView($book);

        parent::__construct($app, $menu);

        $this->attachRule(new JComponentRouterRulesMenu($this));
        $this->attachRule(new JComponentRouterRulesStandard($this));
        $this->attachRule(new JComponentRouterRulesNomenu($this));
    }

    public function getBookSegment($id, $query)
    {
        if (strpos($query['id'], ':') === false) {
            $db = JFactory::getDbo();
            $dbquery = $db->getQuery(true);
            $dbquery->select($db->quoteName('alias'))
                ->from($db->quoteName('#__bookstore_books'))
                ->where('id = ' . $db->quote($id));
            $db->setQuery($dbquery);

            $id .= ':' . $db->loadResult();
        }

        return array((int)$id => $id);
    }

    public function getBookId($segment, $query)
    {
        return (int)$segment;
    }
}

In my understanding Nestable was necessary for Parent. Seems I got it all wrong. Works like a charm now.

added 547 characters in body
Source Link
Tom
  • 43
  • 4

Update

Problem seems to be my parent has no Id of some kind so I am getting this Warning. I can route to the menu item, which is my list view. From there I have a dilemma. I can register the books view, resulting in my totally correct item links will not work. Or I can have only the book view registered and not have the links build in my books view at all.

I did build a legacyrouter.php like the one com_content uses which works fine. But since it is marked as deprecate I really want to make it work with the JComponentRouterView.

Update

Problem seems to be my parent has no Id of some kind so I am getting this Warning. I can route to the menu item, which is my list view. From there I have a dilemma. I can register the books view, resulting in my totally correct item links will not work. Or I can have only the book view registered and not have the links build in my books view at all.

I did build a legacyrouter.php like the one com_content uses which works fine. But since it is marked as deprecate I really want to make it work with the JComponentRouterView.

Source Link
Tom
  • 43
  • 4
Loading