Senin, 10 September 2018

Code Igniter ERROR syntax error, unexpected 'use' (T_USE)

Some of you might face this problem, when you try to integrate github library to your Project and you are using CodeIgniter.

The main problem is

You cannot put 'use' inside a function.

But you might have to use it inside your model. To solve it, I put the php file using the 'use' inside the 'views' directory and load it as a views.

In this example I am using the Github's shamir secret sharing library that is developed by Oliver Mueller and Stefan Gehrig.

model.php
<?php 

public function shamirSecretSharing()
{
       $data['message'] = 'this is a secret';
       return $this->load->views('shamir/compute');
}


?>

And here is my compute.php located in "..\application\views\shamir\compute.php".

compute.php
<?php 

require_once APPPATH. 'views/shamir/autoload.php';

use TQ\Shamir\Secret;

$shares = Secret::share($message, 3, 3);

return $shares;

?>

I'm not going to explain the function of the library. What I want to show is how I use the Library inside my model. If you ask me, what APPPATH mean. You can read it here.

1 komentar:

  1. Artikelnya bagus mudah dipahami, kunjungi website kami juga ya! untuk mendapatkan pengalaman lebih :)

    BalasHapus