Giter VIP home page Giter VIP logo

ci3-to-4-upgrade-helper's Introduction

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

<?php
namespace App\Controllers;

use App\Models\News_model;
use Kenjis\CI3Compatible\Core\CI_Controller;
use Kenjis\CI3Compatible\Library\CI_Form_validation;

/**
 * @property News_model $news_model
 * @property CI_Form_validation $form_validation
 */
class News extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('news_model');
        $this->load->helper('url_helper');
    }

    public function index()
    {
        $data['news']  = $this->news_model->get_news();
        $data['title'] = 'News archive';

        $this->load->view('templates/header', $data);
        $this->load->view('news/index', $data);
        $this->load->view('templates/footer');
    }

    public function view($slug = null)
    {
        $data['news_item'] = $this->news_model->get_news($slug);

        if (empty($data['news_item'])) {
            show_404();
        }

        $data['title'] = $data['news_item']['title'];

        $this->load->view('templates/header', $data);
        $this->load->view('news/view', $data);
        $this->load->view('templates/footer');
    }

    public function create()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');

        $data['title'] = 'Create a news item';

        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('text', 'Text', 'required');

        if ($this->form_validation->run() === false) {
            $this->load->view('templates/header', $data);
            $this->load->view('news/create');
            $this->load->view('templates/footer');
        } else {
            $this->news_model->set_news();
            $this->load->view('news/success');
        }
    }
}

app/Models/News_model.php

<?php
namespace App\Models;

use Kenjis\CI3Compatible\Core\CI_Model;

class News_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();

        $this->load->database();
    }

    public function get_news($slug = false)
    {
        if ($slug === false) {
            $query = $this->db->get('news');
            return $query->result_array();
        }

        $query = $this->db->get_where('news', ['slug' => $slug]);
        return $query->row_array();
    }

    public function set_news()
    {
        $this->load->helper('url');

        $slug = url_title($this->input->post('title'), '-', true);

        $data = [
            'title' => $this->input->post('title'),
            'slug'  => $slug,
            'text'  => $this->input->post('text')
        ];

        return $this->db->insert('news', $data);
    }
}

app/Views/news/create.php

<h2><?php echo $title; ?></h2>

<?php echo validation_errors(); ?>

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

    <label for="title">Title</label>
    <input type="input" name="title" /><br />

    <label for="text">Text</label>
    <textarea name="text"></textarea><br />

    <input type="submit" name="submit" value="Create news item" />

</form>

How to Upgrade from CI3 to CI4

See How to Upgrade from CI3 to CI4.

If you have test code with ci-phpunit-test, see How to Upgrade Test Code from CI3 to CI4.

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

ci3-to-4-upgrade-helper's People

Contributors

jderr-mx avatar kenjis avatar totoprayogo1916 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ci3-to-4-upgrade-helper's Issues

Bug: group_by does not reset

Describe the bug
$this->group_by does not reset in Kenjis\CI3Compatible\Database\CI_DB_query_builder:_reset_select(). This causes $this->group_by to remain populated after the query has completed running.

ci3-to-4-migration-helper version
0.7.1

Expected behavior, and steps to reproduce if appropriate
For example, running $this->db->select('...')->group_by('...')->get('...')->row_array(); and then $this->db->get('...')->result_array() will fail with error "Unknown column '...' in 'group statement'".

Context

  • OS: Linux
  • Web server: Docker (not sure)
  • PHP version: 8.x

Migration Errors

Models and Library can't migrate with Tailwindcss, DaisyUI & CodeIgniter 3. How can I send you DM? Thank you.

.drawer
  ├── .drawer-toggle
  ├── .drawer-content
  │    ├── [navbar.php], [header.php], etc.
  │    ├── [page content] ???
  │    └── [footer.php] ???
  └── .drawer-side
       ├── .drawer-overlay
       └── [sidebar.php]

Issue: missing functions in CI_Input

Thanks for this great work.

I have a question. Some functions seem to be missing in the CI_Input file, like 'cookie()'.
Is it possible to add these functions? Or can I override the CI_Input file myself somehow, without editing it in the vendor directory?

Thanks!

Query Builder Support for where_in, where_or and its variations

Describe the bug
Thank you for creating this helper, it is quite useful.
I am working on a large project which makes use of where_in and where_or functions from the query builder.
Does this helper support those functions?

Looking at https://github.com/kenjis/ci3-to-4-upgrade-helper/blob/1.x/src/CI3Compatible/Database/CI_DB_query_builder.php

It appear that might be the case.

I am happy to provide more detail if needed. Thanks!

ci3-to-4-migration-helper version
Which version (and branch, if applicable) the bug is in.

Expected behavior, and steps to reproduce if appropriate
A clear and concise description of what you expected to happen,
and how you got there.
Feel free to include a text/log extract, but use a pastebin facility for any
screenshots you deem necessary.

Context

  • OS: [e.g. Windows 99]
  • Web server [e.g. Apache 1.2.3]
  • PHP version [e.g. 6.5.4]

Missing feature: load class_library()

Hi,
when I'm using this library when I'm using:

$CI = &get_instance();
$CI->load->class_library(CLASS_NAME);

I've got this error:
Call to undefined method Kenjis\CI3Compatible\Core\CI_Loader::class_library()

Bug: $this->abcxyz_model and $this->load->view('abcxyz') no longer work in views in 0.6.0

Describe the bug
In our controller we have some code similar to this:

$this->load->model("abcxyz_model");
$this->load->view("view1");

And in the view our code looks like this:

$this->abcxyz_model->get_items();
$this->load->view("view2")

Both $this->abcxyz_model->get_items() and $this->load->view("view2") were working in 0.5.0, but are no longer working in 0.6.0. We get these errors: Call to a member function get_items() on null and Call to a member function view() on null.

ci3-to-4-migration-helper version
0.6.0

Expected behavior, and steps to reproduce if appropriate
$this->abcxyz_model->get_items() and $this->load->view("view2") should work 🤷

Context

  • OS: Linux
  • Web server: php spark serve
  • PHP version: 8.1.2

Bug: Are nested views supported?

Describe the bug
I am working on migrating an application that has many nested views
If in one view I include another with $this->load->view('view_name');

Stack trace:

Call to a member function view() on null
#0 /var/www/occrra/vendor/codeigniter4/framework/system/View/View.php(213): include()
#1 /var/www/occrra/vendor/codeigniter4/framework/system/View/View.php(216): CodeIgniter\View\View->CodeIgniter\View\{closure}()
#2 /var/www/occrra/vendor/kenjis/ci3-to-4-upgrade-helper/src/CI3Compatible/Core/CI_Loader.php(116): CodeIgniter\View\View->render('inc/header', NULL, true)
#3 /var/www/occrra/vendor/kenjis/ci3-to-4-upgrade-helper/src/CI3Compatible/Core/CI_Loader.php(105): Kenjis\CI3Compatible\Core\CI_Loader->viewRender('inc/header', Array)
#4 /var/www/occrra/app/Controllers/User.php(505): Kenjis\CI3Compatible\Core\CI_Loader->view('inc/header', Array)

I also tried this with a new CI4 instance

where I updated the Home controller with:

use Kenjis\CI3Compatible\Core\CI_Controller;

class Home extends CI_Controller

Then I created a view called test_view.php and loaded it in the welcome_view

<?php $this->load->view('test_view'); ?>

It creates this stack trace

CRITICAL - 2023-03-08 02:24:06 --> Undefined property: CodeIgniter\View\View::$load
in APPPATH/Views/welcome_message.php on line 323.
 1 APPPATH/Views/welcome_message.php(323): CodeIgniter\Debug\Exceptions->errorHandler(2, 'Undefined property: CodeIgniter\\View\\View::$load', 'APPPATH/Views/welcome_message.php', 323)
 2 SYSTEMPATH/View/View.php(213): include('APPPATH/Views/welcome_message.php')
 3 SYSTEMPATH/View/View.php(216): CodeIgniter\View\View->CodeIgniter\View\{closure}()
 4 VENDORPATH/kenjis/ci3-to-4-upgrade-helper/src/CI3Compatible/Core/CI_Loader.php(116): CodeIgniter\View\View->render('welcome_message', null, true)
 5 VENDORPATH/kenjis/ci3-to-4-upgrade-helper/src/CI3Compatible/Core/CI_Loader.php(105): Kenjis\CI3Compatible\Core\CI_Loader->viewRender('welcome_message', [])
 6 APPPATH/Controllers/Home.php(9): Kenjis\CI3Compatible\Core\CI_Loader->view('welcome_message', [])
 7 SYSTEMPATH/CodeIgniter.php(934): App\Controllers\Home->index()
 8 SYSTEMPATH/CodeIgniter.php(499): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Home))
 9 SYSTEMPATH/CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
10 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()
11 SYSTEMPATH/Commands/Server/rewrite.php(47): require_once('FCPATH/index.php')

ci3-to-4-migration-helper version
Which version (and branch, if applicable) the bug is in.

Expected behavior, and steps to reproduce if appropriate
A clear and concise description of what you expected to happen,
and how you got there.
Feel free to include a text/log extract, but use a pastebin facility for any
screenshots you deem necessary.

Context

  • OS: [e.g. Windows 99]
  • Web server [e.g. Apache 1.2.3]
  • PHP version [e.g. 6.5.4]

Feature Request: Add support for `group_by`

Hello, sorry for the bug report, I couldn't find a label for a feature request.

I see that group_by is not supported in the query builder, here is a request and an incoming PR for your consideration

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.