/** * Returns count * * @param int $entryId * * @return EntryCountModel */ public function getCount($entryId) { // create new model /* 'Model' being an object from the EntryCountModel class. */ $entryCountModel = new EntryCountModel(); // get record from DB /* Creates $entryCountRecord property, then calls the static model() method on the EntryCountRecord. This will return an instance of the record back to us. Then, we'll call the method findByAttributes() and we'll pass an array with the attribute 'entryId' and the value that was passed in to $entryId. */ $entryCountRecord = EntryCountRecord::model()->findByAttributes(array('entryId' => $entryId)); if ($entryCountRecord) { // populate model from record /* If $entryCountRecord exists, we're going to populate the model with it. We do this by calling the static populateModel() method and passing in our $entryCountRecord. */ $entryCountModel = EntryCountModel::populateModel($entryCountRecord); } return $entryCountModel; }
/** * @param $entryId * @return EntryCountModel */ public function getCount($entryId) { // create new model $entryCountModel = new EntryCountModel(); // get record from the database $entryCountRecord = EntryCountRecord::model()->findByAttributes(array('entryId' => $entryId)); // if record exists, populate model from the record if ($entryCountRecord) { $entryCountModel = EntryCountModel::populateModel($entryCountRecord); } return $entryCountModel; }
/** * Returns count * * @param int $entryId * * @return EntryCountModel */ public function getCount($entryId) { // create new model $entryCountModel = new EntryCountModel(); // get record from DB $entryCountRecord = EntryCountRecord::model()->findByAttributes(array('entryId' => $entryId)); if ($entryCountRecord) { // populate model from record $entryCountModel = EntryCountModel::populateModel($entryCountRecord); } return $entryCountModel; }