PHP code example of ivanamat / cakephp3-documents

1. Go to this page and download the library: Download ivanamat/cakephp3-documents library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ivanamat / cakephp3-documents example snippets


    Plugin::load('Documents', ['bootstrap' => false, 'routes' => true]);

    Configure::write('Documents.home', ['plugin' => false, 'controller' => 'Pages', 'action' => 'display', 'home']);

    Configure::write('Documents.index', '../INDEX.md');

    /**
     * Allow CategoriesController actions
     * @actions: index, edit
     */
    Configure::write('Categories.auth.allow', ['index','edit']);

    /**
     * Allow DocumentsController actions
     * @actions: index, view, add, edit, delete
     **/
    Configure::write('Documents.auth.allow', ['index','view']);

    $slug = $this->Docs->slugCategory($id);
    # Example $slug value: 'proyectos/cakephp/plugins'
    echo '<a href="/' . $this->plugin . DS . $slug . '"><strong>'.$category->title.'</strong></a>';

    $slug = $this->Docs->slugDocument($id);
    # Example $slug value: 'proyectos/cakephp/plugins/cakephp-3-x-markdown-documents'
    echo '<a href="/' . $this->plugin . DS . $slug . '"><strong>'.$document->title.'</strong></a>';

    $category = $this->Docs->getCategory($id);
    echo '<h2>'.$category->title.'</h2>';

    # $slug = 'projects/cakephp/plugins/cakephp-3-x-markdown-documents'
    $parentSlug = $this->Docs->getParentSlug($slug);
    # $parentSlug will output 'projects/cakephp/plugins'
    echo '<a href="/' . $this->plugin . DS . $parentSlug . '"><strong>Parent category</strong></a>';

    $relatedDocuments = $this->Docs->getParentSlug($slug);
    foreach($relatedDocuments as $document) {
        echo '<h4>' . $document->title . '</h4>';
        echo $this->Markdown->parse($document->body);
    }