在Joomla 2.5中将数据从控制器传递到模型 [英] passing data from controller to model in Joomla 2.5

查看:97
本文介绍了在Joomla 2.5中将数据从控制器传递到模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个joomla 2.5组件,该组件需要将数据从控制器传递到模型.控制器正在从url接收数据.我发现控制器正在正确获取值.现在,我需要将该值从控制器移至模型.在另一篇文章中,我找到了如下代码的控制器代码.

I am developing a joomla 2.5 component where I need to pass data from controller to model. The controller is receiving data from url. I find that controller is getting the value properly. Now I need to move that value to model from controller. From different post I have found a snippet of code for controller like below.

$datevalue = JRequest::getVar('day',$day); //receiving value from view
$item = JRequest::setVar('day',$datevalue); //setting variable

$model =& $this->getModel('WeeklyProgram'); //assign model
$model->setState('dayVar', $item); // assign value for model

问题是我不知道如何从模型中接收此值"dayVar".有人可以帮我解决这个问题吗?谢谢.

The problem is that I don't know how to receive this value 'dayVar' from model. Can anybody help me on this issue? Thanks.

推荐答案

您可以这样做.首先在模型中创建get和set函数,然后在控制器中加载模型并将值简单地传递给setter函数,示例如下:

You can do like this . First you make get and set function in the model.Second load the model in the controller and simply pass the values to setter function.Example as follows:

updateratings.php ---这是我的模型

updateratings.php---this is my model

class RatingManagerModelUpdateRatings extends JModelLegacy
    {
     public $data;

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

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

    }

Controller.php class RatingManagerController扩展了JControllerLegacy {

Controller.php class RatingManagerController extends JControllerLegacy {

public function save_ratings(){

 $tips = JRequest::getVar('tips'); //get data from front end form
 $model = $this->getModel('UpdateRatings'); //load UpdateRatings model
 $model->set_data($tips); //update setter function of model
 $res=$model->get_data(); // retrieve getter function
  //print_r($res);

} 

 }

这篇关于在Joomla 2.5中将数据从控制器传递到模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆