Im getting Complie error while using phpword library in codeigniter - codeigniter

Below is code in library file.
if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."/third_party/PHPWord.php";
class Word extends PHPWord {
public function __construct() {
parent::__construct();
}
}
Below is the error which i got.
Fatal error: require_once(): Failed opening required '/var/www/html/app/v1/application//third_party/PHPWord.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/app/v1/application/libraries/Word.php on line 4
Mainly because of this
(include_path='.:/usr/share/pear:/usr/share/php')
I have no idea about it.

Related

Code igniter controller view mysql

I have one controller abc_con with view abc_ view.
There is second controller cart_con with cart_view.
And I have third controller xyz_con with view xyz_view.php
The flow of my website is like when I click on abc_view then values go to abc_con and in abc_con there is function cartload(). This function load cart_view view. When cart_view submit all value go to xyz_con controller. In xyz_con there is function loadxyz(). This function load the xyz_view.
In abc_view there is an input with name pin code. This input value I can easy fetch in abc_con
I just wanted to transfer this $data t
Directly to xyz_view without storing in database.
You have to extend those controllers together
like this
1).in oneController.php
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/controllers/twoController.php';
class oneController extends BaseController
{
$this->abc();
}
2).in twoController.php
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/controllers/threeController.php';//parent class is threeController now you can access to function abc using inheriting like this
class twoController extends threeController
{
$this->abc();
}
}
3).in threeController.php
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class threeController extends CI_Controller
{
function abc()
{
your code
}
}//end of 3rd controller

CodeIgniter + PHPExcel: What is best way to call this library to CodeIgniter?

I have PHPExcel, and I want to add it to CodeIgniter.
Where is the best to copy the files from all CodeIgniter folders, and how do I call it in my controllers/models for regular usage?
EDIT:
It's a whole folder that I need to move, and call the main file: PHPExcel\IOFactory.php
You may add PHPExcel to library in Codeigniter, E.g:
application > libraries > PHPExcel.php
Let say in PHPExcel.php library file:
<?php
if (!defined('BASEPATH')):
exit('No direct script access allowed');
endif;
class PHPExcel
{
public function __construct()
{
//
}
public function some_function()
{
return 'some_function';
}
}
To call PHPExcel library, in your Controller. Let say I named it as
My_controller.php:
<?php
if (!defined('BASEPATH')):
exit('No direct script access allowed');
endif;
class My_controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
//Call PHPExcel class
$this->load->library('PHPExcel');
}
public function index()
{
echo $this->PHPExcel->some_function();
}
}
I followed this tutorial: https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/
Got my answer !

CodeIgniter Creating Core Base Classes not working like User Guide

I want to extend CI_Controller as a base class for my other classes according do my own need.
I read the user guid. Acted as what it told me.
I created application core:
./application/core/MY_ControllerPermission.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_ControllerPermission extends CI_Controller
{
function __construct()
{
parent::__construct();
}
}
And this is my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if(class_exists('MY_ControllerPermission'))
echo 'clase does exist';
else
echo 'clase does not exist';
class Users extends MY_ControllerPermission
{
....
In my config file:
$config['subclass_prefix'] = 'MY_';
It just show blank page and "clase does not exist"
So where is the problem?
UPDATE
If I add this line:
include_once(APPPATH . 'core/MY_ControllerPermission.php');
before my controller, it would work. Doesn't CodeIgniter load core PHP files automatically?
Rename MY_ControllerPermission.php to MY_Controller.php and you should be good to go.
You can leave everything else the same, you don't even need to use the name MY_Controller for your class if you don't want to.

Codeigniter when calling library method I get HTTP 500 error

I'm trying to create a library (in application/libraries) but I'm having problems when I call it from the controller.
Below is the code in the controller
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Client extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('security');
}
function index() {
try {
$activation_code = 'aa';
$this->security->Check_User_By_ValidationCode($activation_code);
} catch (Exception $e) {
log('error', $e->getMessage());
}
}
}
?>
And this is what I have in the library
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Security {
var $CI;
public function __construct()
{
$this->CI =& get_instance();
}
public function Check_User_By_ValidationCode($activation_code) {
return $activation_code ;
}
}
?>
But I'm getting a "HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request." in Chrome.
I'm not able to get anything from logs so I can't tell what I'm doing wrong here.
Any clues?
Thanks
You cannot use the class security because that class is defined by CodeIgniter. Just change the name to something else, like "Auth" or something more descriptive.
See: http://ellislab.com/codeigniter/user_guide/libraries/security.html

Codeigniter HMVC Modular Error

I'm new to CI + MX and I tried the Modules::run(); style but I can't seem to let it work.
Here's my directory structure:
/application
-/modules
--/main
---/controllers
----main.php
---/models
---/views
--/connections
---/controllers
----connections.php
---/models
----/group_model.php
---/views
----connection_view.php
main.php controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends MX_Controller {
function __construct(){
parent::__construct();
$this->load->helper('url');
}
function index(){
echo modules::run('connections/load_connections');
}
}
?>
connections.php controller:
<?php
class Connections extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->model('connections/group_model');
}
function load_connections(){
$user_id = 2;
$data['tabs'] = $this->group_model->get_groups($user_id);
$this->load->view('connection_view', $data);
}
}
?>
group_model.php model:
class Group_model extends CI_Model{
function __construct(){
parent::__construct();
}
/**
* Get all groups in db
**/
function get_groups($user_id){
$this->db->select('g.group_name');
$this->db->from('groups AS g');
$this->db->join('members AS m', 'g.group_id = m.group_id');
$this->db->where('m.user_id', $user_id);
return $this->db->get()->result_array();
}
}
My connection_view.php view contains a div and some php codes to display the $data['tabs'] passed as array in load_connections function.
The problem is, I'm getting an error that says:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Connections::$group_model
Filename: controllers/connections.php
Line Number: 14
and
Fatal error: Call to a member function get_groups() on a non-object in C:\xampp\htdocs\hmvc\application\modules\connections\controllers\connections.php on line 14
I have clearly followed all the instructions provided on MX wiki at https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
and set up everything as needed.
My database.php under /application/config is already configured.
routes.php is also configured pointing the default controller to main.php
I wonder what I have missed or have done wrong that I can't get it to work.
Codeigniter version: 2.1.3
MX version: 5.4
almost missed it, extend connections with MX_Controller since you are calling modules::run(). Whenever you want a controller to be called with modules::run(), you extend it with MX_Controller instead of CI_Controller
Your second error is caused because of your first error.
Your first error is most likely caused because it cant open the group_model.
try this
$this->load->model('group_model');

Resources