简体   繁体   中英

Check the value exist in codeigniter

I am trying to make a condition of getting value but it is not working actually I have 3 pages and the layout of the page is same only the form is changed so what I am trying to do is if pagename?page is set then do something otherwise show recent activities in normal php it is easy to do by using isset() function but in codeigniter the isset function is not working here is what i did

<?php 
    if($this->input->get('page') == true) {
        if($this->input->get('page')  == true && $this->input->get('page') == 'page1') {
            echo 'page 01';
        }
        if($this->input->get('page')  == true && $this->input->get('page') == 'page2') {
            echo 'page 02';
        }
    } else {
        //normal activities page to be shown
    }
?>

This is what I am trying to do but nothing is working for me like it's directly jumping to else condition can anyone help me our please if not clarified do ask me please.

Thank You and hoping to learn

Try This :

if($this->input->get('page')) {
    if($this->input->get('page') == 'page1') {
        echo 'page 01';
    } else if($this->input->get('page') == 'page2') {
        echo 'page 02';
    }
} else {
    //normal activities page to be shown
}

Try this ;)

switch($this->input->get('page')) {
  case 'page1':
    echo 'page 01';
    break;

  case 'page2':
    echo 'page 02';
    break;

  default:
  /* normal activities page to be shown */
}

In View

<a href="<?php echo  base_url() ?>index.php/controller_name/order/one">Page One</a>
<a href="<?php echo  base_url() ?>index.php/controller_name/order/two">Page two</a>
<a href="<?php echo  base_url() ?>index.php/controller_name/order/three">Page three</a>

In Controller

public function order($value)
{
    switch ($value) {
        case 'one':
            $page = 'one';
            break;

        case 'two':
            $page = 'two';
            break;

        case 'three':
            $page = 'three';
            break;

        default:
            $page = 'three';
            break;
    }
    echo $page;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM