When I attempt to load my database results, it doesn't work, until I switch:
$id === null
to
$id !== null
.. then, everything loads as expected. What am I missing?
Here's my code:
config.php
'services' => array(
'models' => array(
'serv.widget.model.widget' => array(
'class' => 'ServPlugin\BundleNameBundle\Model\ClassModel'
)
)
),
DefaultController.php
namespace ServPlugin\BundleNameBundle\Controller;
use Serv\CoreBundle\Controller\FormController;
use ServPlugin\BundleNameBundle\Entity\Class;
/** @var \ServPlugin\BundleNameBundle\Model\ClassModel $classModel */
$classModel = $this->getModel('class');
/** @var \ServPlugin\BundleNameBundle\Entity\Class $class */
$class = $classModel->getEntity($formId);
//html here
echo 'Total Rows: '.$class->getCount();
ClassModel.php
namespace ServPlugin\BundleNameBundleBundle\Model;
use Serv\CoreBundle\Model\FormModel;
use ServPlugin\BundleNameBundleBundle\Entity\Class;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
class ClassModel extends FormModel
{
public function getEntity($id = null)
{
if ($id === null) {
return new Class();
}
return parent::getEntity($id);
}
function getEntity is what I am struggling with. When I view the cache, I can see the model is loading appropriately, but I cannot access it until I go backwards on the null value.
(It turns out, $classModel is loading nothing; -- so when my code moves to $class->getCount() -- the $formId is working as it should (which is a number); the model should be loading FIRST with ServPlugin\BundleNameBundle\Model\ClassModel with ID #7, right?)
This is the error I get when I try to call it as posted above:
Call to a member function getCount() on null - in file /var/www/plugins/BundleNameBundle/Controller/DefaultController.php - at line 299 [] []
Line 299: $class->getCount()