R
R
Relike2015-06-17 23:22:18
PHP
Relike, 2015-06-17 23:22:18

How to make routing as fast as possible?

There is a URL :
/main_category/
/main_category/page/1
/main_category/category/
/main_category/category/page/1
/main_category/category/post/
Where main_category, category and post are the corresponding post character codes in the database. How to determine what is being shown in the fastest possible time? Here is what I did now:

if($s1 && $this->m_categories->isCategoryUrl($s1) && (!$s2 && !$s3 && !$s4) || ($s2 == 'page' && $s3 > 0))
    {
      $this->main_cat($s1);
      
    }
    elseif($s1 && $s2 == 'page' && intval($s3))
    {
      
      $this->main_cat($s1, intval($s3));
    }
    elseif($s1 && $this->m_categories->isCategoryUrl($s2) && $post = $this->m_posts->isPostUrl($s3))
    {
      $this->post($s3, $s1, $s2);
    }
    elseif($s1 && $this->m_categories->isCategoryUrl($s2))
    {
      if($s3 == 'page' && intval($s4))
      {
      
        $this->subcat($s2, intval($s4), $s1);
      }
      elseif($s3)
      {
        show_404();
      }
      else
      {
        $this->subcat($s2, 0, $s1);
      }
    }
    elseif($s1 && $this->m_posts->isPostUrl($s2))
    {			
      $this->post($s2, $s1);
    }
    else
    {
      show_404();
    }

Do you have any suggestions? $1/$2/$3 - respectively.
Thanks in advance!
PS The fact that in addition to main_category is determined in advance by the regular framework router, I also need to scatter the functionality inside one controller.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2015-06-18
@index0h

Again you ...))) Already asked .
A similar situation is possible if you are clearly doing something wrong. Routing is not the task of the controller.
You should not file a lot of logic into the router, then it will definitely backfire.
Look at the implementation : docs.slimframework.com/routing/get , lumen.laravel.com/docs/routing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question