• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter change url if get is empty

#1
Codeigniter change url if get is empty

When my get question id is empty http://localhost/project-ask/questions?question_id=

It should switch back to http://localhost/project-ask/questions

I have tried this below


PHP Code:
if (empty($this->input->get('question_id'))) {
redirect('questions')



And a couple of other ways but not working keep getting message. This page isn’t working message

Question if ?question_id= is in url but empty how to make sure it redirects to base_url('questions')

PHP Code:
<?php

class Questions extends MX_Controller {

    public function 
__construct() {
        
parent::__construct();
        
$this->load->library('parsedown');
        
$this->load->library('form_validation');
        
$this->load->model('catalog/questions/question_model');
    }

    public function 
index() {
        
$this->form_validation->set_rules('search''search''trim|required');
        
$this->form_validation->set_message('required''You did not enter any thing in {field} input');

    
        if (
$this->form_validation->run() == true) {
            
$results $this->question_model->getQuestions($this->input->post('search'));
        }

        if (
$this->input->post('search') == NULL) {
            
$results $this->question_model->getQuestions();
        }

        if (
$this->input->get('question_id')) {
            
$results = array();
        }

        
$data['questions'] = array();

        if (
$results) {
            foreach (
$results as $result) {
                
$tags = array();

                
$tag_results $this->question_model->getQuestionCategories($result['question_id']);

                if (
$tag_results) {
                    foreach (
$tag_results as $tag_result) {
                        
$tags[] = array(
                            
'tag_name' => $tag_result['name'
                        );
                    }
                }

                
$data['questions'][] = array(
                    
'title' => $result['title'],
                    
'tags' => $tags,
                    
'message' => strip_tags($result['message']),
                    
'href' => site_url('questions?question_id=') . $result['question_id']
                );
            }
        }

        
$data['header'] = Modules::run('catalog/common/header/index');
        
$data['navbar'] = Modules::run('catalog/common/navbar/index');
        
$data['footer'] = Modules::run('catalog/common/footer/index');

        
$this->load->view('theme/default/template/questions/questions'$data);
    }



Attached Files
.php   Questions.php (Size: 1.72 KB / Downloads: 67)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
Codeigniter change url if get is empty - by wolfgang1983 - 04-05-2017, 04:54 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.