Hi I am new to cassandra database. I am trying to do a project in codeigniter with cassandra database. I have downloaded the phpcassandra files through below link
https://github.com/mauritsl/php-cassandra.
When I am trying to autoload my casssandra.php in codeigniter I got Non-existent class: Cassandra error. Why I got this error and how to solve the issue?
You will need to create a wrapper for it if you wish to use it as a library.
I would suggest you take the composer route.
You can check on packagist for a suitable library.
If you use this particular library phpcassa this is how you would go about getting it to work in Codeigniter.
composer.json
{
"require": {
"php": ">=5.3.0",
"thobbs/phpcassa": "1.1.0"
}
}
index.php
require "../composer/autoload.php";
system/core/codeigniter.php
// Where codeigniter starts to load the Main Controller
// $cassandraDB will be in the GLOBAL scope, so you may want to write a wrapper
$cassandraDB = new ConnectionPool('localhost');
// Then right after this
// if (class_exists('CI_DB') AND isset($CI->db))
// {
// $CI->db->close();
// }
$cassandraDB->close();
User Model
implement it how you wish in your models
public function __construct()
{
//YOU MAY NEED TO PASS $cassandraDB AS A DEPENDANCY!!
$this->users = new ColumnFamily($cassandraDB, 'Standard1');
}
Related
I tried installing phppresentation library in codeigniter framework. But in codeigniter can't able to use namespace. So how to integrate ?
This probably isn't a 'best practices' example but I got the "Getting Started" example on the PHPPresentation Packagist page to work in CI 3.1.3.
I'm using the default way to use composer as described in the CI manual.
The application and system dirs are up one level from root dir.
The composer.json file is in the application dir.
Cut-n-pasted below from the packagist page into composer.json and ran composer update which saved it into application/vendor/phpoffice.
{
"require": {
"phpoffice/phppresentation": "dev-master"
}
}
In application/libraries created Ppt_stuff.php. Cut-n-pasted Getting Started example into the file. Had to add the class name and function make_ppt. Also fixed the setPath and Save functions path names with realpath('.').
<?php defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
class Ppt_stuff {
public function make_ppt() {
$objPHPPowerPoint = new PhpPresentation();
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
->setDescription('PHPPresentation logo')
->setPath(realpath('.') . '/../application/vendor/phpoffice/phppresentation/samples/resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor(new Color('FFE06B20'));
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(realpath('.') . "/downloads/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(realpath('.') . "/downloads/sample.odp");
}
}
In root directory created /downloads directory.
Added this to the Home controller.
public function use_presentation() {
// load library
$this->load->library('Ppt_stuff');
// call make_ppt
$this->ppt_stuff->make_ppt();
return;
}
Went to http://localhost/home/use_presentation and it created sample.pptx and sample.odp in /downloads.
When I opened them, Powerpoint 2010 complained and offered to fix them.
I wrote a basic package for augmenting ldap into laravel
it can now parse subschema do searchs and generate ldif entries,my problem is
this package is driver based as in
when you create you first instance from the manager the front class
i do like this
$driver=new ldapman('openldap')->getDriverInstance();
or in Larvel 5.1
$man=app('Ldapman',['drivername'=>'openldap']);
$driver=$man->getDriverInstance();
and that's lead to constructer like this,
public function __construct( $driver,$type='driver')
{
$drivername=ucfirst($this->drivername);
$drivername.=$type;
$this->driverArray[$type]=null;
if(file_exists(__DIR__."/driver/$drivername.php"))
{
include_once(__DIR__."/driver/$drivername.php");
$drivername="\\Chromax\\Ldapman\\driver\\".$drivername;
if(isset($config)&&!is_null($config))
{
$this->driverArray[$type]=new $drivername($this->config);
}else{
$this->driverArray[$type]=new $drivername();
}
if($this->driverArray[$type] instanceof $drivername)
{
}else{
throw new \Exception("201 Class Not Found");
}
}
else
{
throw new \Exception("200 Driver Not Found");
}
}
this approach is fine and it helps me well but when i sent this package to a friend who was costumed to auto completion he had a hard time working with it
so i want to mod it to support completion
notice : my IDE is PHPSTROM
The template engine called blade can be used with codeigniter or pure php? I know that it can be used with laravel and I'd like to know if also can be used with any other php framework or with pure php
Blade can be used stand-alone in PHP.
This means you can comfortably use it in CodeIgniter.
https://github.com/PhiloNL/Laravel-Blade
Then again, you will need composer for that.
Alternatively you could use this CodeIgniter Library to simulate Blade: CodeIgniter Slice-Libray
It works pretty like Blade and it was designed directly for CodeIgniter!
For the record and as answer to another post:
I tested many libraries to run blade outside Laravel (that i don't use) and most (with all respect of the coders) are poor hacks of the original library that simply copied and pasted the code and removed some dependencies yet it retains a lot of dependencies of Laravel.
I created an alternative for blade that its free (MIT license, i.e. close source/private code is OK) in a single file and without a single dependency of an external library. You could download the class and start using it, or you could install via composes (composer require eftec/bladeone). So even composer is optional.
https://github.com/EFTEC/BladeOne
https://packagist.org/packages/eftec/bladeone
Its 100% compatible sans the Laravel's own features (extensions).
You can use BladeView library for CI.
NB: I ported this library
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library("bladeview");
}
public function renderView(){
$data=array(
"name"=>"Jhon",
"age"=>21
);
$this->bladeview->render("test", $data);
}
public function renderString(){
$data=array(
"name"=>"Jhon",
"age"=>21
);
$string="Hello I'm \{{$name}}. My age is \{{$age}}";
$this->bladeview->render($string, $data,false);
}
}
then in view.blade.php you can render like you do in laravel blade.
Hello my name is {{$name}}. My Age is {{$age}}.
Output:
Hello my name is Jhon. My Age is 21.
I have done a full write up here: http://mstd.eu/index.php/2017/03/02/using-the-laravel-blade-templating-engine-in-codeigniter-3/
Basically, include the package with composer (you need to set CI up to use composer), then create a blade instance passing it your view and cache folder like so:
$blade = new BladeInstance(__DIR__ . "/../views", __DIR__ . "/../cache/views");
echo $blade->render("index");
I have been looking into how to create a plugin system with Phalcon. I have checked INVO tutorial, Events Management to be more specific. It doesn't look like this is what I exactly need.
In this example it is loading the plugins manually and before establishing database connection.
I need to be able to access the database to check if the plugin actually installed and activated. So I can retrieve settings of installed & activated plugins as well as dynamically add them to the app.
I need to be able to attach the plugins pretty much anywhere; controllers (before / after / within method execution), models (before, after, within method execution) etc.
Does Phalcon provide such feature or do I have to ahead and try to create my own logic without using any framework feature?
Do you have any examples of what you would have plugins do? Or specifics about where Events Management is lacking?
I think you should be able able to get a very flexible system using dependency injection and events management.
It appears you can use the phalcon models before running the application, as long as you place the code after setting the db in the injector.
$plugins = \Plugin::find([
'active = :active:',
'bind'=>[
'active'=>1
]
]);
foreach($plugins as $plugin){
if(file_exists($plugin->filename)){
include $plugin->filename;
}
}
and in the file you could have code to subscribe to events, and/or add new dependencies.
// plugin file - for a db logger
$eventsManager = new \Phalcon\Events\Manager();
$logger = new \PhalconX\Logger\Adapter\Basic();
$profiler = $phalconDi->getProfiler();
$eventsManager->attach('db', function($event, $phalconConnection) use ($logger, $profiler) {
if ($event->getType() == 'beforeQuery') {
$profiler->startProfile($phalconConnection->getSQLStatement());
$logger->log($phalconConnection->getSQLStatement(), \Phalcon\Logger::INFO, $phalconConnection->getSQLVariables());
}
if ($event->getType() == 'afterQuery') {
$profiler->stopProfile();
}
});
or
class myHelper{ ... }
$phalconDi->set('myHelper', function() use ($phalconConfig, $phalconDi) {
$helper = new myHelper();
$helper->setDi( $phalconDi );
return $helper;
});
I'm using Stripe's php library. DL link: https://code.stripe.com/stripe-php-latest.zip
I've included the library like so inside of a view:
require_once(APPPATH.'libraries/stripe/lib/stripe.php');
Everything works fine when I do this in a view, but if I attempt to do it in a controller I get a server error. Why?
I have tried codeigniters load library method, but still a server error. I've change all capitals to lowercases, still the error.
Loading Packages:
$this->load->add_package_path(APPPATH.'third_party/stripe/');
$this->load->library('stripe');
Documentation: Application "Packages" section
http://ellislab.com/codeigniter/user-guide/libraries/loader.html
If you use third_party libraries, like for example the Facebook PHP SDK, use the following code:
$this->_obj->load->add_package_path(APPPATH.'third_party/facebook/');
$this->_obj->load->library('facebook', $config);
$this->_obj->load->remove_package_path(APPPATH.'third_party/facebook/');
And place the files for this library in the /third_party/facebook/libraries/ folder.
Note: It's a common mistake to place the files directly in '/facebook/' instead of in '/libraries/' (and also not mentioned in the documentation, too bad).
You can use the stripe native library by adding as codeigniter helper.
step 1: put the stripe package into helper directory
step 2: rename the init.php to init_helper.php
step 3: load the helper into your controller
$this->load->helper('stripe/init');
step 4: call stripe library
try
{
// set api key
\Stripe\Stripe::setApiKey('YOUR_SECRET_STRIPE_API_KEY');
// create customer
$customer_detail = \Stripe\customer::create(array(
'email' => 'customer_email#testdomain.com'
));
echo $customer_detail->id;
}
catch (Exception $e)
{
$error = $e->getMessage();
echo $error;
}
Try putting your library on application/libraries and then load your librarie with
$this->load->libraries('Stripe.php');