PHP code example of kenjis / ci3-to-4-upgrade-helper
1. Go to this page and download the library: Download kenjis/ci3-to-4-upgrade-helper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kenjis / ci3-to-4-upgrade-helper example snippets
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', '
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);
}
}
<h2> echo $title;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.