PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to make a sitemap.xml with Cakephp2 shell?

 April 22, 2022     cakephp, cakephp-2.3, shell, sitemap, xml     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing