Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14114

CodeIgniter 3.x with RedBean PHP ORM

$
0
0
So im gonna share this stuff to you guys, this is about how to use readbean php ORM to your codeigniter

1. First download the latest version here
ReadBeanPHP Latest

2.Extract the contents and copy the rb.php to your application/third_party folder
[Image: 1.PNG]

3. In your controller, require the file rb.php

Code:
<?php
defined('BASEPATH) or exit('Error');
require_once APPPATH.'third_party/rb.php';

4. And in your controller constructor add this code

PHP Code:
public function __construct(){
parent::__construct();
$this->load->database();
if(!
R::testConnection()){
R::setup("mysql:host=".$this->db->hostname.";dbname=".$this->db->database,$this->db->username,$this->db->password); 
}


Now you can use the readbean ORM by calling it's static Class


To get all records from database simply do this

Example Code: If you want to get all records from your table just simply call the R::findAll  static method

In your controller

Code:
public function list_records(){
$data['records'] = R::findAll('table_name');
}
where table_name is the table that you want to fetch all records.


Note: every tables must have a column named "id" and has a primary key and auto increment.refer to the screenshot below
[Image: 2.PNG]

To know more about RedBean PHP ORM just follow this links

CRUD BASICS
http://www.redbeanphp.com/crud

FINDING
http://www.redbeanphp.com/finding

or visit their official site for more docs
http://www.redbeanphp.com/

Download Sample Code
here

Viewing all articles
Browse latest Browse all 14114


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>