javascript で作成された envato マーケット プレイスから modalbox プラグインを購入しました。これを使用して、カテゴリ > サブカテゴリ > アイテムを実装したいと考えています。とにかく、PHPを使用してJavaScript変数に値を割り当てることができることは知っていますが、反対が必要です。
私の最初のステップでは、基本的なリンクを使用してユーザーにカテゴリを選択させ、onclick で 2 番目のスライドに移動し、選択したこのカテゴリに関連するサブカテゴリとアイテムを表示します。
私は2つのことを試しました:
1) setting onClick = "step2();<?php $chosen_cat = ' . $this->db->escape(trim($category)) . '?>"
選択したカテゴリの名前を値に割り当てるだけで、step2() javascript メソッドで $chosen_cat を使用して製品を表示できることを願っていますが、出力に競合があるため、javascript が壊れます。
2) step2() を step2(category) に変更してから、onclick="step2(db->escape($category););" を使用しました。これは値を step2() メソッドに渡しますが、今は呼び出す必要がありますクライアント関係ですが、戻ってきました..
$this->db->escape() はhttp://codeigniter.com/user_guide/database/queries.html codeigniter メソッドです。
私のコード:
<script type="text/javascript">
function step1() {
modalbox.show(new Element("div").insert(
new Element("p", { "align": "justify" }).insert(
<?php
$categories = $items;
$chosen_cat = '';
?>
<?php
$i = 0;
foreach($categories as $category => $itemarray) {
$i++;
if($i==27){
echo $this->db->escape('<a class="category" onclick="step2();<?php $chosen_cat = ' . $this->db->escape(trim($category)) . '?>" href="#">'. trim($category) . '</a>');
}
else {
echo $this->db->escape('<a class="category" onclick="step2();" href="#">' . trim($category) . '</a>') . '+';
}
}
?>
)
), {
"title" : "Step 1/3",
"width" : 800,
"options" : [{
"label" : "Next »",
"onClick" : step2
}]
});
};
function step2() {
alert(<?php $this->db->escape($chosen_cat); ?>);
modalbox.show([ new Element("div").insert(
new Element("p", { "align": "justify" }).insert(
"If you open a modalbox when another one is opened, it will stretch to the new " +
"modalbox width and height and overwrite the content.<br /\><br /\>" +
"You can use HTML or Prototype Elements like a DIV or a TABLE."
)
),
new Element("p", { "align": "justify" }).insert(
"You can have multiple contents on a single modalbox by using an array like this:<br /\><br /\>" +
"<pre>modalbox.show([ content1, content2, ... ], options);</pre>"
)
], {
"title" : "Step 2/3",
"width" : 800,
"options" : [{
"label" : "« Previous",
"onClick" : step1
}, {
"label" : "Next »",
"onClick" : step3
}]
});
};
function step3() {
modalbox.show([ new Element("div").insert(
new Element("p", { "align": "justify" }).insert(
"If you open a modalbox when another one is opened, it will stretch to the new " +
"modalbox width and height and overwrite the content.<br /\><br /\>" +
"You can use HTML or Prototype Elements like a DIV or a TABLE."
)
),
new Element("p", { "align": "justify" }).insert(
"You can have multiple contents on a single modalbox by using an array like this:<br /\><br /\>" +
"<pre>modalbox.show([ content1, content2, ... ], options);</pre>"
)
], {
"title" : "Step 3/3",
"width" : 800,
"hideOnPageClick": false,
"options" : [{
"label" : "« Previous",
"onClick" : step2
}, {
"label" : "Finish",
"isDefault" : true,
"onClick" : modalbox.hide
}]
});
};
</script>
onclick イベントで JavaScript を使用してセッション変数を設定し、js スタイルで $_SESSION['category'] = 'category' と言ってから、そのセッションを php で読み取り、設定を解除することは可能でしょうか。これにより多くのセキュリティが作成されるとは思いませんセッションが約 1 秒未満しか存在しないため、問題が発生します。