How to use namespace in the TCPDF? - php

I am trying to use TCPDF to print a pdf file in my php mvc project (model view controller), my problem is how to use namespace and use to make the tcpdf work.
i try this idea require_once(dirname(__FILE__).'/../TCPDF/TCPDF.php'); and it worked but i want to make it like this use MYPROJECT\TCPDF\TCPDF; and also i have been added this namespace MYPROJECT\TCPDF in all tcpdf php file and i get this erreur in the end class TCPDF_FONTS not found, although the TCPDF_FONTS file was added???
thanks for the help

You search for TCPDF_FONTS in class TCPDF_FONTS.
Then replace TCPDF_FONTS in function with namespace\TCPDF_FONTS.
I did the same and it worked.
Example:
public static function UTF8ArrayToUniArray($ta, $isunicode=true) { <br>
if ($isunicode) { <br>
return array_map(array('**src\pdf\tcpdf\include\TCPDF_FONTS**',
'unichrUnicode'), $ta);
} <br>
return array_map(array('**src\pdf\tcpdf\include\TCPDF_FONTS**', 'unichrASCII'), $ta); <br>
}

Related

Symfony\Component\Debug\Exception\FatalThrowableError Class 'app\link' not found

I already started using Laravel and I have this problem
"Symfony\Component\Debug\Exception\FatalThrowableError Class 'app\link' not found".
under the app folder, I have a link file but it's empty and not in PHP format, what I need to do in this case?
If your file is under app folder but it is not in PHP format, you have the answer for your question. Laravel will not recognize it as a class if the file isn't a php file. Just rename is to Link.php and add a basic structure, like this one:
<?php
namespace App;
class Link
{
public function __construct()
{
}
}
Also, check this link and learn how to ask a good question in Stack Overflow.
Hope it helps.

Laravel Class 'App\FBLogin\authlogin' not found

I created a new FBLogin.php file in App Folder, added class:
namespace App\FBLogin;
class authlogin {}
Now i want to use this class in my Controller File, so i added:
use App\FBLogin\authlogin;
Now when i am trying to use this class authlogin, it is showing me error Class 'App\FBLogin\authlogin' not found
Is there something i am doing wrong?
Laravel Version: 5.5
Why would you use a lowercase format when naming your classes? Anyway, your namespace inside your app folder should follow your file structure.
If you create your class like below,
namespace App\FBLogin;
class authlogin {
// code here
}
Your file structure must be:
app/
FBLogin/
authlogin.php
Then you can use the class anywhere in your app by declaring the proper namespace
use App\FBLogin\authlogin;
$authlogin = new authlogin();

CodeIgniter - How to make function that extends helper?

First my plan was to make a library that read php code content with html meta content and send it into html header.
And just several day ago, I found that CodeIgniter already working about meta tags and My plan change...
Now how to make my library extends this html helper like this
class Htmlplus extends CI_html {
public function show(){
//show html header
}
}
Did you checked the docs?
http://www.codeigniter.com/user_guide/general/helpers.html#extending-helpers
Or do you looking for some other solution?
edit to comment #1
using helper functions in an extended helper is same way as you would do anywhere else. just use them (make sure, helper is loaded)
e.g. in the file application/helpers/MY_url_helper.php you can use anchor()
function helper_test($str) {
return anchor($str, 'test');
}
Create an instance of CI and load helper!
class Htmlplus extends CI_html {
public function show(){
//show html header
$ci = & get_intance();
$ci->load->helper('myhelper');
myfunction();
}
}

Converting php code to Symfony class

i am using a simple php code with Activexpert to send sms here the intersting part
<?php
if(isset($_POST["submit1"]))
{
$_objSmsProtocolGsm = new Com("ActiveXperts.SmsProtocolGsm");
...
}
?>
it working fine but when i tried to insert it into my controller in symfony
i get an error
Attempted to load class "Com" from namespace
"PFE\SiivtBundle\Controller" in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\Symfony2.5\src\PFE\SiivtBundle\Controller\SiivtController.php
line 835. Do you need to "use" it from another namespace?
while my php code is simple and doesnt include or require any other files
Error message is self-explanatory.
Com class doesn't exist in PFE\SiivtBundle\Controller namespace (which is current namespace in your controller class).
Try:
new \Com("ActiveXperts.SmsProtocolGsm");
The backslash before classname means that we're looking for a class in global namespace

Symfony 2: Class not found in Controller

I've been struggling with this for some time now. It is most likely a rookie/typo problem, but I just can't find it.
I have this class ...
<?php
namespace PriceOrQuality\POQBundle\RegExConf;
use PriceOrQuality\POQBundle\RegExConf\RegExConf;
class RegExConfIrma extends RegExConf {
public function __construct() {
$this->start_page = 'https://irma.dk';
$this->startConnection();
$this->getAllLinks();
}
}
?>
that I'm trying to load from this controller.
<?php
// src/PriceOrQuality/POQBundle/Controller/CrawlerController.php;
namespace PriceOrQuality\POQBundle\Controller;
use PriceOrQuality\POQBundle\RegExConf\RegExConfIrma;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Monolog\Logger;
use Monolog\Handler\FirePHPHandler;
Class CrawlerController extends Controller {
public function testAction($page) {
if($page == 'irma') {
$regex = new RegExConfIrma();
return $this->render('PriceOrQualityBundle:Crawling:crawling_test.html.twig', array('links' => $regex->getLinks()));
}
}
}
?>
However I get this error, and I just cannot seem to find the problem.
FatalErrorException: Error: Class 'PriceOrQuality\POQBundle\RegExConf\RegExConfIrma' not found in /Users/Rune/Sites/poq/src/PriceOrQuality/POQBundle/Controller/CrawlerController.php line 16
The RegExConfIrma resides in /Users/Rune/Sites/poq/src/PriceOrQuality/POQBundle/RegExConf/RegExConfIrma
I've tried to debug:
* the namespace
* clearing cache
* changing the namespace
But nothing helps.
Any help is highly appreciated.
Thanks!
The problem was extremely rookie.
I forgot to add .php after my file extension as I use Netbeans where the logo showed is as a php file, but without the proper extension.
So for anyone else finding this post with the same problem:
Make sure you use the right namespace
Make sure you include or usethe class
Make sure of the spelling of the class
Make sure the
filename is spelled exactly the same as the class
Make sure you've
added .php after the class file

Categories