I have a problem with the following code. How do i put 2 included files into 1 line include?
I already tried it like the code below but nothing is shown (blank page). It should show the url.
Url: theme/default/main/index.php (it would be)
application-sql-realtime.php = (should show 'default' or anything else when user changing their themes template it connect to sql)
<?php include('./theme/<?php include_once("config/application-sql-realtime.php");?>/main/index.php');?>
Refer image for code
include_one returns boolean
Maybe can be like this:
<?php
$theme = exec("php config/application-sql-realtime.php");
include("./theme/{$theme}/main/index.php");
?>
But I think you better put it in some class/function
<?php
// inside application-sql-realtime.php you declare a function to return theme name eg: getThemeName
include("config/application-sql-realtime.php");
$theme = getThemeName();
include("./theme/{$theme}/main/index.php");
?>
Make a class with a static or non static method to retrive the value you need (e.g. 'default'). Then you can implement this value in your string to include the first file. Following an example of a static method call:
<?php
$val = EgClass::getPathPart();
include('./theme/'.$val.'/main/index.php');
?>
Related
I am trying to integrate two pieces of code together. The existing code already generates a hash code and the function is called with this URL
header(Location: http://".$_SERVER['HTTP_HOST']."/subfolder/controller.php?document&validate&patient_id=".$pid."&document_id=".$nid."&process=true");
Is there another way to execute this function without doing a header redirect because the header redirect is causing the code to halt processing upon redirect.
In the controller file there is only one line echo Controller::act($_GET);
I tried to convert it to a function. I tried.
include_once controller.php //class file
function hash_tag($pid, $nid){
$filetag = "document&validate&patient_id=".$pid."&document_id=".$nid."&process=true";
echo Controller::act($filetag);
}
hashtag($pid, $nid);
Any help would be greatly appreciated.
Code for the Controller.class.php file can be seen here
https://github.com/juggernautsei/Drag-N-Drop/blob/master/library/classes/Controller.class.php
You didn't post your code inside controller.php but considering that your first approach was accessing that code via url parameters, I'll assume that you are executing variables in that code as GET variables (example: $_GET['patient_id']).
If that is the case, now that you are executing that code via include_once you have to change the way you set your variables in controller.php because there is not more $_GET.
You are trying to pass the string from the GET request to the controller.
But Contract::act() works on an array ($_GET is a superglobal array).
Build an array inside the function and assign the parameters of the function to it, then pass it to the controller, like so:
include_once 'controller.php';
function hash_tag($pid, $nid)
{
$array = array();
$array['document'] = 1;
$array['validate'] = 1;
$array['patient_id'] = $pid:
$array['document_id'] = $nid;
$array['process'] = 1;
echo Controller::act($array);
}
hashtag($pid, $nid);
Ok so I have the code for a form that is called and works but it needs two varibles grabbed from the string of a url. I have the first and the second is the same for what im doing on any page that I am creating which is alot. Here is the code at the url: collabedit.com/9g99j
Question if Get <?php echo $_GET['id']; ?> is grabbing my id string from the url how do I use this in the echo of my function I just defined at the bottom of the code? Instead of having this: echo DescriptionGet(1256124, 50874); can someone tell me how to put something like this: echo DescriptionGet(1256124, $id);
This would make it so i dont' have to enter that id value for every page I want to create.
Thanks,
Thanks everyone for your replies and I was able to figure it out on my own and actually used exactly what the first reply was.
Now I have a new question about this function. How do I make it grab the image from that same page its grabbing the form code from? I can't figure this part out and its keeping me from doing mass automation for this site.
Anyone help?
Try this:
$id = $_GET['id'];
echo DescriptionGet(1256124, $id);
You can change your function definition from:
function DescriptionGet($c, $id)
to
function DescriptionGet($c, $id=50874)
Each time when you will call DescriptionGet($c) it will behave as you passed $id=50874 but also if you need you can call DescriptionGet($c, 20) and $id in the function will be set to 20.
And in case you want to simple use $_GET['id'] as function parameter you can simple run
echo DescriptionGet(1256124, intval($_GET['id']));
you don't even need to use extra variable.
Currently I am working with Smarty and been busy with translations.
I am using the config files for translation, but I cannot find a way to collect all the vars that are not in my config file. When I don't have the translation in my config file, the output is blank.
My config files look like:
register = "Registreren"
username = "Gebruikersnaam"
password = "Wachtwoord"
login = "Inloggen"
In PHP I use:
$this->smarty = new Smarty();
$this->smarty->configLoad(THEME_DIR . "/translations/nl.conf");
$this->translations = $this->smarty->getConfigVars();
echo $this->translations["username"]; // output: Gebruikersnaam
I can use in my HTML:
{#password#}
{#username#}
{#password#}
{#login#}
But when I want to output a not yet translated var like this:
{#logout#}
My result is blank.
Does anyone know how to use a default function when this occurs? Or maybe add the not found var to my config file? Or at least, show the var name instead of nothing.
There is a way that doesn't need resorting to |default for each of your variables, but it requires a little change in one of the core files.
on line 340 of smarty/sysplugins/smarty_internal_data.php
replace
return null
by
return "#$variable#";
After this, all vars not defined int he conf file will appear as #name# (i.e. this is your #password#).
If for some reason you want a variable to be empty, just define it in the conf file as
variable = ""
The only way I found was this:
{#foo#|default:'foo'}
setting a default, if the variable is empty it will display that string.
http://www.smarty.net/docsv2/en/tips.tpl
I have a variable set in my main file (main.php), and need the second file (uploads.php) to reference the variable as it is set in the first file. It is returning undefined right now tho.
The second file is loaded with $.load into the first file: code example below -
Main.php Contents:
<?php $accountName = get_option('account_name'); ?>
<div id="uploads"></div>
Load Your Playlist
function loadUploadsFile() {
jQuery('#uploads').load('uploads.php');
}
Uploads.php file contents
<?php echo $account_name; ?> <== returns undefined
$url = 'http://www.somewebsite.com/' . $accountName . '/page/'
/* more code below running a query/loop etc. */
As you may be able to tell, I want Uploads.php to reference the variable decleration in Main.php but is is not pulling the value, it is just returning undefined. Uploads.php loads into the uploads div, but without the account name set the content is just blank.
Would I need to pass the variable to Uploads.php through ajax? I've tried session variables but couldn't get that to work. I was trying an ajax request but I am new to it so couldn't get that nailed. Any help would be great.
Session variables should work after all. Make sure you have the following:
In Main.php
session_start();
$_SESSION["account_name"] = "test";
In Uploads.php
echo $_SESSION["account_name"];
You could pass it as a GET parameter in your jQuery call like:
jQuery('#uploads').load('uploads.php?account=<?php echo($accountName);?>');
And then in your uploads.php file get it from the request like:
$accountName = $_GET['account'];
Some other options are storing it in the session, setting a cookie, or using jQuery .post to send it as POST data.
Since you are doing jQuery, you might want to look at http://api.jquery.com/jQuery.post/.
Your code should be something like (not sure if exactly)
$.post('uploads.php', { account_name: "<?= get_option('account_name') ?>" }, function(data) {
$('.result').html(data);
});
And then you can use this variable in your uploads.php by referencing $_POST['account_name'].
PS: I assume you are having PHP 5.4x
Save the account name in a session
Main.php
<?php
session_start();
$accountName = get_option('account_name');
$_SESSION['accountName'] = $accountName;
?>
Uploads.php
<?php echo $_SESSION['accountName']; ?>
I'm creating a language file - content modifying file - for my website so that I can change text over multiple websites in my admin panel. I have everything working except one thing. When I use a standard lang.php file with the contents like this:
$error_page_title = "$sitename | PAGE ERROR";
and use
<? echo $error_page_title ?>
I get:
example.com | PAGE ERROR to appear on my website. Perfect, exactly what I want. Reflects the $sitename in my config file and outputs the correct website name.
When I do it as a function:
function langString($lang_id) {
$lang_result = mysql_query("SELECT lang_string as phrase FROM lang WHERE lang_id='$lang_id'");
$lang_row = mysql_fetch_array($lang_result);
return $lang_row[phrase];
}
and use
<? echo langString(3); ?>
I get:
$sitename | PAGE ERROR appearing on my website. Not what I want... Arrr!
How can I get it so that my output is recognized as PHP instead of text?
echo str_replace('$sitename', $sitename, langString(3));
when using your function langString() instead of
return $lang_row[phrase];
use
return $lang_row['phrase'];
Also use <?php instead of <?, some servers cannot parse it correctly if you only use <?. probably not the problem, but never know