Comments (15)
Probably this is NOT a question about this SDK, this is a PHP question.
I'll show you an implementation sample of carousel with foreach
statement;
$imageUrl = 'https://example.com/path/to/your/image.png';
$columnTemplateBuilders = array();
$columnTitles = array('foo', 'bar', 'buz');
foreach ($columnTitles as $title) {
$columnTemplateBuilder = new CarouselColumnTemplateBuilder($title, 'description', $imageUrl, [
new UriTemplateActionBuilder('Go to line.me', 'https://line.me'),
new PostbackTemplateActionBuilder('Buy', 'action=buy&itemid=123'),
]);
array_push($columnTemplateBuilders, $columnTemplateBuilder);
}
$carouselTemplateBuilder = new CarouselTemplateBuilder($columnTemplateBuilders);
$templateMessage = new TemplateMessageBuilder('Button alt text', $carouselTemplateBuilder);
$this->bot->replyMessage($replyToken, $templateMessage);
from line-bot-sdk-php.
ThumbnailImageUrl must be "HTTPS".
from line-bot-sdk-php.
$option = array();
$imageUrl = "https://image.slidesharecdn.com/kelompok3-141030011817-conversion-gate01/95/multimedia-gambar-1-638.jpg";
foreach ($data as $data) {
$option = new CarouselColumnTemplateBuilder('foo', 'bar', $imageUrl, [
new UriTemplateActionBuilder('Go to line.me', 'https://line.me'),
new PostbackTemplateActionBuilder('Buy', 'action=buy&itemid=123'),
]);
}
$carouselTemplateBuilder = new CarouselTemplateBuilder($option);
$messageBuilder = new TemplateMessageBuilder('Button alt text', $carouselTemplateBuilder);
How i add Carousel using Foreach? Because when i using foreach always return "500 Internal Server Error"
from line-bot-sdk-php.
First of all, foreach ($ data as $ data)
is wrong. $data
is duplicated.
In addition, it is meaningless that you assign CarouselColumnTemplateBuilder
to $option
each time you loop.
from line-bot-sdk-php.
i change foreach ($ data as $ data)
with foreach ($ data as $ value)
but it's same..
would you like to give me a example with foreach?
from line-bot-sdk-php.
It is not example of foreach
, but I think this sample code will be helpful.
thanks.
from line-bot-sdk-php.
my references same with your link, but i confused with foreach... i think my foreach is true ( for me )
but i wrong... so what must i do now?
from line-bot-sdk-php.
Please paste the code more detail.
from line-bot-sdk-php.
And could you show us the error log of your application?
from line-bot-sdk-php.
$city = $this->api_m->getCity();
foreach($city as $v) {
if ($v->name == $_POST['city']) {
$data = $this->api_m->getDetail($v->id);
}
}
$option = array();
$imageUrl = "https://image.slidesharecdn.com/kelompok3-141030011817-conversion-gate01/95/multimedia-gambar-1-638.jpg";
foreach ($data as $data) {
$option = new CarouselColumnTemplateBuilder('foo', 'bar', $imageUrl, [
new UriTemplateActionBuilder('Go to line.me', 'https://line.me'),
new PostbackTemplateActionBuilder('Buy', 'action=buy&itemid=123'),
]);
}
$carouselTemplateBuilder = new CarouselTemplateBuilder($option);
$messageBuilder = new TemplateMessageBuilder('Button alt text', $carouselTemplateBuilder);
$this->bot->pushMessage($userid, $messageBuilder);
@be-hase : Problem in Foreach
@moznion : i use heroku.com, so there's not found error log... just response 500
from line-bot-sdk-php.
Why don't you use array_push
?
http://php.net/manual/ja/function.array-push.php
from line-bot-sdk-php.
foreach ($data as $v) {
$isi = new CarouselColumnTemplateBuilder('foo', 'bar', $imageUrl, [
new UriTemplateActionBuilder('Go to line.me', 'https://line.me'),
new PostbackTemplateActionBuilder('Buy', 'action=buy&itemid=123'),
]);
array_push($option, $isi);
}
like this? Bot not respon too
from line-bot-sdk-php.
Please try it.
(But I cannot understand what you want to do. Why do you use foreach
statement like so? It looks that makes no sense)
from line-bot-sdk-php.
i have a API, i want make a Carousel with my API Data...
from line-bot-sdk-php.
{
"status": "success",
"kota": "Surabaya",
"date": "15\/02\/17",
"data": [
{
"movie": "BALLERINA",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Animation, Adventure, Family",
"duration": "90 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"14:45",
"19:00"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "CEK TOKO SEBELAH",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Drama, Comedy",
"duration": "104 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"12:30",
"16:45",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "GALAXY XXI",
"jam": [
"12:15",
"14:30",
"16:45",
"19:00",
"21:15"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "FROM LONDON TO BALI",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Comedy, Romantis",
"duration": "91 minute",
"jadwal": [
{
"bioskop": "DELTA",
"jam": [
"12:30",
"14:40",
"16:50",
"19:00",
"21:10"
],
"harga": "Rp.35,000"
},
{
"bioskop": "ROYAL",
"jam": [
"12:30",
"14:40",
"16:50",
"19:00",
"21:10"
],
"harga": "Rp.40,000"
}
]
},
{
"movie": "GENERASI KOCAK: 90AN VS KOMIKA",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Comedy",
"duration": "80 minute",
"jadwal": [
{
"bioskop": "CITO 21",
"jam": [
"12:45",
"14:45",
"16:45",
"18:45",
"20:45"
],
"harga": "Rp.40,000"
},
{
"bioskop": "SURABAYA TOWN SQUARE 21",
"jam": [
"12:45",
"14:45",
"16:45",
"18:45",
"20:45"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN PLAZA XXI",
"jam": [
"12:45",
"14:45",
"16:45",
"18:45",
"20:45"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "GUNUNG KAWI",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Horror",
"duration": "95 minute",
"jadwal": [
{
"bioskop": "DELTA",
"jam": [
"13:00",
"15:00",
"17:00",
"19:00",
"21:00"
],
"harga": "Rp.35,000"
},
{
"bioskop": "TUNJUNGAN 3 XXI",
"jam": [
"13:00",
"15:00",
"17:00",
"19:00",
"21:00"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "JOHN WICK: CHAPTER 2",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Action, Crime, Thriller",
"duration": "122 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD PREMIERE",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.100,000"
},
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "CITO 21",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.40,000"
},
{
"bioskop": "GALAXY XXI",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "GRAND CITY PREMIERE",
"jam": [
"18:00",
"20:30"
],
"harga": "Rp.100,000"
},
{
"bioskop": "GRAND CITY XXI",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "LENMARC PREMIERE",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.100,000"
},
{
"bioskop": "LENMARC XXI",
"jam": [
"13:15",
"15:45",
"18:15",
"20:45"
],
"harga": "Rp.40,000"
},
{
"bioskop": "PAKUWON CITY XXI",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SUPERMAL XXI",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SURABAYA TOWN SQUARE 21",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN 5 PREMIERE",
"jam": [
"13:00",
"15:30",
"18:00",
"20:30"
],
"harga": "Rp.100,000"
},
{
"bioskop": "TUNJUNGAN 5 XXI",
"jam": [
"13:15",
"15:45",
"18:15",
"20:45"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN PLAZA XXI",
"jam": [
"13:30",
"16:00",
"18:30",
"21:00"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "KUNG FU YOGA",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Action, Adventure, Comedy",
"duration": "107 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"12:30",
"14:45",
"17:00",
"19:15",
"21:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "CITO 21",
"jam": [
"12:30",
"14:45",
"17:00",
"19:15",
"21:30"
],
"harga": "Rp.40,000"
},
{
"bioskop": "GALAXY XXI",
"jam": [
"12:30",
"14:45",
"17:00",
"19:15",
"21:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "GRAND CITY XXI",
"jam": [
"12:30",
"14:45",
"17:00",
"19:15",
"21:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "LENMARC XXI",
"jam": [
"19:00",
"21:15"
],
"harga": "Rp.40,000"
},
{
"bioskop": "PAKUWON CITY XXI",
"jam": [
"12:30",
"14:45",
"17:00",
"19:15",
"21:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SUPERMAL XXI",
"jam": [
"12:30",
"14:45",
"17:00",
"19:15",
"21:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SURABAYA TOWN SQUARE 21",
"jam": [
"19:00",
"21:15"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN 3 XXI",
"jam": [
"12:30",
"14:45",
"17:00",
"19:15",
"21:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN 5 XXI",
"jam": [
"12:15",
"14:30",
"16:45",
"19:00",
"21:15"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "LA LA LAND",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Comedy, Drama, Musical",
"duration": "128 minute",
"jadwal": [
{
"bioskop": "GRAND CITY XXI",
"jam": [
"18:45",
"21:20"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "REMEMBER THE FLAVOR",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Drama",
"duration": "92 minute",
"jadwal": [
{
"bioskop": "ROYAL",
"jam": [
"13:00",
"15:00",
"17:00",
"19:00",
"21:00"
],
"harga": "Rp.40,000"
},
{
"bioskop": "SURABAYA TOWN SQUARE 21",
"jam": [
"13:00",
"15:00",
"17:00",
"19:00",
"21:00"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN 3 XXI",
"jam": [
"12:45",
"14:45",
"16:45",
"18:45",
"20:45"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "RESIDENT EVIL: THE FINAL CHAPTER",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Action, Horror, Sci-fi",
"duration": "106 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"12:45",
"14:55",
"17:05",
"19:15",
"21:25"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SURABAYA TOWN SQUARE 21",
"jam": [
"12:30",
"14:40",
"16:50"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN PLAZA XXI",
"jam": [
"16:50",
"19:00",
"21:10"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "SPLIT",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Horror, Thriller",
"duration": "117 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD PREMIERE",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.100,000"
},
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.50,000"
},
{
"bioskop": "CITO 21",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.40,000"
},
{
"bioskop": "GALAXY XXI",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.50,000"
},
{
"bioskop": "GRAND CITY PREMIERE",
"jam": [
"13:15",
"15:40"
],
"harga": "Rp.100,000"
},
{
"bioskop": "GRAND CITY XXI",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.50,000"
},
{
"bioskop": "LENMARC XXI",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.40,000"
},
{
"bioskop": "PAKUWON CITY XXI",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SUPERMAL XXI",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SURABAYA TOWN SQUARE 21",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN 5 PREMIERE",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.100,000"
},
{
"bioskop": "TUNJUNGAN 5 XXI",
"jam": [
"12:00",
"14:25",
"16:50",
"19:15",
"21:40"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "SURGA YANG TAK DIRINDUKAN 2",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Drama",
"duration": "121 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "CITO 21",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.40,000"
},
{
"bioskop": "DELTA",
"jam": [
"12:45",
"13:30",
"15:10",
"15:55",
"17:35",
"18:20",
"20:00",
"20:45"
],
"harga": "Rp.35,000"
},
{
"bioskop": "GRAND CITY XXI",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "LENMARC XXI",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.40,000"
},
{
"bioskop": "PAKUWON CITY XXI",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "ROYAL",
"jam": [
"12:45",
"13:30",
"15:10",
"15:55",
"17:35",
"18:20",
"20:00",
"20:45"
],
"harga": "Rp.40,000"
},
{
"bioskop": "SUPERMAL XXI",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "SURABAYA TOWN SQUARE 21",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN 3 XXI",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN PLAZA XXI",
"jam": [
"13:15",
"15:40",
"18:05",
"20:30"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "THE LEGO BATMAN MOVIE",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Animation, Action, Adventure",
"duration": "104 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"12:15",
"14:25",
"16:35",
"18:45",
"20:55"
],
"harga": "Rp.50,000"
},
{
"bioskop": "GALAXY XXI",
"jam": [
"12:45",
"14:55",
"17:05",
"19:15",
"21:25"
],
"harga": "Rp.50,000"
},
{
"bioskop": "GRAND CITY XXI",
"jam": [
"12:45",
"14:55",
"17:05",
"19:15",
"21:25"
],
"harga": "Rp.50,000"
},
{
"bioskop": "LENMARC XXI",
"jam": [
"12:30",
"14:40",
"16:50"
],
"harga": "Rp.40,000"
},
{
"bioskop": "SUPERMAL XXI",
"jam": [
"12:15",
"14:25",
"16:35",
"18:45",
"20:55"
],
"harga": "Rp.50,000"
},
{
"bioskop": "TUNJUNGAN PLAZA XXI",
"jam": [
"12:30",
"14:40"
],
"harga": "Rp.50,000"
}
]
},
{
"movie": "THE LEGO BATMAN MOVIE (IMAX 3D)",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Animation, Action, Adventure",
"duration": "104 minute",
"jadwal": [
{
"bioskop": "TUNJUNGAN 5 <img border=\"0\" alt=\"logo_mtix\" src=\"html\/images\/logo_imax.png\">",
"jam": [
"12:30",
"14:40",
"16:50",
"19:00",
"21:10"
],
"harga": "Rp.60,000"
}
]
},
{
"movie": "XXX RETURN OF XANDER CAGE",
"poster": "http:\/\/ibacor.com\/bcr_asset\/images\/poster.jpg",
"genre": "Action, Adventure, Thriller",
"duration": "106 minute",
"jadwal": [
{
"bioskop": "CIPUTRA WORLD XXI",
"jam": [
"13:00",
"15:10",
"17:20",
"19:30",
"21:40"
],
"harga": "Rp.50,000"
},
{
"bioskop": "GRAND CITY XXI",
"jam": [
"12:15",
"14:25",
"16:35"
],
"harga": "Rp.50,000"
}
]
}
]
}
from line-bot-sdk-php.
Related Issues (20)
- [Bug Report] Undefined index: imageSet HOT 3
- [Bug Report] An Undefined array key "keywords" error occurs when a StickerMessage has no keywords HOT 1
- [Feature Request] Send multiple messages at once. HOT 2
- Flex Message Update 3 released
- Webhook redelivery HOT 1
- Confirm template has location button is not working HOT 2
- Automatic opening and closing of the rich menu when tapping a rich menu HOT 1
- Added "inputoOption" property to action object HOT 2
- Validate rich menu object HOT 1
- [Bug Report] Placing required parameters after optional parameters is deprecated HOT 1
- [Bug Report] ImageSet event without index/total make Undefined index access HOT 3
- Dependency Dashboard
- fix(ci): set-output in Github Actions to be deprecated
- Validating message objects HOT 1
- [Feature Request] Enable to set `trackingId` via `VideoMessageBuilder` HOT 1
- Get content transcoding status and a preview image HOT 1
- @All in the mention property of the webhooks HOT 1
- [Feature Request] Automatically generate code with github actions when renovate updates
- Add doc
- CI should run openapi-generator, and run test after it
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from line-bot-sdk-php.