Issue
I'm new to cakephp2 and I would want to have some help. I want to make a sitemap xml for the website I made with cakephp2 but I have no clue to how to make a function that will generate the xml and save it to the webroots file with cakephp2. I read the official document, but I still cannot find the solution.
Solution
Something like this will do. only a part though.
public function display() {
$sitemapData = array();
//Generate a list of Models in the App
$listOfModels = $this->_generateListOfModels();
//foreach model
foreach($listOfModels as $model) {
App::uses($model, 'Model');
// We need to load the class
$newModel = new $model;
if (!empty($newModel->actsAs) && array_key_exists('Sitemap.Sitemap', $newModel->actsAs)) {
$response = $newModel->generateSitemapData();
$sitemapData[$newModel->name] = $response;
} else {
}
unset($newModel);
}
//Generate Sitemap of Static Pages
$sitemapData['Page'] = $this->_generateListOfStaticPages();
$this->set('sitemapData', $sitemapData);
}
/**
* _generateListOfModels - generate the list of models
*
* @return [type] [description]
*/
protected function _generateListOfModels() {
//Generate list of Models
$appModelClasses = App::objects('Model');
$listOfModels = array();
//Foreach Model
foreach ($appModelClasses as $modelClass) {
if ($modelClass != 'AppModel') {
// Load the Model
App::import('Model', str_replace('Model', '', $modelClass));
$listOfModels[] = $modelClass;
}
}
return $listOfModels;
}
Answered By - user3728425 Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.