Welcome Guest, Not a member yet? Register   Sign In
What am I missing.............
#1

[eluser]Otemu[/eluser]
Hi,

I am checking two url segments for id and page title e.g /news/4/NM-Star-Shinning-so-brightly
if a result is found in the database then the page is returned, if not then it directs them to codeigniter default 404 page.

Problem is the actual index page /news, orginally I was just checking if uri_string() was equal to /news then display the news index. However I noticed its possible a user could be using possible 4 different urls to get to the page:

/news
/news/
/home
/home/news/

I doubt that checking all 4 different urls is the best method for this, what has escaped me?

Thanks for the help
#2

[eluser]dudeami0[/eluser]
Mind sharing a little bit of code related to the problem?
#3

[eluser]Otemu[/eluser]
Here you go:

Code:
function news(){
    $id = $this->uri->segment(3);
    $pageurl = $this->uri->segment(4);
    $news = $this->M_Articles->getArticles($id,$pageurl);
    if(!count($news)){
     if(uri_string()!=="/news"){
            redirect ('errors/error_404','refresh');
            }    
        $data['general'] = $this->M_Articles->getArticleInfo(2);
        $data['newsListAll'] = $this->M_Articles->getNewsAll();
        }
    if(count($news)){
        $data['general'] = $this->M_Articles->getArticleInfo($id);
        $data['default'] = $news;
        }
    $this->load->vars($data);
    $this->load->view('template_master');
    }
#4

[eluser]dudeami0[/eluser]
Code:
function news($id=null, $pageurl=null){
    $news = $this->M_Articles->getArticles($id,$pageurl);
    if(!count($news)){
       if (!empty($id) || !empty($pageurl)) {
          redirect ('errors/error_404','refresh');
       }    
       $data['general'] = $this->M_Articles->getArticleInfo(2);
       $data['newsListAll'] = $this->M_Articles->getNewsAll();
    } else {
        $data['general'] = $this->M_Articles->getArticleInfo($id);
        $data['default'] = $news;
    }
    $this->load->vars($data);
    $this->load->view('template_master');
}

Also, use else instead of redoing the count. This is less stress on the server (Might seem small, but it all adds up).
#5

[eluser]Otemu[/eluser]
Hi,

You make it all seem so easy Smile

Thanks for fixing the problem and making the code more efficent.

Cheers




Theme © iAndrew 2016 - Forum software by © MyBB