![]() |
Custom Helper Problem ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Custom Helper Problem ? (/showthread.php?tid=65682) |
Custom Helper Problem ? - jocm.aguiar - 07-11-2016 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() { } } ??? RE: Custom Helper Problem ? - HTLove - 07-11-2016 you can't use $this in function. Is base in PHP. RE: Custom Helper Problem ? - InsiteFX - 07-12-2016 $ci->session->set_userdata($ws_session_data); RE: Custom Helper Problem ? - jocm.aguiar - 07-12-2016 (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 RE: Custom Helper Problem ? - mwhitney - 07-12-2016 (07-12-2016, 01:23 PM)jocm.aguiar Wrote: I managed to fix the code, thanks. But introduces a new error: 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. RE: Custom Helper Problem ? - jocm.aguiar - 07-12-2016 (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: 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 } RE: Custom Helper Problem ? - InsiteFX - 07-12-2016 It looks like it may be in your check() method, maybe its trying to use a string and it's looking for an array? RE: Custom Helper Problem ? - jocm.aguiar - 07-14-2016 (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; ?> RE: Custom Helper Problem ? - InsiteFX - 07-14-2016 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() RE: Custom Helper Problem ? - jocm.aguiar - 07-14-2016 (07-14-2016, 10:50 AM)InsiteFX Wrote: You are returning this check($ws_safe_email); as an array $data 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. |