PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label include. Show all posts
Showing posts with label include. Show all posts

Saturday, November 5, 2022

[FIXED] How can I add a default include path for GCC in Linux?

 November 05, 2022     environment-variables, gcc, include, linux     No comments   

Issue

I'd like GCC to include files from $HOME/include in addition to the usual include directories, but there doesn't seem to be an analogue to $LD_LIBRARY_PATH.

I know I can just add the include directory at command line when compiling (or in the makefile), but I'd really like a universal approach here, as in the library case.


Solution

Try setting C_INCLUDE_PATH (for C header files) or CPLUS_INCLUDE_PATH (for C++ header files).

As Ciro mentioned, CPATH will set the path for both C and C++ (and any other language).

More details in GCC's documentation.



Answered By - jcrossley3
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, August 31, 2022

[FIXED] How to include PEAR packages by only including the PEAR.php file?

 August 31, 2022     include, mdb2, pear, php     No comments   

Issue

I'm using PEAR on a hosted website and I want to use the MDB2 package. Every site on the web initializes the MDB2 package with an require('MDB2.php'). Sadly, my web host only provides to me the location of the main PEAR.php file.

But I think I remember a method of including PEAR packages without specifically including them by file name, but using the global PEAR class by calling some static function. Sadly I ran through the documentation several times and tried to Google every combination of keywords that could help me find the solution but I didn't find it.
So, is this possible?? And if so, how do I do so??

Thanks a lot, I've been looking for multiple hours now :(

Steven


Solution

No, it is not possible to load pear packages through the PEAR class.

The only official way to include a pear package is to require/include the file you want to use:

require_once 'MDB2.php';

Also, your web host probably will not have MDB2 installed, so you need to ship it yourself. See the installation on a shared host manual.



Answered By - cweiske
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, August 25, 2022

[FIXED] How can I conditionally use a module in Perl?

 August 25, 2022     conditional, include, module, perl     No comments   

Issue

I want to do something like this in Perl:

$Module1="ReportHashFile1"; # ReportHashFile1.pm
$Module2="ReportHashFile2"; # ReportHashFile2.pm

if(Condition1)
{
  use $Module1;
}
elsif(Condition2)
{
  use $Module2;
}

ReportHashFile*.pm contains a package ReportHashFile* .

Also how to reference an array inside module based on dynamic module name?

@Array= @$Module1::Array_inside_module;

Is there anyway I can achieve this. Some sort of compiler directive?


Solution

You might find the if module useful for this.

Otherwise the basic idea is to use require, which happens at run-time, instead of use, which happens at compile-time. Note that '

BEGIN {
    my $module = $condition ? $Module1 : $Module2;
    my $file = $module;
    $file =~ s[::][/]g;
    $file .= '.pm';
    require $file;
    $module->import;
}

As for addressing globals, it might be easier if you just exported the variable or a function returning it to the caller, which you could use by its unqualified name. Otherwise there's also the possibility of using a method and calling it as $Module->method_name.

Alternatively, you could use symbolic references as documented in perlref. However, that's usually quite a code smell.

my @array = do {
    no strict 'refs';
    @{ ${ "${Module}::Array_inside_module" } };
};


Answered By - rafl
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, August 23, 2022

[FIXED] How to include multiple html file in another phtml file?

 August 23, 2022     include, magento, magento2, php     No comments   

Issue

I would like to include several file in Magento 2 in one phtml file. The project was in laravel at first and looks like this :

https://i.imgur.com/XpUbynf.png

So now I need to import all the project in a Magento 2 project but the semantic is different. I have tried this so far but doesnt work :

https://i.imgur.com/hewweJg.png

The files I'm trying to call are in a subfolder and the path of these files is :

Wo/EyeTest/view/frontend/templates/eyetestSteps

with other subfolders like

Wo/EyeTest/view/frontend/templates/eyetestSteps/step1/

Wo/EyeTest/view/frontend/templates/eyetestSteps/step2/

Do you have any idea how can I do this ? When the file is in the same directory, there is no problem, it's display, and I guess I'm writting the path badly.

Thanks


Solution

Please use the below path for this:

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Wo_EyeTest::eyetestSteps/step1/_instructions.phtml")->toHtml(); ?>


Answered By - Amit Saini
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, February 18, 2022

[FIXED] MAMP localhost include and cookie setting functionality

 February 18, 2022     cookies, include, localhost, mamp, php     No comments   

Issue

I am trying to move my site offline for obvious reasons and I am having trouble getting the localhost PHP function to work. My code is the following:

include "http://localhost:8888/mainbar.php?display=1";

I am able to include the file if I just have it's name, but I need to pass values over the url so this is not an option. I have looked into other means of getting this to work, but the whole point of using MAMP is to be able to work offline and then upload improvements.

Next, I am unable to set cookies. Here is the following cookie code I have:

$expire=time() + (14 * 24 * 60 * 60);
setcookie("user", "Conan", $expire, '/');

I also have tried to set cookies with Chrome but am unable to do so.I would be surprised if this cannot be done.


Solution

Includes should only be given file paths, not URLs.

The proper usage would look like the following: include "/path/to/file"

include "/var/www/html/yourappfolder/mainbar.php";

I see that you are trying to pass it a variable, ?display=1. The solution wouldn't be to figure out how to load the file with a URL parameter, you really want to redesign how your fetching the information that corresponds to the display variable.

What you want to do is improve the software design and create a separate function somewhere, something like: getMainBarData($display). In your mainbar.php file, you will call this function to get the results you currently have. In your file that you're using include, you can include the file holding the new function getMainBarData($display), and call it directly: getMainBarData(1).

So basically, you want to create a function that is both usable by mainbar.php and this file using include. 1 function that can be used by 2 pages is your optimal solution here.

As far as the cookie issue.. Try without the path "/".. so:

setcookie('user', 'Conan', $expire);



Answered By - Atticus
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, January 31, 2022

[FIXED] Including a non-class php file via namespace without using relative path

 January 31, 2022     composer-php, include, namespaces, path, php     No comments   

Issue

The problem I have been having for some time is including a "view" php file that resides in some location, known to the class whose method I am calling, but not necessarily to the place from which I am calling it. Best to explain it by example:

Say I have a file being included somewhere, that is responsible for rendering a table. Because there are many similar tables in my application, I use a separated file with template-like table view and if I want to change some aspects of it, I pass the needed parameters.

Here is said concrete view:

[MainView.php]


// Convert data from JSON.
/** @var $model MainDataModel */
$model = MainDataModel::rebuildFromJson($_POST["model"]);

// Prepare data for table view
/** @var $data TableViewData */
$data = new TableViewData();
$data->model = $model;
$data->tableBody = "MainTableBody.php";
$data->tableClass = "main-table";
$data->viewClass = "main-view";

/** Attach table. */
// include("../../Common/View/TableView.php"); (1)
include("../../../../vendor/composer/wb/Common/src/View/TableView.php"); (2)

and here is common TableView I want to pass the $data to and include to page:

[TableView.php]
namespace Common\Controller;

use ...

/** @var $data TableViewData  */
if (!(isset($data) && $data->checkForRequiredFields($data))) {
    return;
}

?>
<div class="<?php echo $data->viewClass; ?>">
    <div class="datatable">
        <table class="<?php echo $data->tableClass; ?>">
            <thead>
                <tr>
                <?php /** @var $column ColumnModel */
                    foreach ($data->model->columns as $column): ?>
                       <th><?php echo $column->text ?></th>
                <?php endforeach; ?>
                </tr>
            </thead>
            <tbody class="datatable-body">
                <?php include($data->tableBody); ?>
            </tbody>
         </table>
    </div>
</div>

All is fine (relatively) as long as I use include (1), but when I switched to composer I also separated the common classes and put them in some remote location, that I really should not care about.

In other words, something tells me I shouldn't need to have knowledge about exact path to TableView.php, relative to wherever I am using it and there probably has to be a better way to use it. Obviously, (2) doesn't quite work and I would actually be surprised if such a foolish way would have worked.

So now my question is: how could I include that view (TableView) without using relative path every time I use it? Something along the lines of including and accessing controller class (TableViewController?), which is in same directory as TableView and holds information about absolute positioning of the TableView?

Some way around the problem is also to make the class return the view and then call the class by namespace, but that's workaround, not the solution.


Solution

After playing around with various path functions and constants I've come to some solution of a problem. It's not too neat but nevertheless it works. Here it is:

[TableViewController.php]
(...)
public static function getTableViewPath() {
        return __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "View" . DIRECTORY_SEPARATOR
            . "TableView.php";
    }  
(...)

[MainView.php]
(...)
/** Attach table. */
include(TableViewPresenter::getTableViewPath());
(...)


Answered By - mareckmareck
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, January 25, 2022

[FIXED] Javascript file inclusion 406 error in CakePHP

 January 25, 2022     cakephp, include, javascript, jquery     No comments   

Issue

I have several js files under webroot

http://www.in-culture.info/app/webroot/js/

All the files are ok

Eg http://www.in-culture.info/app/webroot/js/lightbox.js

Except this

http://www.in-culture.info/app/webroot/js/jquery.cookie.js

It's throwing 406 Not acceptable error.

Help please.


Solution

Check file permissions, also try changing filename.



Answered By - aularon
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing