1

I am trying to duplicate a view and modify it, but it is giving me an error.

Before this, I did it with other views and it worked perfectly, all I had to do was rename the views and modify the code.

But now , I get this error:

Fatal error: Call to a member function get() on a non-object in D:\UniServerZ\vhosts\restaurant\administrator\components\com_restaurant\views\reviews\view.html.php on line 54

Line 54 has this code:

$canDo = RestaurantHelper::getActions($state->get('filter.category_id'));

var_dump($this); gives me the following ->

    object(RestaurantViewReviews)#156 (18) {
  ["items":protected]=>
  NULL
  ["pagination":protected]=>
  NULL
  ["state":protected]=>
  NULL
  ["_name":protected]=>
  string(7) "reviews"
  ["_models":protected]=>
  array(0) {
  }
  ["_basePath":protected]=>
  string(71) "D:\UniServerZ\vhosts\restaurant\administrator/components/com_restaurant"
  ["_defaultModel":protected]=>
  NULL
  ["_layout":protected]=>
  string(7) "default"
  ["_layoutExt":protected]=>
  string(3) "php"
  ["_layoutTemplate":protected]=>
  string(1) "_"
  ["_path":protected]=>
  array(2) {
    ["template"]=>
    array(2) {
      [0]=>
      string(89) "D:\UniServerZ\vhosts\restaurant\administrator\templates\isis\html\com_restaurant\reviews\"
      [1]=>
      string(91) "D:\UniServerZ\vhosts\restaurant\administrator\components\com_restaurant\views\reviews\tmpl\"
    }
    ["helper"]=>
    array(1) {
      [0]=>
      string(80) "D:\UniServerZ\vhosts\restaurant\administrator\components\com_restaurant\helpers\"
    }
  }
  ["_template":protected]=>
  NULL
  ["_output":protected]=>
  NULL
  ["_escape":protected]=>
  string(16) "htmlspecialchars"
  ["_charset":protected]=>
  string(5) "UTF-8"
  ["_errors":protected]=>
  array(0) {
  }
  ["baseurl"]=>
  string(14) "/administrator"
  ["document"]=>
  object(JDocumentHTML)#122 (32) {
    ["_links"]=>
    array(0) {
    }
    ["_custom"]=>
    array(0) {
    }
    ["template"]=>
    NULL
    ["baseurl"]=>
    NULL
    ["params"]=>
    NULL
    ["_file"]=>
    NULL
    ["_template":protected]=>
    string(0) ""
    ["_template_tags":protected]=>
    array(0) {
    }
    ["_caching":protected]=>
    NULL
    ["_html5":"JDocumentHTML":private]=>
    NULL
    ["title"]=>
    string(27) "Restaurant - Administration"
    ["description"]=>
    string(24) "Restaurant description.."
    ["link"]=>
    string(0) ""
    ["base"]=>
    string(0) ""
    ["language"]=>
    string(5) "en-gb"
    ["direction"]=>
    string(3) "ltr"
    ["_generator"]=>
    string(40) "Joomla! - Open Source Content Management"
    ["_mdate"]=>
    string(0) ""
    ["_tab"]=>
    string(2) "  "
    ["_lineEnd"]=>
    string(1) "
"
    ["_charset"]=>
    string(5) "utf-8"
    ["_mime"]=>
    string(9) "text/html"
    ["_namespace"]=>
    string(0) ""
    ["_profile"]=>
    string(0) ""
    ["_scripts"]=>
    array(0) {
    }
    ["_script"]=>
    array(0) {
    }
    ["_styleSheets"]=>
    array(0) {
    }
    ["_style"]=>
    array(0) {
    }
    ["_metaTags"]=>
    array(2) {
      ["http-equiv"]=>
      array(1) {
        ["content-type"]=>
        string(24) "text/html; charset=utf-8"
      }
      ["standard"]=>
      array(1) {
        ["keywords"]=>
        NULL
      }
    }
    ["_engine"]=>
    NULL
    ["_type"]=>
    string(4) "html"
    ["mediaVersion":protected]=>
    string(32) "5a22c74e31c4742e55ee891853d099a2"
  }
}

Any help regarding this would be greatly appreciated,

Thanks

2

$state is not an object. That means that it is not correctly initialized earlier in your method. Or may be it should be $this->state instead of $state.

  • First of all, thanks for your reply. I have this code before that line: $state = $this->get('State'); So basically I am already calling the object's get() method and assigning to the $state variable. But this doesn't seem to work in this case. Hmm, any more ideas? Thanks again. – Sameer Nyaupane Jan 12 '15 at 8:42
  • Then something is wrong in your code. May be model is not connected with the view and you can not get the state from it. Try to dump $state or $this to check whether the model is ok. Then try to explore further where the problem could be. – Dmitry Rekun Jan 12 '15 at 9:48
  • var_dump($state) gives me "NULL". while var_dump($this) 's output is too long to post here, so I added it to the original question. The model array seems is empty, is that the cause? Thanks – Sameer Nyaupane Jan 12 '15 at 10:16
  • Yeah _defaultModel also is empty! Then you should go up to reviews controller and check there display() method. Is it custom? How do you instantiate the view there? – Dmitry Rekun Jan 12 '15 at 11:11
  • Well yes, I am creating the component myself. So yes I do have a 'RestaurantControllerReviews' controller with just a getModel() method in it. I have a generic display() method on my controller.php. – Sameer Nyaupane Jan 12 '15 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.