When logged in - everything works correctly. If I view the page without a login - I get

Message: Trying to get property of non-object.

controler:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Payment extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model("user_model"); // If the user does not have premium. // -1 means they have unlimited premium if($this->settings->info->global_premium && ($this->user->info->premium_time != -1 && $this->user->info->premium_time < time()) ) { $this->session->set_flashdata("globalmsg", lang("success_29")); redirect(site_url("funds/plans")); } } public function go($username="") { if(empty($username)) $this->template->error(lang("error_51")); $user = $this->user_model->get_user_by_username($username); if($user->num_rows() == 0) $this->template->error(lang("error_52")); $user = $user->row(); if($user->user_role == -1) $this->template->error(lang("error_53")); $groups = $this->user_model->get_user_groups($user->ID); $this->template->set_layout("layout/pay_layout.php"); $this->template->loadContent("payment/go.php", array( "user" => $user, "groups" => $groups ) ); } } ?> 

View:

 <!-- Page Header --> <div class="content bg-gray-lighter"> <h1 class="page-heading push"> Π‘Ρ‡Π΅Ρ‚ β„–8788 - На Ρ‡Π°ΡˆΠ΅Ρ‡ΠΊΡƒ ΠΊΠΎΡ„Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Π΅ <?php echo $user->credit_card ?> **// Π—Π΄Π΅ΡΡŒ Π½ΠΎΡ€ΠΌΠ°Π»ΡŒΠ½ΠΎ появляСтся пСрСмСнная** </h1> </div> <!-- END Page Header --> <!-- Page Content --> <div class="content content-boxed"> <div class="row"> <?php if($this->user->info->disable_credit_card) : ?> // здСсь Π½Π΅ знаю ΠΊΠ°ΠΊ ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ <div class="col-sm-4 col-md-4"> <a href="#" data-toggle="modal" data-target="#pp" class="block block-rounded block-link-hover3"> <div class="block-content block-content-full clearfix"> <div class="col-lg-3"> <img class="img-avatar enter" src="<?php echo base_url();?>theme/onui/assets/img/pay/card.png" alt=""> </div> <div class="col-lg-9"> <div class="font-w600 push-5">БанковскиС ΠΊΠ°Ρ€Ρ‚Ρ‹</div> <div class="text-muted">Комиссия 0%</div> </div> </div> </a> </div> <?php endif; ?> </div> </div> <!-- END Page Content --> 

So, this code has worked, but the situation has become the following: if the user is not logged in, he sees the block correctly, if logged in - for him the opposite is true:

 <?php if($user->disable_credit_card) : ?> <div class="col-sm-4 col-md-4"> <a href="#" data-toggle="modal" data-target="#pp" class="block block-rounded block-link-hover3"> <div class="block-content block-content-full clearfix"> <div class="col-lg-3"> <img class="img-avatar enter" src="<?php echo base_url();?>theme/onui/assets/img/pay/card.png" alt=""> </div> <div class="col-lg-9"> <div class="font-w600 push-5">БанковскиС ΠΊΠ°Ρ€Ρ‚Ρ‹</div> <div class="text-muted">Комиссия 0%</div> </div> </div> </a> </div> <?php endif; ?> <?php if($user->disable_yandex_money) : ?> 

where <?php if($user->disable_credit_card) : ?> - on / off. block.

that is, it is not logged in and it is noted that the unit is turned off - the user sees it turned on.

  • one
    where is the line where the warning happened and what is there at all - Naumov
  • <? php if ($ this-> user-> info-> disable_credit_card):?> - this is on / off block. - Anton Bogomolov
  • $ disable_credit_card = intval ($ this-> input-> post ("disable_credit_card")); // On / Off Bank Cards in Account Controller - Anton Bogomolov
  • 2
    somewhere somewhere instead of an object comes null / boolean / etc - etki
  • 2
    as said Etki dump through var_dump and see where the variable came from - Naumov

1 answer 1

Thank you all for the tips. Everything works in such a synapse.

 <?php if($user->disable_credit_card) : ?> <div class="col-sm-4 col-md-4"> <a href="#" data-toggle="modal" data-target="#pp" class="block block-rounded block-link-hover3"> <div class="block-content block-content-full clearfix"> <div class="col-lg-3"> <img class="img-avatar enter" src="<?php echo base_url();?>theme/onui/assets/img/pay/card.png" alt=""> </div> <div class="col-lg-9"> <div class="font-w600 push-5">БанковскиС ΠΊΠ°Ρ€Ρ‚Ρ‹</div> <div class="text-muted">Комиссия 0%</div> </div> </div> </a> </div> <?php endif; ?>