Joomla源代码解析(十九) JController

同样 JController 是MVC中重要的起点,正式这个类决定的动作的下一步流向,我们来看看表格提交数据的典型的controller的代码:

 function edit()
 {
  JRequest::setVar( 'view', 'hello' );
  JRequest::setVar( 'layout', 'form'  );
  JRequest::setVar('hidemainmenu', 1);

  parent::display();
 }

 /**
  * save a record (and redirect to main page)
  * @return void
  */
 function save()
 {
  $model = $this->getModel('hello');

  if ($model->store($post)) {
   $msg = JText::_( 'Greeting Saved!' );
  } else {
   $msg = JText::_( 'Error Saving Greeting' );
  }

  // Check the table in so it can be edited.... we are done with it anyway
  $link = 'index.php?option=com_hello';
  $this->setRedirect($link, $msg);
 }

 /**
  * remove record(s)
  * @return void
  */
 function remove()
 {
  $model = $this->getModel('hello');
  if(!$model->delete()) {
   $msg = JText::_( 'Error: One or More Greetings Could not be Deleted' );
  } else {
   $msg = JText::_( 'Greeting(s) Deleted' );
  }

  $this->setRedirect( 'index.php?option=com_hello', $msg );
 }

 /**
  * cancel editing a record
  * @return void
  */
 function cancel()
 {
  $msg = JText::_( 'Operation Cancelled' );
  $this->setRedirect( 'index.php?option=com_hello', $msg );
 }

实际上 controller 跟提交的task参数,调用controller中的不同的函数,当然默认会调用display ,我觉得还需要记住的就是

getModel ,和setRedirect ,其余函数用到再看就可以了。

转载于:https://www.cnblogs.com/vicenteforever/articles/1628250.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值