Created
March 1, 2012 03:54
-
-
Save gabconcepcion/1947165 to your computer and use it in GitHub Desktop.
CodeIgniter using Zend Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Structure: | |
applications/libraries/Zend | |
- Db/ | |
- Db.php | |
- Exception.php | |
applications/core/MY_Controller.php | |
<?php | |
class MY_Controller extends CI_Controller | |
{ | |
function __construct() | |
{ | |
parent::__construct(); | |
set_include_path(implode(PATH_SEPARATOR, array( | |
realpath(APPPATH . 'libraries') | |
))); | |
require_once 'Zend/Loader.php'; | |
//Zend Library | |
Zend_Loader::loadClass('Zend_Db'); | |
} | |
} | |
?> | |
applications/config/config.php | |
<?php | |
$config['db']['host'] = 'localhost'; | |
$config['db']['dbname'] = 'database'; | |
$config['db']['username'] = 'root'; | |
$config['db']['password'] = ''; | |
?> | |
applications/core/MY_Model.php | |
<?php | |
class MY_Model extends CI_Model { | |
protected $_oDb; | |
function __construct() | |
{ | |
parent::__construct(); | |
$aDbConfig = $this->config->item('db'); | |
$this->_oDb = $db = Zend_Db::factory('Pdo_Mysql', $aDbConfig ); | |
} | |
} | |
?> | |
applications/models/Auth.php | |
<?php | |
class Auth extends MY_Model { | |
function doAuth($sUsername, $sPassword) | |
{ | |
$data = $this->_oDb->fetchAll('SELECT * FROM table'); | |
die(var_export($data,true)); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Structure | |
applications/libraries/Zend | |
- Loader/ | |
- Loader.php | |
- Json/ | |
- Json.php | |
application/core/MY_Controller.php | |
class MY_Controller extends CI_Controller | |
{ | |
function __construct() | |
{ | |
parent::__construct(); | |
set_include_path(implode(PATH_SEPARATOR,array( | |
APPPATH.'/libraries', | |
))); | |
include 'Zend/Loader.php'; | |
} | |
} | |
application/controllers/welcome.php | |
class Welcome extends MY_Controller { | |
public function index() | |
{ | |
$aData = array('content'=>'Hello World!'); | |
Zend_Loader::loadClass('Zend_Json'); | |
echo Zend_Json::encode($aData); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment