hello,
i have a _func.php file with this function. in the documentation i read that some api variables in functions are not available, so i use wire('pages').
function doSomething($u, $p) {
$p = wire('pages')->get("id=$p");
$u = wire('pages')->get("id=$u");
$p->of(false);
{ ... populate repeater field stuff }
$p->save();
}
if i call this function in my home.php like doSomething(41,1093) (only for testing!) everything is fine, the function works, it add items to a repeater field.
the german says "Wenn es dem Esel zu wohl ist, geht er aufs Eis", so i play around with ajax to fire up this function.
$(document).ready(function() {
$("#hit").click(function(){
$.ajax({
url: '<?= $config->urls->templates?>includes/_func.php/',
type: 'post',
data: {userID: "<?= $user->id ?>", pageID: "<?= $page->id ?>"},
success: function(output){
console.log(output);
}
})
})
})
i read something about variable scopes and i think i understand it a little bit. but i don't understand why doSomething(41,1093) works in home.php the ajax call runs into a Call to undefined function wire() ? also i tried if ($config->ajax) but no luck ...
that's the relevant party of _func.php.
function doSomething($u, $p) {
$p = wire('pages')->get("id=$p");
$u = wire('pages')->get("id=$u");
$p->of(false);
{ ... populate repeater field stuff }
$p->save();
}
if(isset($_POST['userID']) && !empty($_POST['userID']) && isset($_POST['pageID']) && !empty($_POST['pageID'])) {
$u = $_POST['userID'];
$p = $_POST['pageID'];
{ ... }
echo sendLike($u, $p);
}
where is my mistake? any ideas?
thx