if (!isset($modx->myDB)) { $host = 'IPAddress'; $username = 'Username'; $password = 'Password'; $dbname = 'DBName'; $port = 3306; $charset = 'utf-8'; $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset"; $modx->myDB = new xPDO($dsn, $username, $password); echo $o = ($modx->myDB->connect()) ? 'Connected </br>' : 'Not Connected'; $path = MODX_CORE_PATH . 'components/nhs/'; if (!$modx->myDB->addPackage('packageName', $path . 'model/','')) { print 'There was a problem adding your package.'; }; }
$results = $modx->myDB->getCollection('LogData',array('diallednumber' => $search));
Notice: Undefined property: modX::$myDB in /home/sites/domain.co.uk/public_html/nhs/core/cache/includes/elements/modsnippet/20.include.cache.php on line 11 Fatal error: Call to a member function getCollection() on a non-object in /home/sites/domain.co.uk/public_html/nhs/core/cache/includes/elements/modsnippet/20.include.cache.php on line 11
[[dbconnect]] [[!dbform]]
<?php if (isset($_POST['search'])) { $search = $_POST['search']; $results = $modx->myDB->getCollection('LogData',array('diallednumber' => $search)); if ($results) { $output =''; foreach($results as $result) { $fields = $result->toArray(); $output .= $modx->getChunk('ShowData', $fields); } }else { return 'No items found.'; } } return $output;
class MyClass { /* @var xPDO $myDB */ public $myDB = null; /* @var modX $modx */ public $modx = null; public function __construct(&$modx, $options) { $this->modx = &$modx; $this->getConnection(); } public function getConnection() { $host = 'IPAddress'; $username = 'Username'; $password = 'Password'; $dbname = 'DBName'; $port = 3306; $charset = 'utf-8'; $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset"; $this->myDB = new xPDO($dsn, $username, $password); $this->modx->log(modX::LOG_LEVEL_ERROR, ($modx->myDB->connect()) ? 'Connected </br>' : 'Not Connected' ); $path = MODX_CORE_PATH . 'components/nhs/'; if (!$this->myDB->addPackage('packageName', $path . 'model/')) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'There was a problem adding your package.'); }; } }
$modx->getService('myclass','MyClass', MODX_CORE_PATH . '/components/myclass/model/myclass.class.php'); $modx->myclass->myDB->getCollection();
[[dbconnect]] [[dbform]]
[[!dbconnect]] [[!dbform]]
<?php if (isset($_POST['search'])) { $search = $_POST['search']; $modx->getService('myclass','MyClass', MODX_CORE_PATH . '/components/packagename/model/packagename/myclass.class.php'); $results = $modx->myclass->myDB->getCollection('LogData',array('diallednumber' => $search)); if ($results) { $output =''; foreach($results as $result) { $fields = $result->toArray(); $output .= $modx->getChunk('ShowData', $fields); } }else { return 'No items found.'; } } return $output;
Notice: Undefined property: modX::$myclass in /home/sites/domain.co.uk/public_html/nhs/core/cache/includes/elements/modsnippet/20.include.cache.php on line 13 Notice: Trying to get property of non-object in /home/sites/domainl.co.uk/public_html/nhs/core/cache/includes/elements/modsnippet/20.include.cache.php on line 13 Fatal error: Call to a member function getCollection() on a non-object in /home/sites/paradoxal.co.uk/public_html/nhs/core/cache/includes/elements/modsnippet/20.include.cache.php on line 13
$modx->getService('myclass','MyClass', MODX_CORE_PATH . '/components/myclass/model/myclass.class.php');
Name: myclass
Path: {core_path}components/nhs/model/nhs/
File: myclass.class.php
Path: core/components/nhs/model/nhs/myclass.class.php
[2013-01-08 12:26:29] (ERROR @ /nhs/index.php) Could not load class: MyClass from myclass.
[2013-01-08 12:26:29] (ERROR @ /nhs/index.php) Problem getting service myclass, instance of class MyClass, from path /home/sites/domain.co.uk/public_html/nhs/core/components/nhs/model/nhs/myclass.class.php
$modx->getService('myclass','MyClass', MODX_CORE_PATH . 'components/nhs/model/nhs/myclass.class.php');