my code is running perfectly on local host but when i am uploading on server after running its showing
This above error We're sorry, an error has occurred while generating
this email.
my block code show.php is
<?php
namespace Diaspark\Location\Block;
class PageLink extends \Magento\Framework\View\Element\Template
{
protected $_locationFactory;
public function __construct(\Magento\Framework\View\Element\Template\Context $context,
\Diaspark\Location\Model\locationFactory $db)
{
$this->_locationFactory = $db;
parent::__construct($context);
}
public function getDisplayData()
{
$data=$this->_locationFactory->create()->getCollection();
return $data;
}
public function getImagePath()
{
$imagePath = $this->_storeManager->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$var= $imagePath .'mycustomfolder/';
return $var;
}
}
and PHTML code is
<?php
$_gridrecords = $block->getDisplayData();
foreach ($_gridrecords as $d )
{ $id= $d->getEntityId();
echo " ".$id;
}
?>
on cms page is calling my block like this way
{{block class="Diaspark\Location\Block\Show" template="show.phtml"}}
location.php in model
<?php
/**
* Auction Location Model.
*
* @category Diaspark
*
* @author Diaspark Software Private Limited
*/
namespace Diaspark\Location\Model;
use Diaspark\Location\Api\Data\LocationInterface;
class Location extends \Magento\Framework\Model\AbstractModel implements LocationInterface
{
/**
* CMS page cache tag.
*/
const CACHE_TAG = 'diaspark_location';
/**
* @var string
*/
protected $_cacheTag = 'diaspark_location';
/**
* Prefix of model events names.
*
* @var string
*/
protected $_eventPrefix = 'diaspark_location';
/**
* Initialize resource model.
*/
protected function _construct()
{
$this->_init('Diaspark\Location\Model\ResourceModel\Location');
}
/**
* Get EntityId.
*
* @return int
*/
public function getEntityId()
{
return $this->getData(self::ENTITY_ID);
}
/**
* Set EntityId.
*/
public function setEntityId($entityId)
{
return $this->setData(self::ENTITY_ID, $entityId);
}
/**
* Get Title.
*
* @return varchar
*/
public function getTitle()
{
return $this->getData(self::TITLE);
}
/**
* Set Title.
*/
public function setTitle($title)
{
return $this->setData(self::TITLE, $title);
}
public function getImage()
{
return $this->getData(self::IMAGE);
}
/**
* Set image
* @param string $image
*
*/
public function setImage($image)
{
return $this->setData(self::IMAGE, $image);
}
/**
* Get getContentFirst.
*
* @return varchar
*/
/**
* Get IsActive.
*
* @return varchar
*/
public function getLocationDescription()
{
return $this->getData(self::LOCATION);
}
/**
* Set PublishDate.
*/
public function setLocationDescription($location_description)
{
return $this->setData(self::LOCATION, $location_description);
}
public function getAddress()
{
return $this->getData(self::ADDRESS);
}
/**
* Set PublishDate.
*/
public function setAddress($address)
{
return $this->setData(self::ADDRESS, $address);
}
public function getContact()
{
return $this->getData(self::CONTACT);
}
/**
* Set PublishDate.
*/
public function setContact($contact)
{
return $this->setData(self::CONTACT, $contact);
}
public function getPublishDate()
{
return $this->getData(self::PUBLISH_DATE);
}
/**
* Set PublishDate.
*/
public function setPublishDate($publishDate)
{
return $this->setData(self::PUBLISH_DATE, $publishDate);
}
}
any help will be appreciated please
thanks
Best Answer
You can get media path by using below code:
The solution you used will return you URL path not Folder Path.