Welcome Guest, Not a member yet? Register   Sign In
Stuck If Statment Gets Canceld
#1

On my content_top page I need to set two if statements for my $route variable.

But when I have second one it stops cancels the first if statment for some reason.

How can I get them to work both together.  Works fine when just have first one the second $route page id gives correct path but cancels out first one.


PHP Code:
http://localhost/project/catalog/pages/category/?&path=138_140
http://localhost/project/catalog/pages/page/?&path=138_139&page_id=56 // with page_id

$path $this->input->get('path');
$page_id $this->input->get('page_id');

if (
$path == TRUE) {
$route current_url() . '/?&path=' $path;
} elseif (
$path == FALSE) {
$route current_url();
}

if (
$page_id == TRUE) {
$route current_url() . '/?&path=' $path '&page_id=' $page_id;
} elseif (
$page_id == FALSE) {
$route current_url();


Controller


PHP Code:
<?php

class Content_top extends MX_Controller {

    public function 
index() {        
        
$this->load->model('catalog/design/model_design_layout');

        
$path $this->input->get('path');
        
$page_id $this->input->get('page_id');

        if (
$path == TRUE) {
            
$route current_url() . '/?&path=' $path;
        } elseif (
$path == FALSE) {
            
$route current_url();
        }

        if (
$page_id == TRUE) {
            
$route current_url() . '/?&path=' $path '&page_id=' $page_id;
        } elseif (
$page_id == FALSE) {
            
$route current_url();
        }

        
$layout_id 0;

        if (!
$layout_id) {
            
$layout_id $this->model_design_layout->get_layout($route);
        }

        if (!
$layout_id) {
            
$layout_id $this->setting->get('config_layout_id');
        }

        
$this->load->model('catalog/extension/model_extension_module');
        
        
$data['modules'] = array();

        
$modules $this->model_design_layout->get_layout_modules($layout_id'content_top');

        foreach (
$modules as $module) {
            
$part explode('.'$module['code']);

            if (isset(
$part[0]) && $this->setting->get($part[0] . '_status')) {
                
$data['modules'][] = Modules::run('catalog/module'.'/'.$part[0].'/'.'index');

            }
                        
            if (isset(
$part[1])) {
                
$setting_info $this->model_extension_module->get_module($part[1]);

                
                if (
$setting_info && $setting_info['status']) {
                    
$data['modules'][] = Modules::run('catalog/module'.'/'.$part[0].'/'.'index'$setting_info);


                }
            }
        }

        if (
file_exists(DIR_TEMPLATE .$this->setting->get('config_template'). '/template/common/content_top.php')) {
            return 
$this->load->view('theme/'.$this->setting->get('config_template').'/template/common/content_top'$data);
        } else {
            return 
$this->load->view('theme/default/template/common/content_top'$data);
        }
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

(This post was last modified: 04-29-2015, 09:43 AM by CroNiX.)

$path = $this->input->get('path');
$page_id = $this->input->get('page_id');

Those will never return boolean "TRUE" like you are testing for. They will either be the values from the GET variable if they exist, or boolean FALSE if they don't (CI2), or NULL in CI3 if it doesn't exist.

So you'd probably want your logic to be more like:
PHP Code:
if ($path === FALSE) {
  
//$path did not have a value in GET
  
$route current_url();
} else {
  
$route current_url() . '/?&path=' $path;
}

//or just use ternary operator instead of above:
$route = ($path === FALSE) ? current_url() : current_url() . '/?&path=' $path

And incorporate the same logic for your $page_id check.

Not sure why you have "?&" for your query string with nothing in between though.
Should be ?something=var1&something_else=var2
Reply
#3

(04-29-2015, 09:42 AM)CroNiX Wrote: $path = $this->input->get('path');
$page_id = $this->input->get('page_id');

Those will never return boolean "TRUE" like you are testing for. They will either be the values from the GET variable if they exist, or boolean FALSE if they don't (CI2), or NULL in CI3 if it doesn't exist.

So you'd probably want your logic to be more like:

PHP Code:
if ($path === FALSE) {
 
 //$path did not have a value in GET
 
 $route current_url();
} else {
 
 $route current_url() . '/?&path=' $path;
}

//or just use ternary operator instead of above:
$route = ($path === FALSE) ? current_url() : current_url() . '/?&path=' $path

And incorporate the same logic for your $page_id check.

Not sure why you have "?&" for your query string with nothing in between though.
Should be ?something=var1&something_else=var2

Thanks for that advice I am still learning query strings. Today I also tried code below and seem to work fine but will try and work out what the best is.


PHP Code:
$url current_url();
$path $this->input->get('path');
$page_id $this->input->get('page_id');

if (isset(
$path)) {
$route $url '/?&path=' $path;
} elseif (isset(
$page_id)) {
$route $url '/?&path=' $path '&page_id=' $page_id;
} else {
$route $url;

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB