PHP code example of tourze / coupon-h5-link-bundle
1. Go to this page and download the library: Download tourze/coupon-h5-link-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Tourze\CouponH5LinkBundle\Entity\H5Link;
use Tourze\CouponCoreBundle\Entity\Coupon;
// Create a new H5 link
$h5Link = new H5Link();
$h5Link->setUrl('https://example.com/coupon-page');
$h5Link->setCoupon($coupon); // Associate with a coupon
// Save to database
$entityManager->persist($h5Link);
$entityManager->flush();
use Tourze\CouponH5LinkBundle\Repository\H5LinkRepository;
// Inject the repository
public function __construct(
private H5LinkRepository $h5LinkRepository
) {}
// Find H5 links
$h5Links = $this->h5LinkRepository->findAll();
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
use Doctrine\ORM\Events;
use Tourze\CouponH5LinkBundle\Entity\H5Link;
#[AsEntityListener(event: Events::prePersist, entity: H5Link::class)]
class H5LinkListener
{
public function prePersist(H5Link $h5Link): void
{
// Custom logic before saving
$this->validateUrl($h5Link->getUrl());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.