Pole 'cats' to pole wyboru z aplikacji Angular, zawierające dane z tabel kotów, o identyfikatorze, nazwie i module_id.Ustaw json w tablicy mysql return Array
funkcyjne na Slim ram dodać elementy ..
function addItem($section) {
$request = \Slim\Slim::getInstance()->request();
$item = json_decode($request->getBody());
$sql = "INSERT INTO " .$section. " (title, subtitle, slug, excerpt, originalDate, content, cats, published) VALUES (:title, :subtitle, :slug, :excerpt, :originalDate, :content, :cats, :published)";
try {
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("title", $item->title);
$stmt->bindParam("subtitle", $item->subtitle);
$stmt->bindParam("slug", $item->slug);
$stmt->bindParam("excerpt", $item->excerpt);
$stmt->bindParam("originalDate", $item->originalDate);
$stmt->bindParam("content", $item->content);
$stmt->bindParam("cats", $item->cats);
$stmt->bindParam("published", $item->published);
$stmt->execute();
$item->id = $db->lastInsertId();
$db = null;
print_r(json_encode($item));
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
kod kątowe, do zaznaczania
<div class="col-sm-12 m-b-30">
<p class="f-500 c-black m-b-15">Categorias</p>
<div class="btn-group bootstrap-select show-tick">
<button type="button" class="btn selectpicker btn-default" ng-model="item.cats" data-toggle="dropdown" title="Selecione a Categoria" aria-expanded="false" data-html="1" data-multiple="1" bs-options="cats.id as cats.name for cats in categorias" bs-select>
Selecione a categoria <span class="caret"></span>
</button>
</div>
</div>
koty, powrót Array na kolumnie mysql
Wszelkie pomysły ?!
Przykład Internecie: http://45.55.73.98/angular-admin/api/v1/s/posts
Aktualizacja!
$cats = null;
foreach ($item->cats as $cat) {
$cats .= $cat . ",";
}
i
$stmt->bindParam("cats", $cats);
post przez JSON = kotów \t [ "1", "2"] \t zawartość \t "dfgdfgdfg" \t fragment \t "dfgdfgdfg" \t oryginałData \t "2015-06-24T03: 00: 00.000Z" \t opublikowane \t prawdziwymi \t sekcja \t "posty" \t ślimak \t "gdfg" \t napisów \t "GDF" \t tytuł –
Czy umieścisz swój kod Angular –
Dodałem kod teraz, odpowiedź json ten ostatni link –