ridwanskaterock / cicool

Cicool is a multifunctional application that is used to facilitate your work in creating a system, CMS, E-Comerce and others
20 stars 13 forks source link

PHP Condition for view button #420

Open LenkaSoma opened 4 years ago

LenkaSoma commented 4 years ago

Hello, I have a little problem,

I'm trying to check the user's role in thelsdh_effectifs table but to verify the user, I need to check if his username in theaauth_users table is the same as the lsdh_id inlsdh_effectifs j tried to create a request on the view with a php condition but a blank page appears, so I tried to create a function on the model but similarly a blank page appears, do you have any idea of the problem ?

More simply, I want the user to be able to see the content only if he has value1 as value in theroles column of the lsdh_effectifs table

Model_lsdh_effectifs.php (model)

public function roles() {

       $this->db->select('roles');
       $this->db->from('lsdh_effectifs');
       $this->db->join('aauth_users', 'aauth_users.username = lsdh_effectifs.lsdh_id', 'LEFT');
       $result = $this->db->get();

       if ($result == 'value1') {
           return true;
       }
           return false;
    }

lsdh_effectifs_list.php (view)

<?php if (function roles() == true): ?>
     html code visible only if user have 'value1' in 'roles'
<?php endif; ?>

Thank you very much

ridwanskaterock commented 4 years ago

Hi for first can you change the environment to development for seeing your error? change environment on index.php

Thanks

LenkaSoma commented 4 years ago

I managed to remove the blank page by adding the variable in the controller and making a condition with it.

lsdh_effectifs.php (controller) $this->data['test'] = $this->model_lsdh_effectifs->roles();

lsdh_effectifs_list.php (view) <?php if ($test == true): ?>

A problem solved, but it still does not work, I may have crashed in the function ... :/

ridwanskaterock commented 4 years ago

can you change

$result = $this->db->get()->row(); dd($result);

for see return value

LenkaSoma commented 4 years ago

blank page :x

A Database Error Occurred
Error Number: 1052

Column 'roles' in field list is ambiguous

SELECT `roles` FROM `lsdh_effectifs` LEFT JOIN `aauth_users` ON `aauth_users`.`username` = `lsdh_effectifs`.`lsdh_id`

Filename: /home/armalifejq/intranet/modules/lsdh_effectifs/models/Model_lsdh_effectifs.php

Line Number: 95
LenkaSoma commented 4 years ago

It's okay, I don't have the error anymore, I also had a roles column in aauth_users, the result returns value1 but the condition doesn't work