1. Go to this page and download the library: Download vietiso/oneguide 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/ */
vietiso / oneguide example snippets
use Vietiso\OneGuide\Client;
$client = new Client([
'api_key' => 'xxxxxxxxx',
'secret' => 'xxxxxxxxxxxxx',
'url' => 'https://api.oneguide.example/api',
]);
use Vietiso\OneGuide\Tour\Tour;
use Vietiso\OneGuide\Tour\TourType;
use Vietiso\OneGuide\Tour\Itinerary;
use Vietiso\OneGuide\Tour\Operator;
use Vietiso\OneGuide\Service\Service;
use Vietiso\OneGuide\Service\ServiceType;
// Thông tin chung
$tour = new Tour($client);
$tour
->setId(111) // ID tour bên hệ thống của bạn (external id)
->setStartDate(new DateTime('2026-01-01'))
->setType(TourType::PRIVATE) // PRIVATE | SIC | OUTBOUND
->setNumberAdult(1) // Phải > 0
->setCode('HNHP2DAY3NIGHT')
->setTitle('Hà Nội Hải Phòng 2 ngày 3 đêm')
->setNumberDay(3)
->setNumberNight(2);
// Hành trình theo ngày (bắt buộc có ít nhất một)
$tour->addItinerary(
(new Itinerary())
->setTitle('Ngày 1')
->setDayNumber(1)
->setImage('https://example.com/day1.jpg') // Phải là URL hợp lệ
);
// Dịch vụ đi kèm
$tour->addService(
(new Service())
->setType(ServiceType::SIC)
->setTitle('Dịch vụ test')
->setTourDays([1, 2, 3])
);
// Điều hành viên (bắt buộc có ít nhất một)
$tour->addOperator(
(new Operator())
->setName('Nguyễn Văn A')
->setEmail('[email protected]')
->setPhone('0325305738') // Tối đa 20 ký tự
->setAvatar('https://example.com/avatar.jpg')
);
// Validate rồi đẩy lên OneGuide (ném ValidationException nếu dữ liệu sai/thiếu)
$tour->sync();
use Vietiso\OneGuide\Tour\Tour;
use Vietiso\OneGuide\Guide\Guide;
$tour = new Tour($client);
$tour->setId(111); // ID tour cần gán
$guide = new Guide('148235149'); // number_card: số thẻ hướng dẫn viên
$guide->setEmail('[email protected]'); // Email bắt buộc & phải hợp lệ
$guide->setPhone('0327145495');
// Tham số thứ hai là các ngày trong tour mà hướng dẫn viên phụ trách
$tour->addGuide($guide, [1, 2, 3, 4]);
$tour->syncGuides();
use Vietiso\OneGuide\Province\Province;
$province = new Province($client);
// Cách 1 (khuyến nghị): foreach tự lấy hết các trang
$provinces = [];
foreach ($province->list() as $item) {
$provinces[] = $item;
}
// Cách 2: lặp thủ công bằng con trỏ
$provinces = [];
$page = $province->list();
$provinces = array_merge($provinces, $page->getItems());
while ($page->hasMore()) {
$page = $province->list(null, 10, $page->getNextCursor());
$provinces = array_merge($provinces, $page->getItems());
}
use Vietiso\OneGuide\Exception\ValidationException;
use Vietiso\OneGuide\Exception\ApiException;
try {
$tour->sync();
} catch (ValidationException $e) {
// Dữ liệu sai trước khi gửi
echo $e->getMessage();
} catch (ApiException $e) {
// Lỗi từ phía server
echo $e->getStatusCode() . ': ' . $e->getMessage();
if ($e->hasErrors()) {
var_dump($e->getErrors());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.