• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Helper Problem ?

#1
Hi guys.
Who can help me solve a problem?
I made a helper in the CI3 standard but I displays the following error message:

An uncaught Exception was encountered
Type: Error
Message: Using $this when not in object context
Filename: /var/www/Dropbox/screens.dev/public_html/application/helpers/sessdata_helper.php
Line Number: 71
Backtrace:
File: /var/www/Dropbox/screens.dev/public_html/application/controllers/apps/Runcode.php
Line: 35
Function: check

File: /var/www/Dropbox/screens.dev/public_html/index.php
Line: 315
Function: require_once


Helper : sessdata_helper.php:
<?php

defined('BASEPATH') OR exit('No direct script access allowed');



  if ( ! function_exists('check')) {

    //

    function check($ws_safe_email) {

      //get main CodeIgniter object

      $ci =& get_instance();

      //load databse library

      $ci->load->database('screens.db', TRUE);

      // data decode and execute search in columm

      $ci->db->where('ws_safe_email', base64_decode($ws_safe_email));

      // Open table for search

      $ws_user_list = $ci->db->get('ws_screens')->result();

      //

      if  (count($ws_user_list)==1) {

        // atribui resultado da consulta dentro de um array relacionada a varaiavel:

        $ws_session_data['ws_user_list'] = $ws_user_list[0];

        // atribui valor bolean

        $ws_session_data['logado'] = TRUE;

        // abre a session

        $this->session->set_userdata($ws_session_data);

        // recupera o valor decodificado de acesso e atribui dentro de um array relacionado a variavel:

        $data['ws_safe_email'] = $this->session->userdata('ws_user_list')->ws_safe_email;

        // obten o feedback:

        return $data;

      }

      //

      elseif ($ws_safe_email == '') {

        // restricted access

        //$url = "http://access.webstrucs.com/";

        //header("Location: $url" );

        echo "Acesso restrito";

      }

    }
  }

Controller : Runcode.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Runcode extends CI_Controller {

// Contructor Method :
 public function __construct() {
parent::__construct();
}

 public function index() {
}

 public function accesscheck($ws_safe_email) {
$this->load->helper('sessdata');
$feedbk = check($ws_safe_email);
echo $feedbk;
  }
  public function accessclose() {
  }
}

???

Reply

#2
you can't use $this in function. Is base in PHP.
Reply

#3
$ci->session->set_userdata($ws_session_data);
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#4
(07-12-2016, 04:42 AM)InsiteFX Wrote: $ci->session->set_userdata($ws_session_data);

I managed to fix the code, thanks. But introduces a new error:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: apps / Runcode.php
Line Number: 36

backtrace:
File: /var/www/Dropbox/screens.dev/public_html/application/controllers/apps/Runcode.php
Line: 36
Function: _error_handler

File: /var/www/Dropbox/screens.dev/public_html/index.php
Line: 315
Function: require_once

array

Reply

#5
(07-12-2016, 01:23 PM)jocm.aguiar Wrote: I managed to fix the code, thanks. But introduces a new error:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: apps / Runcode.php
Line Number: 36

backtrace:
File: /var/www/Dropbox/screens.dev/public_html/application/controllers/apps/Runcode.php
Line: 36
Function: _error_handler

Which leads to the question, what is on line 36 of /application/controllers/apps/Runcode.php? (preferably any other code required to understand that line, as well) PHP's error messages are a mixed bag, but they usually point you in the right direction.
Reply

#6
(07-12-2016, 02:23 PM)mwhitney Wrote:
(07-12-2016, 01:23 PM)jocm.aguiar Wrote: I managed to fix the code, thanks. But introduces a new error:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: apps / Runcode.php
Line Number: 36

backtrace:
File: /var/www/Dropbox/screens.dev/public_html/application/controllers/apps/Runcode.php
Line: 36
Function: _error_handler

Which leads to the question, what is on line 36 of /application/controllers/apps/Runcode.php? (preferably any other code required to understand that line, as well) PHP's error messages are a mixed bag, but they usually point you in the right direction.

Ok.

Controller File: Runcode.php
Method:

31  // Paramente variable receive method:
32  public function accesscheck($ws_safe_email) {
33     // load helper:
34     $this->load->helper('sessdata');
35     $feedbk = check($ws_safe_email);
36     echo $feedbk;
37  }

Reply

#7
It looks like it may be in your check() method, maybe its trying to use a string and it's looking for an array?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#8
(07-12-2016, 07:06 PM)InsiteFX Wrote: It looks like it may be in your check() method, maybe its trying to use a string and it's looking for an array?

I rectified the code and can get the result of the function by the 'echo'. But I can not see the result in view, when step by parameter ?

Code Funcional :

    public function accesscheck($ws_safe_email) 
    {
       $output = check($ws_safe_email);
       echo $output;
    }

Nonfunctional code : Shows the view but do not see the function output ?

    public function accesscheck($ws_safe_email) 
    {
       $output['see'] = check($ws_safe_email);
       $this->load->view('apps/runcode', $output);
    }

View:
<?php $see; ?>

Reply

#9
You are returning this check($ws_safe_email); as an array $data

Another thing I just noticed is that your assigning the result obj from the query to the session user_data,
the user_data is expecting an associate array not an object.

you need to return a result_array() not just a result()
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#10
(07-14-2016, 10:50 AM)InsiteFX Wrote: You are returning this check($ws_safe_email); as an array $data

Another thing I just noticed is that your assigning the result obj from the query to the session user_data,
the user_data is expecting an associate array not an object.

you need to return a result_array() not just a result()

I noticed the code assigning only a variable as the previous post. Now the output of the problem function result? I forgot to declare the (echo) of the array () in view.php. This running perfect.

Grateful.

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.