I'm assigning a value to smarty template from PHP file. My code snippet from PHP file is as follows :
<?php
require_once("includes/public-application-header.php");
ob_start();
prepare_request();
$request = empty( $_GET ) ? $_POST : $_GET ;
$op = $request['op'];
$objTeacherDetails = new TeacherDetails();
$teacher_id = $_GET['teacher_id'];
$teacher_classes = $objTeacherDetails->GetAllClassesByTeacherId($teacher_id);
$smarty->assign('teacher_classes', $teacher_classes);
$file_to_show = "teacher-details.tpl";
switch( $op ) {
case "get_assigned_subject_list":
$objClassSubjects = new ClassSubjects();
$objSubjects = new Subjects();
$class_id = $request['class_id'];
$all_subjects = $objSubjects->GetAllSubjects();
$subject_details = $objClassSubjects-> GetClassSubjectDetailsById($class_id);
$smarty->assign('all_subjects', $all_subjects);
$smarty->assign('subject_details', $subject_details);
$smarty->assign('teacher_id', $teacher_id);
$smarty->display("assigned-subject-list.tpl");
die();
break;
?>
My issue is I can't access the value of $teacher_id in smarty template. My code of smarty template is as follows:
<input type="text" value="{$teacher_id}" name="tid">
But I'm getting the text field blank. Can anyone help me out to resolve this minor issue? Thanks in Advance
Have you assigned $smarty somewhere?
$smarty = new Smarty();
Edit:
The problem was the $_GET['teacher_id'] was not being passed from one page call to the next.
Related
I am using a widget licence under GPL and want to remove the footer link.
you can see the link showing here
http://www.emortgagecalculator.org
and please advice how to edit this function to remove the link
function mcalc_init() {
// $code = 'PGEgaHJlZj0iaHR0cDovL3d3dy5rZXlzdG9uZWF1dG9sb2Fucy5jb20iPmF1dG8gbG9hbnM8L2E+;PGEgaHJlZj0iaHR0cDovL3d3dy5rZXlzdG9uZWF1dG9sb2Fucy5jb20vYmFkLWNyZWRpdC1hdXRvLWxvYW5zLyI+YmFkIGNyZWRpdCBhdXRvIGxvYW5zPC9hPg==;PGEgaHJlZj0iaHR0cDovL3d3dy5rZXlzdG9uZWF1dG9sb2Fucy5jb20vYmFkLWNyZWRpdC1hdXRvLWxvYW5zLyI+YmFkIGNyZWRpdCBjYXIgbG9hbnM8L2E+;PGEgaHJlZj0iaHR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sb2Fud2l0aG5vY3JlZGl0LmNvbSI+bm8gY3JlZGl0IGF1dG8gbG9hbnM8L2E+';
$code = "PGEgaHJlZj0iaHR0cDovL3d3dy5yZXBhaWQub3JnIj5SZXBhaWQub3JnPC9hPg==";
$init = explode(';',$code);
$loan_init = rand(0,sizeof($init)-1);
update_option('loan_init', base64_decode($init[$loan_init]));
update_option('mc_footer_color', '#999');
}
You can replace link with and base64 equivalent of this is Jm5ic3A7, so you can use;
function mcalc_init() {
$code = "Jm5ic3A7";
$init = explode(';',$code);
$loan_init = rand(0,sizeof($init)-1);
update_option('loan_init', base64_decode($init[$loan_init]));
update_option('mc_footer_color', '#999');
}
Or you can try;
function mcalc_init() {
$init = explode(';',$code);
$loan_init = rand(0,sizeof($init)-1);
update_option('loan_init', " "); // Or put anything you want
update_option('mc_footer_color', '#999');
}
Update: Second option worked for OP (just for incoming users)
First of all find the action hook,
Hook will be something like this:-
add_action('HOOK_NAME', 'mcalc_init');
Now add this in your theme's functions.php or plugin's main file file:-
remove_action('HOOK_NAME', 'mcalc_init');
add_action('HOOK_NAME', 'my_mcalc_init');
function my_mcalc_init()
{
// $code = 'PGEgaHJlZj0iaHR0cDovL3d3dy5rZXlzdG9uZWF1dG9sb2Fucy5jb20iPmF1dG8gbG9hbnM8L2E+;PGEgaHJlZj0iaHR0cDovL3d3dy5rZXlzdG9uZWF1dG9sb2Fucy5jb20vYmFkLWNyZWRpdC1hdXRvLWxvYW5zLyI+YmFkIGNyZWRpdCBhdXRvIGxvYW5zPC9hPg==;PGEgaHJlZj0iaHR0cDovL3d3dy5rZXlzdG9uZWF1dG9sb2Fucy5jb20vYmFkLWNyZWRpdC1hdXRvLWxvYW5zLyI+YmFkIGNyZWRpdCBjYXIgbG9hbnM8L2E+;PGEgaHJlZj0iaHR0cDovL3d3dy5rZXlzdG9uZWF1dG9sb2Fucy5jb20vdXNlZC1hdXRvLWxvYW5zLyI+dXNlZCBjYXIgYXV0byBsb2FuczwvYT4=;PGEgaHJlZ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update_option('loan_init', base64_decode($init[$loan_init]));
update_option('mc_footer_color', '#999');
}
OR You can hide this part with css also like this:-
Add this in theme's header file.
<style>
.mc-container .mc-footer{display:none;}
</style>
Hope this will will work.
My url contains many variables that I want untouched (don't worry they aren't important).
Let's say it contained...
../index.php?id=5
How would I make a url that just adds
¤t=1
rather than replacing it entirely?
I'd like...
../index.php?id=5¤t=1
rather than..
../index.php?current=1
I know it's a simple question but that's why I can't figure it out.
Thanks.
To append a parameter to a URL you can do this:
function addParam( $url, $param ){
if( strrpos( $url, '?' ) === false){
$url .= '?' . $param;
} else {
$url .= '&' . $param;
}
return $url;
}
$url = "../index.php?id=5";
$url = addParam( $url, "current=1");
You should just create your link to 'add' that parameter
The Link
and then obviously in the index.php somewhere you'll look for the current variable and do what you need to:
<?php
if(isset($_GET['current']) && !empty($_GET['current]) {
// Do stuff here for the 'current' variable
$current = trim($_GET['current']);
}
?>
On the links that you require the $current variable, I suppose that you could just casually put it in the href attribute. For the index,php file, so something like this....
if(isset($_GET['current']))
{
$current = $_GET['current'];
//Do the rest of what you need to do with this variable
}
Try this one:
$givenVar = "";
foreach($_GET as $key=>$val){
$givenVar .= "&".$key."=".$val;
}
$var = "&num=1";
$link = "?".$givenVar."".$var;
echo $link;
You can just add the variable to the href,
When you clink it while the address is
../index.php?id=5
trust me you then go to
../index.php?id=5¤t=1
BUT if you click that link again, than you 'll go to
../index.php?id=5¤t=1¤t=1
Actually I thinks that's tricky and bad practice to just append the variable.
I suggest you to do it like:
<?php
$query = isset($_GET) ? http_build_query($_GET) . '¤t=1' : 'current=1';
?>
A Label
take a look http://us.php.net/manual/en/function.http-build-query.php
I don't know why in Earth you would need this, but here we are. This should do the trick.
$appendString = "¤t=1";
$pageURL = $_SERVER["REQUEST_URI"].$appendString;
$_SERVER["REQUEST_URI"] should return just the name of the requested page, with any other GET variable attached. The other string should be clear enough!
I am trying to pull area of a page with AJAX.
In JS I have on click I pass href to PHP;
in PHP(located in tools):
<?php defined('C5_EXECUTE') or die("Access Denied.");
$path = ($_POST['path']);
$page = Page::getByPath($path);
$a = new Area('Main');
$ret = $a->display($page);
echo json_encode($ret);
?>
If I make:
echo json_encode($page);
I receive the page so everything working, But when I try to receive an Area I get this error:
concrete\elements\block_area_header_view.php on line 5
In this File I found this
$c = Page::getCurrentPage();
$areaStyle = $c->getAreaCustomStyleRule($a);
So as I understand $c is null that why I have this error how can I fix this??
This line of code:
$ret = $a->display($page);
...does not do what you think it does. The "display" function does not return the content -- instead it outputs it to the browser. So your json_encode($ret) is just encoding and echo'ing an empty variable.
To capture the displayed content and put it into a variable, you can use php's output buffering feature, like so:
ob_start();
$a->display($page);
$ret = ob_end_clean();
I'm working on a REST styled API, and I want to be able to break the URL down into individual variables.
Say I have the following URL: www.example.com/user/post/1
I'd like to make the following variables:
$uri_1 = user
$uri_2 = post
$uri_3 = 1
I tried to do this but it got stuck in a loop
$path = explode('/', $this->path($uri));
for($i=0;$i < count($path);$i++){
$uri_.$i = $path[i];
}
$url = explode('/', strtolower(trim($_SERVER['REQUEST_URI'], '/')));
$uri_1 = isset($url[0])?$url[0]:'';
$uri_2 = isset($url[1])?$url[1]:'';
$uri_3 = isset($url[2])?$url[2]:'';
Here's how you do it for an arbitrary number of variables, using PHP's variable variables feature:
$path = explode('/', $this->path($uri));
for($i=0;$i < count($path);$i++){
${"uri_".$i} = $path[i];
}
I'am a newbie also my language maybe bad, and looking for solution for my learning php code
let say i have many page i.e. etc page1.php ... page1001.php each page maybe:
inside of page1.php:
$color = "red";
$pages = "two";
$theme = "ocean";
$lang = "eng";
$charset = "ISO-8859-1";
etc (more..)
inside of page2.php :
$color = "blue";
$pages = "two";
$theme = "ocean";
$lang = "it";
$charset = "UTF-8";
etc (more..)
now i need to put the variable of each pages to one page, n just put a simple code in each pages to setting them so next time easily to edit, note I using plain text (flat file)
anybody help me? i give appreciate and say thank you
You can try to use "include"
or you could use:
require('page1.php');
This will work similarly, but cause an error if the page cannot be located.
see: here
oh sorry maybe i give wrong explained:
I mean all content in page1.php up to page1001.php above i will move to one page call it as parameter.php
so parameter.php become:
<?
//the value of page1.php
$color = "red";
$pages = "two";
$theme = "ocean";
$lang = "eng";
$charset = "ISO-8859-1";
etc (more..)
//the value of page2.php :
$color = "blue";
$pages = "two";
$theme = "ocean";
$lang = "it";
$charset = "UTF-8";
//etc (more..)
//the value of page3.php :
$bla-bla = "bla-bla";
?>
now how to call the value of page1.php also page2.php in parameter.php above? if i using include "parameter.php"; in each page (page1.php up to page1001.php) sometimes not suitable to each of page...
Judging by your data, you could put your values for a certain page into an associative array such as this:
//Page1.php
$page1Information('color' => 'red', 'pages' => 'two', 'theme = 'ocean');
//Page2.php
$page2Information('color' => 'blue', 'pages' => 'five', 'theme = 'forest');
Then you can include all the pages in your parameter.php file, and call upon the data in any one file by going:
echo $page1Information['color'];
//Prints out "red"