Hey guys,
First I have to say that I'm not an expert in php etc. :/
On my page their are 4 div container (header, navi, content, footer) and only the content div should be changed everytime a link is clicked or a form is submitted. I chose Jquery/ajax for this.
Currently I use for example this code:
<script type="text/javascript">
$(document).ready(function() {
$("#searchform").submit(function() {
var clustername = $("#cname").val();
$("#content").load("search/" + clustername);
return false;
});
});
</script>
And the controller:
public function searchAction($cname)
{
//Nach Cluster suchen
if (!empty($cname)) {
$result = cluster::find(array(
"clustername like :clustername:",
"bind" => ["clustername" => $cname]
));
if ($result == false || empty($result) || count($result) == 0) {
$this->flashSession->notice("Kein Cluster gefunden!");
return $this->response->redirect("cluster/noCluster");
};
return $this->view->clusters = $result;
}
else {
$this->flashSession->error("Es wurde kein Name eingegeben!");
return $this->response->redirect("cluster/noCluster");
};
}
But I think this is only a workaround? and there has to be a diffrent method to achieve the same result.
So I tried something like this:
<script type="text/javascript">
$(document).ready(function() {
$("#searchform").submit(function() {
var clustername = $("#cname").val();
$.ajax({
type:"POST",
url:"cluster/search",
data:{cname:clustername},
success:function(){
return false;
};
});
});
});
</script>
And I changed my controller to this:
public function searchAction()
{
$cname = $_POST["cname"];
....
}
But I do something wrong, because it shows a new blank page with the result of my search.
I hope someone could help me with "my problem" and give some hints/examples.
PS: Sry for my bad english