title: Joomla 3 - Loading Model from CLI file
body: <p>I'm trying to load a model class and it's functions inside a CLI script for Joomla 3.6. This is what I have so far:</p>
  
  <pre><code>jimport('joomla.application.component.model');
  JLoader::import('JoomlaupdateModelDefault', './administrator/components/com_joomlaupdate/models');
  $updater = JModelLegacy::getInstance('default');
  var_dump($updater);
  $updater-&gt;finaliseUpgrade();
  </code></pre>
  
  <p>The <code>var_dump</code> always returns <code>false</code> and the final function call always returns this:</p>
  
  <blockquote>
    <p>Error displaying the error page: Application Instantiation Error: Call
    to a member function finaliseUpgrade() on boolean</p>
  </blockquote>
  
  <p>The error is of course because the class hasn't been created and it's really a bool.</p>
  
  <p>So the question remains, how do I pull that model into my php CLI application and use it's functions?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Ok, I've gotten part of the way there, now it return the object but while running <code>finalise</code> it returns an error about Instantiation. Object:</p>
  
  <pre><code>object(JoomlaupdateModelDefault)#52 (7) {
    ["__state_set":protected]=&gt;
    NULL
    ["_db":protected]=&gt;
    object(JDatabaseDriverMysqli)#7 (23) {
      ["name"]=&gt;
      string(6) "mysqli"
      ["serverType"]=&gt;
      string(5) "mysql"
      ["connection":protected]=&gt;
      object(mysqli)#11 (19) {
        ["affected_rows"]=&gt;
        int(1)
        ["client_info"]=&gt;
        string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $"
        ["client_version"]=&gt;
        int(50012)
        ["connect_errno"]=&gt;
        int(0)
        ["connect_error"]=&gt;
        NULL
        ["errno"]=&gt;
        int(0)
        ["error"]=&gt;
        string(0) ""
        ["error_list"]=&gt;
        array(0) {
        }
        ["field_count"]=&gt;
        int(14)
        ["host_info"]=&gt;
        string(25) "Localhost via UNIX socket"
        ["info"]=&gt;
        NULL
        ["insert_id"]=&gt;
        int(0)
        ["server_info"]=&gt;
        string(23) "5.7.16-0ubuntu0.16.04.1"
        ["server_version"]=&gt;
        int(50716)
        ["stat"]=&gt;
        string(138) "Uptime: 10319  Threads: 3  Questions: 8381  Slow queries: 0  Opens: 1523  Flush tables: 1  Open tables: 184  Queries per second avg: 0.812"
        ["sqlstate"]=&gt;
        string(5) "00000"
        ["protocol_version"]=&gt;
        int(10)
        ["thread_id"]=&gt;
        int(131)
        ["warning_count"]=&gt;
        int(0)
      }
      ["nameQuote":protected]=&gt;
      string(1) "`"
      ["nullDate":protected]=&gt;
      string(19) "0000-00-00 00:00:00"
      ["_database":"JDatabaseDriver":private]=&gt;
      string(3) "j34"
      ["count":protected]=&gt;
      int(4)
      ["cursor":protected]=&gt;
      NULL
      ["debug":protected]=&gt;
      bool(false)
      ["limit":protected]=&gt;
      int(0)
      ["log":protected]=&gt;
      array(0) {
      }
      ["timings":protected]=&gt;
      array(0) {
      }
      ["callStacks":protected]=&gt;
      array(0) {
      }
      ["offset":protected]=&gt;
      int(0)
      ["options":protected]=&gt;
      array(9) {
        ["driver"]=&gt;
        string(6) "mysqli"
        ["host"]=&gt;
        string(9) "localhost"
        ["user"]=&gt;
        string(4) "***"
        ["password"]=&gt;
        string(4) "***"
        ["database"]=&gt;
        string(3) "***"
        ["prefix"]=&gt;
        string(6) "***_"
        ["select"]=&gt;
        bool(true)
        ["port"]=&gt;
        int(3306)
        ["socket"]=&gt;
        NULL
      }
      ["sql":protected]=&gt;
      object(JDatabaseQueryMysqli)#9 (24) {
        ["offset":protected]=&gt;
        int(0)
        ["limit":protected]=&gt;
        int(0)
        ["db":protected]=&gt;
        *RECURSION*
        ["sql":protected]=&gt;
        NULL
        ["type":protected]=&gt;
        string(6) "select"
        ["element":protected]=&gt;
        NULL
        ["select":protected]=&gt;
        object(JDatabaseQueryElement)#57 (3) {
          ["name":protected]=&gt;
          string(6) "SELECT"
          ["elements":protected]=&gt;
          array(1) {
            [0]=&gt;
            string(1) "*"
          }
          ["glue":protected]=&gt;
          string(1) ","
        }
        ["delete":protected]=&gt;
        NULL
        ["update":protected]=&gt;
        NULL
        ["insert":protected]=&gt;
        NULL
        ["from":protected]=&gt;
        object(JDatabaseQueryElement)#56 (3) {
          ["name":protected]=&gt;
          string(4) "FROM"
          ["elements":protected]=&gt;
          array(1) {
            [0]=&gt;
            string(12) "`#__updates`"
          }
          ["glue":protected]=&gt;
          string(1) ","
        }
        ["join":protected]=&gt;
        NULL
        ["set":protected]=&gt;
        NULL
        ["where":protected]=&gt;
        object(JDatabaseQueryElement)#55 (3) {
          ["name":protected]=&gt;
          string(5) "WHERE"
          ["elements":protected]=&gt;
          array(1) {
            [0]=&gt;
            string(22) "`extension_id` = '700'"
          }
          ["glue":protected]=&gt;
          string(5) " AND "
        }
        ["group":protected]=&gt;
        NULL
        ["having":protected]=&gt;
        NULL
        ["columns":protected]=&gt;
        NULL
        ["values":protected]=&gt;
        NULL
        ["order":protected]=&gt;
        NULL
        ["autoIncrementField":protected]=&gt;
        NULL
        ["call":protected]=&gt;
        NULL
        ["exec":protected]=&gt;
        NULL
        ["union":protected]=&gt;
        NULL
        ["unionAll":protected]=&gt;
        NULL
      }
      ["tablePrefix":protected]=&gt;
      string(6) "oaetn_"
      ["utf":protected]=&gt;
      bool(true)
      ["utf8mb4":protected]=&gt;
      bool(true)
      ["errorNum":protected]=&gt;
      int(0)
      ["errorMsg":protected]=&gt;
      string(0) ""
      ["transactionDepth":protected]=&gt;
      int(0)
      ["disconnectHandlers":protected]=&gt;
      array(0) {
      }
    }
    ["name":protected]=&gt;
    string(7) "default"
    ["option":protected]=&gt;
    string(16) "com_joomlaupdate"
    ["state":protected]=&gt;
    object(JObject)#53 (1) {
      ["_errors":protected]=&gt;
      array(0) {
      }
    }
    ["event_clean_cache":protected]=&gt;
    string(19) "onContentCleanCache"
    ["_errors":protected]=&gt;
    array(0) {
    }
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>Error displaying the error page: Application Instantiation Error:
    Application Instantiation Error</p>
  </blockquote>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is the code that partially works:</p>
  
  <pre><code>jimport('joomla.application.component.model');
  jimport('joomla.application.component.view');
  JModelLegacy::addIncludePath('./administrator/components/com_joomlaupdate/models', 'JoomlaupdateModel');
  $updater = JModelLegacy::getInstance('Default', 'JoomlaupdateModel');
  var_dump($updater);
  
  $updater-&gt;finaliseUpgrade();
  </code></pre>