我尝试使用Smarty。现在我有正确的文件路径问题。 所有代码现在都有效。我完全不知道怎么做 DIR 。 我有什么:
Smarty的
CartController.php
/**
*
* Add product to cart
*
* @param integer id GET - ID of adding product
* @return json info about operation (success, number of elements in cart)
*/
function addtocartAction(){
$itemId = isset($_GET['id']) ? intval($_GET['id']) : NULL;
if (! $itemId) {
return FALSE;
}
$resData = array();
if (isset($_SESSION['cart'])){
$_SESSION['cart'][] = $itemId;
$resData['cntItems'] = count($_SESSION['cart']);
$resData['success'] = 1;
} else {
$resData['success'] = 0;
}
echo json_encode($resData);
}
/**
*
* Making cart page
*
* @link /cart/
*/
function indexAction($smarty) {
$itemsIds = isset($_SESSION['cart']) ? $_SESSION['cart'] : array();
$rsCategories = getAllMainCatsWithChildren();
$rsKits8 = getKitsByCat(4);
$rsKits16 = getKitsByCat(5);
$rsSortsHoney = getLastSortsHoney();
$rsSortsHoneyKits8 = getAllKits8WithSorts();
$rsSortsHoneyKits16 = getAllKits16WithSorts();
$rsCartKits = getKitsFromArray($itemsIds);
$rsCount = getCountKitsFromArray($itemsIds);
$smarty->assign('pageTitle', 'Cart');
$smarty->assign('rsCategories', $rsCategories);
$smarty->assign('rsKits8', $rsKits8);
$smarty->assign('rsKits16', $rsKits16);
$smarty->assign('rsSortsHoney', $rsSortsHoney);
$smarty->assign('rsSortsHoneyKits8', $rsSortsHoneyKits8);
$smarty->assign('rsSortsHoneyKits16', $rsSortsHoneyKits16);
$smarty->assign('rsCartKits', $rsCartKits);
$smarty->assign('rsCount', $rsCount);
loadTemplate($smarty, 'cart');
}
然后我做了这个功能
的JavaScript
function addToCart(itemId) {
$.ajax({
type: 'POST',
url: "/cart/addtocart/" + itemId + '/',
dataType: 'json',
success: function (data) {
if (data['success']) {
$('#cartCntItems').html(data['cntItems']);
$('#from-ajax').load('http://fashionhoney.local/cart/');
}
}
});
};
$(document).on('click', '.addToCart', function (e) {
e.preventDefault();
addToCart(this.id.split('_')[1]);
});
现在我真的不知道如何在这一行设置正确的路径
$('#from-ajax').load('http://fashionhoney.local/cart/');
如何自动配置 DIR ?