I have a sharedlib.cc and a sharedlib.h code that contains classes and methods. I wrap this up and created a shared library called MySharedLibrary.so.
I would like to work with my .so library inside a php code. So I've created a config.m4 file , a php_code.cc file and a php_code.h file in order to make the extension from php possible. I DON'T WANT TO include in the config.m4 file the sharedlib.cc. I would like to include instead the MySharedLib.so because I don't want to expose my sharedlib.cc code. Besides I have others library that I also included in my .so library. Need some help.
EDIT:!!
I DON;T WANT TO INCLUDE IN THE CONFIG.M4 THE FILE: sharedlib.cc. I want to include only the sharedlib.h and MySharedLibrary.so (the lib that contains both the sharedlib.cc and sharedlib.h)
I believe the PHP_ADD_LIBRARY() macro in config.m4 will achieve this.
You can find some examples here: http://devzone.zend.com/article/4486
edit: you may need PHP_ADD_LIBRARY_WITH_PATH() if your shared lib isn't somewhere that the linker will find it.
edit 2: looks like this was covered before; the answer provides good example code.
Related
I'm facing trouble when using PHPWord with CodeIgniter in loadTemplate always return error "Template Not Found".
I'm using phpword in third party and create Word.php class in library to call it.
My CodeIgniter not a pure one. It already injected like some homemade cms from previous programmer.
My Question is how to I know where is the path of loadTemplate?
Any info needed you can ask me I will provide for you
Thanks,
Hendra
I'm not sure if I understood your scenario, but in any case there is no magic in how the path of loadTemplate works - it works exactly the same as you would access any file with php, i.e. either you place your template file under the phpunit library and use a relative path or you place your file somewhere else and use a full path (or some alias if you have some defined in your server (apache/nginx/..) configuration).
Here's the code, https://github.com/google/google-api-php-client/
Here's the file that's missing, https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php
I know it's possible to create this file with composer, but was just wondering if anyone has it available.
I'm also concerned that this alone might not make the software work, as I've tried to do it the manual way and the Class it can't reference is "GuzzleHttp\Collection" which is accessed in PHP with "use GuzzleHttp\Collection". I don't know how adding "autoload.php" will help referencing a file that's not part of the "google-api-php-client".
Does anyone actually have this software working in PHP, it says Beta?
I found it using Google Cache,
http://webcache.googleusercontent.com/search?q=cache:992oyuQ76a0J:https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php+&cd=1&hl=en&ct=clnk&gl=us
This file should be load from vendor directory
// include your composer dependencies
require_once 'vendor/autoload.php';
I'm coding a form in Drupal 7, and I want to 'include' a php file that adds my DB connection variables to my code.
I've tested my code in several ways, and I'm sure that the 'include' makes me get a WSOD when I run Cron in my site.
I've Googled about this and I tried:
include("/sites/all/libraries/php/connection.inc");
include("./sites/all/libraries/php/connection.inc");
include"./sites/all/libraries/php/connection.inc";
I also tried the above with '.php' extension.
And my last try:
define('__ROOT__', dirname(dirname(__FILE__)));
include(__ROOT__.'/sites/all/libraries/php/connection.inc');
Sometimes I get a WSOD when trying to run Cron, and sometimes my page styles get broken when I submit a form.
What is the correct way to include a PHP file manually in Drupal? Note that I don't want to use the 'Drupal way' to do this or to use the webform module. I want to code it manually with PHP.
The libraries directory should only be used to store files shipped as a library through the libraries module (see here https://drupal.org/project/libraries).
For both examples lets assume library.inc is our file and relative_path_to is the relative path based on the module directory to our library.inc file.
To just include a file you can use:
require(drupal_get_path('module', 'module_name') . '/relative_path_to/library.inc');
And to do it the Drupal way (https://api.drupal.org/api/drupal/includes!module.inc/function/module_load_include/7):
module_load_include('inc', 'module_name', '/relative_path_to/library');
Cheers,
j
Try this ways
1) require 'includes/iso.inc';
2) include_once 'includes/iso.inc';
3) include ('includes/iso.inc');
OR Drupal Ways
include_once DRUPAL_ROOT . '/includes/iso.inc';
In my opinion these are correct Drupal (7) ways to include code:
module_load_include(); function - Drupal API documentation - to include any PHP files from within your or other modules where needed,
files[] = ... in your_module.info file to autoload include classes and interfaces within your own module - Writing .info file documentation.
Libraries module provides it's own way to include external PHP files from the libraries.
The second answer is the correct "Drupal way". The one that was accepted as the answer has many potential pitfalls if locations of things change. Using drupal_get_path is the best way. This is also especially true if you are trying to include a file that may not be fully bootstrapped during a module update hook.
Hi this is my first post on here. I am trying to install the Gdata Zend Client library without much success.
I have used these resources + scoured Stack Overflow.
https://developers.google.com/gdata/articles/php_client_lib
http://jeromejaglale.com/doc/php/google_calendar_api
I want to be able to add,edit etc events on google calendar via PHP. My problem/question is i really dont understand what the include_path settings are all about and how to set them in order to make the class work. Of course i checked php manual regarding this but still draw a blank.
I have downloaded the relevant class and uploaded it to my web root. In the past i would just include a class by using php include at the top of the page and this would suffice.
I am of the understanding that i need to change the php.ini file to show php where my class is. Does this mean that i have to put my class somewhere else other than the web root.
I am terribly confused about this step and i know that if i can get it installed, actually using the class should be relatively easy.
Thanks for any help.
Welcome! Your Q is about include files rather than ZF elements.
Understanding where the include setting can be made (and subsequently overridden) is an absolute key bit of information.
You need to find out where it is on the server you are working on.
echo ini_get('include_path');
Then dash off and really, really read the corresponding manual page.
Try out including a very simple file with an echo statement, and you will regain your sanity and confidence.
http://www.php.net/manual/en/function.include.php
Get that working then have a play with this:
http://www.php.net/manual/en/function.ini-set.php
The experience how you can include a file from the same directory (not generally a good idea if that is a public webpage - inside your webroot)
Then if you want to really chase this thing down, look at where you can set this in Apache and per-directory in .htaccess files.
Finally, you can just include a file by telling include/require the exact path from the top of the tree;
include /var/www/includes/libraries/and/so/on.php;
There are SO many places you can set and override this that you are really best off finding out where the server thinks the include directory is and putting your compoenents in there:
Now, when that comes to ZF stuff, I (on Deb and Ubuntu anyhow) put the contents of
Zend Framworks version XYZ ZendFramework/lib/Zend <-that folder into:
/usr/share/php/Zend <-into this place
Then setup your autoloader and Robert is your mothers brother...
Zend/Gdata.php line 124 is like this:
public static function import($uri, $client = null,$className=’Zend_Gdata_Feed’)
Change that to this:
public static function import($uri, $client = null,$className=’Zend_Gdata_Feed’, $useObjectMapping = true)
I have several functions that I wrote and I use regularly on my servers, is there a way I can add them to the core so I don't have to include them from external files?
I am running PHP5
You could add your libraries as a PEAR extension. Then you could add it to your local PEAR repository. Pear is added to the default include path in php.ini. Then you can just use "pear install myextension" on your machines.
If these are C functions you interface with in php (php extensions) then you can do something similar with PECL.
I've done this before.. it's a fairly involved process, but not too bad. This article at zend.com should tell you everything you need to know:
http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
edit: I should add that there are better ways to achieve the essence of what you're trying to do. Remember that doing this will further clutter up PHP's (already very cluttered) namespace. You're probably better off just making a global include file that has all of your most commonly used functions that you include wherever you need it.
edit2: Upon rereading your original question, you said you don't want to do that, but I still think it's probably the best way. But best of luck to you with the extension route.
If you want your function to always be available, without including it, do this:
Create your function in an php file.
In your php.ini search for the option "auto_prepend_file" and add your php file to that line, like this: auto_prepend_file = "/path/to/my_superglobal_function.php"
Or if you write without a path like this: auto_prepend_file = "my_superglobal_function.php" It will look in your include_path in php.ini to find the file.
Why exactly is it so hard to include the files where you need them?
I suppose the auto_prepend_file PHP.ini directive could work. But it's not really recommended.
If you got autoload, you can move the functions as static methods of a class like My_Functions.
Or for dividing it into more files you can use My_Functions_Math. Then you will only need to load the functions you need. And with autoload you don't have to worry about including files.
You cant autoload namespace functions, so if you want to use autoload the functions have to be static methods in a class. But you can use namespace to make it easier to fx replace the class in the future and/or shorten the long class name. Example:
use My\Functions\Math as Math;
Math::calcThis($i);