I’m creating a class that gets values from my database.
My database looks like this:
id | value | quantity | type |
---------------------------------------
1 | 134 | 12 | 1 |
---------------------------------------
2 | 21 | 2 | 1 |
---------------------------------------
3 | 211 | 53 | 1 |
Right now my class looks like this:
?php
namespace commonclasses;
use commonmodelsdbstockType;
use yiidbActiveRecord;
class Stock extends ActiveRecord
{
/**
* @var stockType
*/
public $StockData;
public function run()
{
$this->StockData::find()
->select([
'SUM(quantity) as stockQuantity',
'SUM(value) as stockValue'
])
->where(['type' => 1])
->asArray()
->one();
}
public function getQuantity()
{
return $this->StockData::findOne(['column' => 'stockQuantity']);
}
And in my view I do this:
<?php
use commonclassesStock;
$stock = new Stock()
?>
<div class='row'>
<?= $stock->getQuantity() ?>
</div>
I would love to see the quantity in my view but I keep getting the following error:
Class name must be a valid object or a string
It points to the get method return, but I have no idea how to fix it.