Search code examples
phpcodeigniterstrcmp

codeigniter array passing in views and string comparision


I am using cibonfire and I am using their template. This is my code in my view page:

<?php
        Template::block(
            $block_name = 'leftsidebar',
            $default_view = 'leftsidebar',              
            $data = array( 'role' => $role[0]->role_name)
        );
?>

In my template I am doing this :

<?php if(strcmp($role['role_name'], "Bimalogy Admin") == 0 ): ?>
    <h4><u><b>User Control</b></u></h4>
<?php endif; ?>

This is showing Undefined index: role_name error.

If I am doing this in my template :

<?php if(strcmp($data['role'], "Bimalogy Admin") == 0 ): ?>
<h4><u><b>User Control</b></u></h4>
<?php endif; ?>

Showing Undefined variable: data

If I echo $role its displaying Array as an output.

My question is how to access that array in this template and compare it with string.


Solution

  • Try to dump the $role array with var_dump($role).

    Depending on how the array is built, you may need to use $role->role_name, or $role[0]->role_name, or $role[0]['role_name'] etc.