Welcome Guest, Not a member yet? Register   Sign In
How to create custom library in CodeIgniter?
#2

Considering that CI4 will be installed via composer: you can create your libraries without worrying about codeigniter methods and then upload your library to packagist. From within your codeigniter directory, composer require "companyName/yourLibrary" and then voila.

Your library file may start off like

PHP Code:
<?php
namespace MyCompanyName;

class 
math {
 public function 
multiply($a 0$b 0) {
 
  return $a $b;
 }



then in your controller file, you can do

PHP Code:
public function index() {
 
$object = new MyCompanyName\math;
 
$answer $object->multiply(45);

 
// code here to pass the variable $answer to the view

Reply


Messages In This Thread
RE: How to create custom library in CodeIgniter? - by meow - 10-08-2017, 04:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB