Welcome Guest, Not a member yet? Register   Sign In
HMVC, Helpers and Undefined property
#1

(This post was last modified: 03-29-2016, 11:51 PM by Krycek.)

I use WireDesignz HMVC and have a KERNEL_Controller (which is actually the MY_Controller with another prefix) with (CodeIgniter 3.0.6)

PHP Code:
class KERNEL_Controller extends MX_Controller {
 public 
$myvar;

 
       public function __construct() {
 
               parent::__construct();

 
               $this->myvar 'test';
 
       }


Now I have an Helper which does the following

PHP Code:
function Editor($id) {
 
   $ci =& get_instance();

 
   echo $ci->myvar;


When I call the Editor in a view, I get

Code:
Severity: Notice

Message: Undefined property: CI::$myvar

Filename: helpers/editor_helper.php

Methods
Also when using in KERNEL_Controller

PHP Code:
public function DoTest() {
 echo 
'1';
 } 

And in the Editor_helper

PHP Code:
function Editor($id) {
 
   $ci =& get_instance();
 
   
    echo $ci
->DoTest();


I get

Code:
Type: Error

Message: Call to undefined method CI::DoTest()

This works
When I do below in the Editor Helper

PHP Code:
function Editor($id) {
    
$ci =& get_instance();

    
$result_content $ci->Core_model->GetLanguages(1);
    
print_r($result_content);


It does give me an array with languages!

In another project without HMVC, above works (ofcourse without extending MX_controller, but the CI_controller).
So in an helper I can call a method or a variable from the KERNEL_Controller.
Anyone an idea ?
Reply
#2

To set a session data:
PHP Code:
$this->session->set_userdata('some_name''some_value');

$newdata = array(
 
       'username'  => 'johndoe',
 
       'email'     => '[email protected]',
 
       'logged_in' => TRUE
);

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

To retrieve session data:
PHP Code:
$this->session->item 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 03-29-2016, 11:52 PM by Krycek.)

(03-29-2016, 05:16 PM)InsiteFX Wrote: To set a session data:
PHP Code:
$this->session->set_userdata('some_name''some_value');

$newdata = array(
 
       'username'  => 'johndoe',
 
       'email'     => '[email protected]',
 
       'logged_in' => TRUE
);

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

To retrieve session data:
PHP Code:
$this->session->item 

Thank you for your reply.
I have edited my topic start, because my session is not really a session (know, name is confusing).
My session can just contain a string or an array, it has nothing to do with real sessions.

Also when trying to call a method in the KERNEL_Controller, this fails with

Code:
Call to undefined method CI::DoTest()
(see my edited TS).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB