Joomla-如何将数据从子控制器发送到模型?

时间:2018-07-06 13:24:08

标签: php model-view-controller joomla3.0

我一直在寻找将数据从子控制器发送到MVC Joomla组件中的模型的问题,并且我一直在google中寻找我的问题并得到了link,但这给了我空白结果。我已经尝试了很多教程,但是没有用。

我的子控制器send.php代码在下面

      <?php
  /**
   * @package     Joomla.Administrator
   * @subpackage  com_helloworld
   *
   * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   */

  // No direct access to this file
  defined('_JEXEC') or die('Restricted access');

  /**
   * Hello World Component Controller
   *
   * @since  0.0.1
   */
  class HostingControllerSend extends JControllerLegacy
  {
    public function save_ratings(){

   $data = 'I am Data from Send Controller'; //get data from front end form
   $model = $this->getModel('Receive'); //load UpdateRatings model
   $model->set_data($data); //update setter function of model
   $res=$model->getData(); // retrieve getter function
    //print_r($res);

  }
  }


我的模型receive.php代码

    <?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * Hello World Component Controller
 *
 * @since  0.0.1
 */
class HostingModelReceive extends JModelLegacy
{
  public $data;

    public function getData(){
    $data=$this->data;
    return $data;
     }

     public function set_data($data){
          $this->data=$data;
     }
}



我的观点

        <?php
    /**
     * @package     Joomla.Administrator
     * @subpackage  com_helloworld
     *
     * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
     * @license     GNU General Public License version 2 or later; see LICENSE.txt
     */

    // No direct access to this file
    defined('_JEXEC') or die('Restricted access');

    /**
     * HTML View class for the HelloWorld Component
     *
     * @since  0.0.1
     */
    class HostingViewReceive extends JViewLegacy
    {
        /**
         * Display the Hello World view
         *
         * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
         *
         * @return  void
         */
        function display($tpl = null)
        {
            // Assign data to the view
            $this->msg = $this->get('Data');

            // Display the view
            parent::display($tpl);
        }
    }

任何帮助将不胜感激。亲切的问候!

0 个答案:

没有答案
相关问题