项目作者: kenjis

项目描述 :
CodeIgniter 3 to 4 Upgrade Helper
高级语言: PHP
项目地址: git://github.com/kenjis/ci3-to-4-upgrade-helper.git
创建时间: 2021-01-18T10:42:25Z
项目社区:https://github.com/kenjis/ci3-to-4-upgrade-helper

开源协议:MIT License

下载



``` ## How to Upgrade from CI3 to CI4 See [How to Upgrade from CI3 to CI4](docs/HowToUpgradeFromCI3ToCI4.md). If you have test code with [ci-phpunit-test](https://github.com/kenjis/ci-phpunit-test), see [How to Upgrade Test Code from CI3 to CI4](docs/HowToUpgradeTestCodeFromCI3ToCI4.md). ## For Development ### Installation composer install ### Available Commands composer test // Run unit test composer tests // Test and quality checks composer cs-fix // Fix the coding style composer sa // Run static analysys tools composer run-script --list // List all commands

CodeIgniter 3 to 4 Upgrade Helper

This project helps you upgrade your CodeIgniter3 apps to CodeIgniter4.

  • The goal is to reduce upgrade costs.
  • It provides compatible interfaces for common use cases in CodeIgniter3 apps.
  • It also provides compatible interfaces to test code using ci-phpunit-test.
  • It does not aim to be 100% compatible.
  • This project is under early development.
  • This project is under early development.
    • We welcome Pull Requests!

Requirements

Sample Code

If you use ci3-to-4-upgrade-helper, You can run the following code on CodeIgniter4.

app/Controllers/News.php

  1. <?php
  2. namespace App\Controllers;
  3. use App\Models\News_model;
  4. use Kenjis\CI3Compatible\Core\CI_Controller;
  5. use Kenjis\CI3Compatible\Library\CI_Form_validation;
  6. /**
  7. * @property News_model $news_model
  8. * @property CI_Form_validation $form_validation
  9. */
  10. class News extends CI_Controller
  11. {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->load->model('news_model');
  16. $this->load->helper('url_helper');
  17. }
  18. public function index()
  19. {
  20. $data['news'] = $this->news_model->get_news();
  21. $data['title'] = 'News archive';
  22. $this->load->view('templates/header', $data);
  23. $this->load->view('news/index', $data);
  24. $this->load->view('templates/footer');
  25. }
  26. public function view($slug = null)
  27. {
  28. $data['news_item'] = $this->news_model->get_news($slug);
  29. if (empty($data['news_item'])) {
  30. show_404();
  31. }
  32. $data['title'] = $data['news_item']['title'];
  33. $this->load->view('templates/header', $data);
  34. $this->load->view('news/view', $data);
  35. $this->load->view('templates/footer');
  36. }
  37. public function create()
  38. {
  39. $this->load->helper('form');
  40. $this->load->library('form_validation');
  41. $data['title'] = 'Create a news item';
  42. $this->form_validation->set_rules('title', 'Title', 'required');
  43. $this->form_validation->set_rules('text', 'Text', 'required');
  44. if ($this->form_validation->run() === false) {
  45. $this->load->view('templates/header', $data);
  46. $this->load->view('news/create');
  47. $this->load->view('templates/footer');
  48. } else {
  49. $this->news_model->set_news();
  50. $this->load->view('news/success');
  51. }
  52. }
  53. }

app/Models/News_model.php

  1. <?php
  2. namespace App\Models;
  3. use Kenjis\CI3Compatible\Core\CI_Model;
  4. class News_model extends CI_Model
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->database();
  10. }
  11. public function get_news($slug = false)
  12. {
  13. if ($slug === false) {
  14. $query = $this->db->get('news');
  15. return $query->result_array();
  16. }
  17. $query = $this->db->get_where('news', ['slug' => $slug]);
  18. return $query->row_array();
  19. }
  20. public function set_news()
  21. {
  22. $this->load->helper('url');
  23. $slug = url_title($this->input->post('title'), '-', true);
  24. $data = [
  25. 'title' => $this->input->post('title'),
  26. 'slug' => $slug,
  27. 'text' => $this->input->post('text')
  28. ];
  29. return $this->db->insert('news', $data);
  30. }
  31. }

app/Views/news/create.php
```php

<?php echo $title; ?>

<?php echo validation_errors(); ?>

<?php echo form_open(‘news/create’); ?>

  1. <label for="title">Title</label>
  2. <input type="input" name="title" /><br />
  3. <label for="text">Text</label>
  4. <textarea name="text">