0

I try to create new stdClass but still nothing and this code make an error: Warning: Creating default object from empty value.

function __construct($params) {
    parent::__construct($params);
    //$this -> view -> controller = null;
    $this -> view -> controller = new stdClass(); // <-- HERE IS ERROR 
    $this -> view -> controller = 'Index';

    require_once 'models/_index_model.php';
    $this -> model = new Index_model();

    $action = 'News';
    if(isset($params[1])){ $action = ucfirst($params[1]); }

    $this->date = 'Today';
    if(isset($params[2])) $this->date = ucfirst($params[2]);

    $this->$action($this->date);
}
3
  • what is $this? which method variable refers to it? does it have a view attribute? Commented Oct 3, 2015 at 16:11
  • please add this code to your question. it's really hard to follow code that way. Commented Oct 3, 2015 at 16:15
  • 1
    creating objects is not so difficult. there are two steps: create an object instance, and set attributes to it (for stdClass). look up this code: codepad.org/8AZAjGKY Commented Oct 3, 2015 at 16:35

1 Answer 1

1

The problem is, that there's no value for the variable $view

I'm not sure what you'd like to achieve, but the code should work if you implement it like in the following example:

function __construct($params) {
    parent::__construct($params);

    $this -> view = new stdClass(); // create a new stdClass object
    $this -> view -> controller = 'Index'; // assign the controller value

    // ... and so on
}

So the main problem here, is that the variable $view was not declared, or its value is not an object.

Feel free to ask in the comment section if there are more questions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.