Heim  >  Artikel  >  Backend-Entwicklung  >  iWebShop 二次开发,创建自己的控制器,模型,视图

iWebShop 二次开发,创建自己的控制器,模型,视图

WBOY
WBOYOriginal
2016-07-23 08:54:451054Durchsuche
创建控制器

路径:/controllers/demo.php

  1. class Demo extends IController
  2. {
  3. public $layout = 'site';
  4. function init()
  5. {
  6. CheckRights::checkUserRights();
  7. }
  8. /**
  9. * 默认index方法
  10. */
  11. public function index()
  12. {
  13. // 调用Model
  14. // Demo_Class::show();
  15. // 获取Admin表列表信息
  16. $adminRow = Demo_Class::adminList();
  17. // 获取Admin表单条信息
  18. $adminInfo = Demo_Class::adminInfo();
  19. // 错误跳转
  20. // IError::show(404,'支付接口类没有找到');
  21. // 跳转到模板
  22. $this->redirect('index');
  23. }
  24. /**
  25. * 测试方法控制器
  26. */
  27. public function demo_list()
  28. {
  29. echo 'demo';
  30. exit;
  31. }
  32. }
复制代码
标题文字

路径:/classes/demo_class.php

  1. class Demo_Class
  2. {
  3. /**
  4. * 获取数据表信息输出
  5. */
  6. public function adminList()
  7. {
  8. // 获取user表列表
  9. $adminObj = new IModel('user');
  10. $adminRow = $adminObj->query();
  11. return $adminRow;
  12. }
  13. /**
  14. * 获取数据表信息输出
  15. */
  16. public function adminInfo()
  17. {
  18. // 获取admin表用户列表
  19. $adminObj = new IModel('admin');
  20. $adminRow = $adminObj->getObj('admin_name = "admin"');
  21. return $adminRow;
  22. }
  23. /**
  24. * 普通输出
  25. */
  26. public static function show()
  27. {
  28. echo '我是哪个啊';
  29. }
  30. }
复制代码
创建视图

路径:/views/default/demo/index.html

  1. 输出普通模型:{echo:Demo_Class::show();}


  2. 输出数组:{set:$arrInfo = Demo_Class::adminInfo(); echo $arrInfo['last_ip'];}


  3. {foreach:items = Demo_Class::adminList()}
  4. {$item['username']}
  5. {/foreach}
复制代码
自己的, iWebShop


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP PSR-1 基本代码规范 Nächster Artikel:基准测试工具:ab