MVC in Joomla

学习了一下joomla里mvc的实现

MVC_joomla

MVC_joomla

  1. require_once( JPATH_COMPONENT.DS.’controller.php’ );
    JPATH_COMPONENT is the absolute path to the current component.
    DS is the directory separator of your system
  2.  Controller class extends JController and override display method
  3. View Claa extends Jview
    1. class HelloViewHello extends JView
    {
        function display($tpl = null)
        {
            $greeting = "Hello World!";
            $this->assignRef( 'greeting', $greeting );
    
            parent::display($tpl);
        }
    }
  4. Last step is to create a template:
    <?php
    // No direct access
    defined('_JEXEC') or die('Restricted access'); ?>
    <h1><?php echo $this->greeting; ?></h1> 
    Original Article   We can also add model and use database in model.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s