Note that there are some explanatory texts on larger screens.

plurals
  1. PONot object although var_dump() says otherwise?
    primarykey
    data
    text
    <p>When I create controller, I load model (<em>AccountModel</em>) to class variable "Model" and check if user is logged in:</p> <pre><code>function __construct() { parent::__construct(); $this-&gt;loadModel("AccountModel", "Model"); $account = $this-&gt;getUserAccount(); ... } </code></pre> <blockquote> <p>Fatal error occurs in getUserAccount():</p> <p>Fatal error: Call to a member function getAccount() on a non-object in wwwroot/lib/account/account.php on line 57</p> </blockquote> <p>That's line 57, I call <code>getAccount()</code> on my previously loaded model:</p> <pre><code>$account = $this-&gt;Model-&gt;getAccount($_SESSION["account"]["user_account_id"]); </code></pre> <p>So, looks like <code>$this-&gt;Model</code> is not object, but when I put <code>var_dump($this-&gt;Model)</code> before calling <code>getAccount()</code>, it says <em>object(AccountModel)#26 (2) ...</em></p> <p>I also did <code>var_dump($this)</code>, which dumped <em>controller</em> and found that class variable <code>$Model</code> exists and is instance of <em>AccountModel</em>.</p> <p>Can anybody tell me what the hell is going on?</p> <p>Btw, model is assigned like that (method of controller):</p> <pre><code>function loadModel($model_name, $var_name) { // blah blah blah $obj = new $class_name(); $this-&gt;$var_name = $obj; } </code></pre> <h2><strong>Update:</strong></h2> <p>In __construct(), if I directly call <em>getAccount()</em> on my model (previously I called <em>getUserAccount</em> and then <em>getAccount</em> within) without parameter, PHP outputs error sayin:</p> <blockquote> <p>Missing argument 1 for AccountModel::getAccount()</p> </blockquote> <p>But when I add parameter it says it's not object again.</p> <h2>Solution:</h2> <p>When loading models, method loadModel() assigned model to instance of controller and stored every name of loaded model into staic property. An error occured when controller has been called second time, so second instance of controller didn't really get its model. Replaced staitc property with object property (checking if model has already been called avoids using require_once lowers overhead, but now will have to find a better solution for that part ;) Anyway, now it works, thanks everyone for helping.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload