HOW TO create dynamic PHP pages to CMF?

Discuss everything related to ApPHP Durecty CMF. All versions. Any questions related to the Directy CMF developing or using should be posted to this forum.

Moderators: alexandrleonenko, alexmst

administrator
Site Admin
Site Admin
Posts: 6011
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO create dynamic PHP pages to CMF?

Postby administrator » Oct 1st, '16, 17:26

To add dynamic PHP pages to CMF you have t odo following:

1. Create new controller SitePagesController in directory protected/controllers/, call this file SitePagesController.php

Code: Select all

<?php
/**
 * SitePagesController controller
 *
 * PUBLIC:                  PRIVATE
 * ---------------          ---------------
 * __construct             
 *
 */

class SitePagesController extends CController
{
   
    /**
     * Class default constructor
     */
    public function __construct()
    {
        parent::__construct();
    }
   
}


2. Define action called "showAction" that will accept page name and will show appropriate view file:
For example:

Code: Select all

/**
 * Show action handler
 * @param string $msg
 */
public function showAction($name = '')
{
   if($name == 'about-us'){
      $this->_view->render('sitePages/about');
   }elseif($name == 'specialists'){
      $this->_view->render('sitePages/specialists');
   }elseif($name == 'medical-centers'){
      $this->_view->render('sitePages/medical-centers');
   }elseif($name == 'main-consultant'){
      $this->_view->render('sitePages/main-consultant');
   }elseif($name == 'contact-us'){
      $this->_view->render('sitePages/contact-us');
   }else{
      $this->redirect('Index/index');   
   }         
}



3. Add also define action to this controller:

Code: Select all

/**
 * Controller default action handler
 */
public function indexAction()
{
   $this->redirect('Index/index');
}


4. Create new sub-directory called sitePages in directory protected/views

5. Create in directory sitepages view files for each rendered view.
For example:

Code: Select all

<?php
$this->_pageTitle = 'About Us';
$this->_activeMenu = 'about-us';
?>
<section id="middle">
   <div class="headline">
      <h1>About Us</h1>
   </div>
   <div class="cmsms_breadcrumbs">
      <a href="Index/index" class="cms_home">Home</a>
      <span class="breadcrumbs_sep">/</span>
      <span>About Us</span>
   </div>   
   <div class="content_wrap fullwidth">
               ... text here
   </div>
</section>


6. In protected protected/config/main.php file add new URL rules.
For example:

Code: Select all

// Url manager
'urlManager' => array(
   'urlFormat' => 'shortPath',  /* get | path | shortPath */
   'rules' => array(
      'paymentProviders/handlePayment/([a-zA-Z0-9\_]+)' => 'paymentProviders/handlePayment/provider/{$0}',
      'paymentProviders/handlePayment/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)' => 'paymentProviders/handlePayment/provider/{$0}/handler/{1}',
      'about-us' => 'sitepages/show/name/about-us',
      'specialists' => 'sitepages/show/name/specialists',
      'medical-centers' => 'sitepages/show/name/medical-centers',
      'main-consultant' => 'sitepages/show/name/main-consultant',
      'contact-us' => 'sitepages/show/name/contact-us',
   ),
),



That's All!!!
You may now access your pages by typing in browser:
your-site.com/about-us, your-site.com/specialists etc.

Of course, you may always access these page by typing a full path:
your-site.com/sitepages/show/name/about-us, your-site.com/sitepages/show/name/specialists etc.

jfreitas
Newbie
Newbie
Posts: 1
Joined: Mar 20th, '14, 12:52

Re: HOW TO create dynamic PHP pages to CMF?

Postby jfreitas » Feb 11th, '18, 22:57

Not functional, returns HTTP 500 error.

Is the missing required information in main.php - see below:

// Required by dynamic pages, if you want t ouse user-friendly URLs
// 'controller / action / value1 / value2' => 'controller / action / param1 / value1 / param2 / value2',
'about-us' => 'sitePages / show / name / about-us',

administrator
Site Admin
Site Admin
Posts: 6011
Joined: Jan 7th, '09, 23:18
Contact:

Re: HOW TO create dynamic PHP pages to CMF?

Postby administrator » Feb 12th, '18, 14:37

Turn on debug mode and check what exactly this error means.


Return to “ApPHP Directy CMF {developers/users}”