I am creating a CMS that uses an MVC-structure to create/modify/delete pages of a website.
I have lots of objects where I store my data in.
E.g. a $sitemodel with:
$site-id$page-template- etc.
To create a new page, I added a button in the HTML:
<ul class="nav nav-pills nav-stacked nav-bracket">
<li class="_add-page">
<a href="#user/sites/new">
<i class="fa fa-plus"></i>
<span> Voeg een pagina toe</span>
</a>
</li>
</ul>
I use jQuery to create an event:
$(document).ready(function(){
$("#test-id").click(function(ev){
ev.preventDefault();
$(".site_creator").load("add_page.php");
});
});
The add_page.php calls the following function:
$pagecontroller->new_page($sitemodel->ID);
This on its turn calls the following function:
public function new_page($site-ID)
{
$pagemodel = new page_model;
$page_ID=$pagemodel->insert_pagemodel($site-ID);
return $page_ID;
}
And finally the SQL function from the pagemodel:
public function insert_pagemodel($site-ID)
{
$sSQL = "INSERT INTO `pages` (object) VALUES (".$site-ID.");
if (mysql_query($sSQL)) {$this->ID = mysql_insert_id();} else {return false;}
return $this->ID;
}
What I am trying to understand is: how do I get to use the methods from my $page-controller and $site-controller in add_page.php?
From my research I find two options:
- $_SESSION variable (rather not, because then I have to add session to all my files)
- Adding them into the .load function, after ("
add_page.php",{})
I am trying to use option 2, but I have no idea how to get my data from PHP into the JavaScript? And is it even possible to add the methods of the classes into the ajax call?
I am trying to see the whole picture here, but it looks to me like I am missing something?
How do I get the data and methods from my objects into the create_page.php?