mansour
December 22, 2020, 9:26pm
1
Hi,
May I ask you convert the following code to 2021 version. (custom file without common files)
<?php
namespace PHPMaker2020\PTINFO;
// Autoload
include_once "autoload.php";
// Session
if (session_status() !== PHP_SESSION_ACTIVE)
\Delight\Cookie\Session::start(Config("COOKIE_SAMESITE")); // Init session data
// Output buffering
ob_start();
global $Language, $CurrentLanguage;
if (!isset($Language))
$Language = new Language();
if (!defined("KimiaPT") OR !isset($_SERVER['HTTP_REFERER'])):
header('Location: noaccess.php');
exit;
endif;
?>
<?php
$myResult = Execute("INSERT INTO exchat (User, PatientID, Message, PostDate) VALUES ('".CurrentUserID()."', '".$_POST['PatientID']."', '".$_POST['comment']."','".CurrentJDateTime()."')");
switch ($myResult) {
case false:
echo "<i class=\"fas fa-exclamation-triangle fa-3x text-danger\"></i>";
return FALSE;
break;
case true:
$Res = ExecuteRow("SELECT * FROM patients WHERE PatientID = '".$_POST['PatientID']."'");
//Sending Email
$email = new Email();
$email->load(Config("RESPONSE_TEMPLATE"));
$email->replaceSender(Config("SENDER_EMAIL")); // Replace Sender
$email->replaceRecipient($Res['EmailAddress']); // Replace Recipient
$email->replaceContent('<!--$Response-->', $_POST['comment']);
$emailSent = $email->send();
echo "<i class=\"far fa-check-circle fa-3x text-success\"></i> $msg";
return TRUE;
}
?>
thanks
mobhar
December 23, 2020, 12:29am
2
Although this following post will not answer your question a hundred percent, but perhaps it might help you to start converting from v2020 to v2021:https://discourse.hkvstore.com/t/how-to-load-data-from-database-into-custom-files-v2021/3471/1
arbei
December 23, 2020, 1:27am
3
Since you want to post data to a page to send email, with v2021 it is better to use Route_Action server event instead, see Server Events and Client Scripts in the help file and:
https://discourse.hkvstore.com/t/using-route-action-server-event-v2021/3393/1
mansour
December 23, 2020, 6:08am
4
Hi,
Thank you for answer.
I can access my custom page with following address:
http://site/mypage?PageID=5Is there any way to access the page with following URL instead?
http://site/mypage/5how can I access the get parameter inside the custom page ?
echo $_GET[“PageID”];thank you
mansour
arbei
December 23, 2020, 6:58am
5
mansour wrote:
Is there any way to access the page with following URL instead?
http://site/mypage/5
That is why I suggested Route_Action server event above.
mansour
December 23, 2020, 9:32am
6
I tried it many times.
$app->options('/mypages/{PageID}', function ($request, $response, array $args) {
$myRow = ExecuteRow("SELECT pages.*, pagetype.PageType as PgType FROM pages join pagetype on pages.PageType = pagetype.TypeID WHERE pages.PID = " .
AdjustSql($args['PID'])); // Get book info by $args['id'], here assume id is integer
$response->getBody()->write($myRow); // Write to response body
return $response; // Return the response
});
Normally I should visit my page like this:
http//site/mypages/5Isn’t it ?
arbei
December 23, 2020, 9:46am
7
mansour wrote:
$app->options(‘/mypages/{PageID}’, function ($request, $response, array $args) {
You should use $app->get() (for HTTP GET) or $app->post() (for HTTP POST), read:
https://www.slimframework.com/docs/v4/objects/routing.html
mansour
December 23, 2020, 10:00am
8
I tested with Route_Action . It prints a field value instead of my entire page.
I want to print the entire page. Following is my entire pedrapages.php file.
I want to access a page with static URL: e.g. I want to visit : http://site/pedrapages/1 instead of http://site/pedrapages?PID=1
<?php
$myRow = ExecuteRow("SELECT pages.*, pagetype.PageType as PgType FROM pages join pagetype on pages.PageType = pagetype.TypeID WHERE pages.PID = '".RemoveHtml($_GET['PID'])."'");
if (IsLoggedIn()){
$uid = CurrentUserID();
$allowed = ExecuteScalar("SELECT COUNT(PID) FROM pages WHERE PID = '".$_GET['PID']."' AND FIND_IN_SET($uid,AllowedUsers)");
}
$levelid = CurrentUserLevel();
$AllowedGroups = ExecuteScalar("SELECT AllowedGroups FROM pages WHERE PID = '".$_GET['PID']."'");
$allowedgrp = ExecuteScalar("SELECT COUNT(PID) FROM pages WHERE PID = '".$_GET['PID']."' AND FIND_IN_SET($levelid,AllowedGroups)");
?>
<!-- Flickity HTML init -->
<div class="carousel mb-4" id="pedra">
<?php
$config = new SiteConfig;
$topcardnum = $config->HomeTopCards;
$sSqlWrk = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".$_GET['PID'].",PagesID) AND IsActive = 'Y' AND CardPlace = 'T' AND flickity = 'Y' ORDER BY ID ASC";
$all_rows = ExecuteRows($sSqlWrk);
if(is_array($all_rows) || is_object($all_rows)){
foreach($all_rows as $a_row){
echo "<div class=\"carousel-cell\">";
if ($a_row['ShowRibon'] == 'Y'){
echo "<div class=\"ribbon-wrapper\">";
echo "<div class=\"ribbon bg-".$a_row['RibbonClass']."\">".$a_row['RibbonText']."</div></div>";
}
echo "<h6 class=\"useTitr text-light text-center p-2 mb-2\">".$a_row['CardTitle']."</h6>";
echo "<img class=\"card-img-top img-fluid\" src=\"cards/".$a_row['CardPhoto']."\" alt=\"".$a_row['CardTitle']."\" title=\"".$a_row['CardTitle']."\">";
echo "<div class=\"carousel-caption d-none d-md-block mb-3\"><h5>".$a_row['CardTitle']."</h5><p>".RemoveHtml($a_row['CardText'])."</p></div>";
echo "<div class=\"card-footer text-center mb-1\">";
echo "<button target=\"_self\" url=\"".$a_row['CardLink']."\" class=\"btn btn-".$a_row['CardClass']." links float-right\">".$a_row['LinkTitle']."</button>";
echo "</div></div>";
}
}
?>
</div>
<!-- Flickity HTML End -->
<!-- TOP CADS START -->
<div class="card-deck">
<?php
$config = new SiteConfig;
$topcardnum = $config->PagesTopCards;
$sSqlWrk = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".$_GET['PID'].",PagesID) AND IsActive = 'Y' AND CardPlace = 'T' AND flickity = 'N' ORDER BY rand() LIMIT $topcardnum";
$all_rows = ExecuteRows($sSqlWrk);
if(is_array($all_rows) || is_object($all_rows)){
foreach($all_rows as $a_row){
echo "<div class=\"card card-widget shadow rounded\">";
echo "<img class=\"card-img-top\" src=\"cards/".$a_row['CardPhoto']."\" alt=\"".$a_row['CardTitle']."\" title=\"".$a_row['CardTitle']."\">";
echo "<blockquote class=\"quote-".$a_row['CardClass']."\">";
echo "<h4 class=\"text-".$a_row['CardClass']." useTitr\">".$a_row['CardTitle']."</h4>";
echo "<p>";
echo $a_row['CardText'];
echo "</p>";
echo "</blockquote>";
echo "<div class=\"card-footer\">";
echo "<p class=\"card-text\"><small class=\"text-muted\"><a href=\"".$a_row['CardLink']."\" class=\"btn btn-".$a_row['CardClass']." btn-sm float-right\">".$a_row['LinkTitle']."</a></small></p>";
echo "</div>";
echo "</div>";
}
}
?>
</div>
<!-- TOP CADS END -->
<!-- PAGE CONTENT -->
<div class="card mb-2 card-widget shadow rounded">
<blockquote class="quote-light">
<h5 class="text-success useTitr"><?php echo $myRow['PageTitle']; ?></h5>
<p><small>
<!-- PAGE TYPE HERE -->
</small></p>
</blockquote>
<div class="card-header text-muted">
<small>
<?php
if ($myRow['IsFree'] == "N")
echo "<span class=\"float-right text-success\">قیمت: ".$myRow['Price']." ریال <button class=\"btn btn-circle btn-default shadow mb-3\" id=\"PurchaseIT\" value=\"".$myRow['PID']."\" price=\"".$myRow['Price']."\"><i class=\"fas fa-cart-plus text-success fa-2x\"></i></button></span><br><br><span class=\"text-danger mb-3\" id=\"message\"></span>";
?>
</small>
<?php
if (IsAdmin()){
?>
<div class="card-tools">
<button type="button" url="pagesedit/<?php echo $myRow['PID']; ?>" target="_self" class="btn btn-tool links" data-toggle="tooltip" title="ویرایش">
<i class="fas fa-edit"></i></button>
<button type="button" url="pagesadd/<?php echo $myRow['PID']; ?>" target="_self" class="btn btn-tool links" data-toggle="tooltip" title="کپی">
<i class="fas fa-copy"></i></button>
</div>
<!-- /.card-tools -->
<?php
}
?>
</div>
<!-- /.card-header -->
<div class="card-body">
<?php
SWITCH (TRUE){
case (!is_null($AllowedGroups) AND $AllowedGroups != "" AND $allowedgrp == 0 AND !IsAdmin()):
echo "<div class=\"alert alert-warning\" role=\"alert\">
<h4 class=\"alert-heading useTitr\">عدم مجوز دسترسی</h4>
<p>دسترسی به Ù…Øتوای این صÙØÙ‡ به گروه های کاربری خاصی Ù…Øدود شده است.</p>
<hr>
<p class=\"mb-0\">متاسÙانه گروه کاربری Ùعلی شما در لیست گروه های مجاز نیست</p>
</div>";
echo $myRow['SummaryText'];
break;
case ($myRow['IsFree'] == "N" and !IsLoggedIn()):
echo "<div class=\"alert alert-warning\" role=\"alert\">
<h4 class=\"alert-heading useTitr\">عدم مجوز دسترسی</h4>
<p>مشاهده متن این صÙØÙ‡ مستلزم ورود به سیستم Ùˆ پرداخت هزینه مصوب است.</p>
<hr>
<p class=\"mb-0\">برای پرداخت هزینه روی آیکون سبد خرید کلیک کنید.</p>
</div>";
echo $myRow['SummaryText'];
break;
case ($myRow['IsFree'] == "N" and IsLoggedIn() AND $allowed == 0 AND !IsAdmin()):
echo "<div class=\"alert alert-warning\" role=\"alert\">
<h4 class=\"alert-heading useTitr\">عدم مجوز دسترسی</h4>
<p>کاربر گرامی برای مشاهده متن این صÙØÙ‡ لازم است هزینه مصوب را پرداخت نمائید.</p>
<hr>
<p class=\"mb-0\">برای پرداخت هزینه روی آیکون سبد خرید کلیک کنید.</p>
</div>";
echo $myRow['SummaryText'];
break;
break;
default:
if ($myRow['TopTPL'] != ""){
$tpl = new template();
$tpl->assign(array(
'PageTitle' => $myRow['PageTitle']
));
$tpl->display("tpl/".$myRow['TopTPL']."");
}
$paginate = new Pagebreak();
$paginate->splitText($myRow['PageContent']);
$paginate->setPage();
$paginate->getContent();
//new pages photos
/*
echo "<span id=\"el_pages_RelatedPhotos\"><span>";
echo GetFileViewTag($pages_view->RelatedPhotos, $pages_view->RelatedPhotos->getViewValue(), FALSE);
echo "</span></span>";
*/
//end pages photos
if ($myRow['BotTPL'] != ""){
$tpl = new template();
$tpl->assign(array(
'PageTitle' => $myRow['PageTitle']
));
$tpl->display("tpl/".$myRow['BotTPL']."");
}
$paginate->getPageLinks();
?>
<!-- Footer Start-->
<!-- Tags Start-->
<div class="btn-group">
<?php
if ($myRow['Tags'] <> ""){
$array = explode('-', $myRow['Tags']);
foreach($array as $value) {
echo "<a class=\"btn btn-default btn-sm rounded\" href=\"listpages-kpt-".$_GET['PID']."-tag-$value.html\">".$value . PHP_EOL."</a> ";
}
}
?>
</div>
<!-- Tags End-->
<div class="card-footer mt-3">
<!-- Go to www.addthis.com/dashboard to customize your tools --> <div class="addthis_inline_share_toolbox"></div>
<small class="float-right text-muted"> <strong>آخرین ویرایش:</strong> <?php echo $myRow['PostDate']; ?> <strong>بازدید:</strong><?php echo $myRow['PageView']; ?></small>
</div>
<!-- Footer End-->
<!--- Printing Start --->
<button id="PrintList" class="btn btn-default btn-circle shadow rounded mt-3"><i class="fas fa-print"></i></button>
<div id="PrintArea" class="container" style="display: none;">
<table class="table">
<tr>
<td>
<div class="text-secondary text-right useTitr"><img src="images/pedralogo.png" class="img-left"> <?php echo $myRow['PageTitle']; ?></div>
<p class="card-text">
<?php
echo str_replace("[more]","",$myRow['PageContent']);
?>
</p>
</td>
</tr>
</table>
</div>
<!-- Printing End --->
<!-- Footer End -->
<?php
}
?>
</div><!-- CARD BODY END -->
</div><!-- PAGE CONTENT END -->
<!-- Flickity HTML init -->
<div class="carousel mb-4" id="pedra">
<?php
$config = new SiteConfig;
$topcardnum = $config->HomeTopCards;
$sSqlWrk = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".$_GET['PID'].",PagesID) AND IsActive = 'Y' AND CardPlace = 'B' AND flickity = 'Y' ORDER BY ID ASC";
$all_rows = ExecuteRows($sSqlWrk);
if(is_array($all_rows) || is_object($all_rows)){
foreach($all_rows as $a_row){
echo "<div class=\"carousel-cell\">";
if ($a_row['ShowRibon'] == 'Y'){
echo "<div class=\"ribbon-wrapper\">";
echo "<div class=\"ribbon bg-".$a_row['RibbonClass']."\">".$a_row['RibbonText']."</div></div>";
}
echo "<h6 class=\"useTitr text-light mb-2 p-2 text-center\">".$a_row['CardTitle']."</h6>";
echo "<img class=\"card-img-top img-fluid\" src=\"cards/".$a_row['CardPhoto']."\" alt=\"".$a_row['CardTitle']."\" title=\"".$a_row['CardTitle']."\">";
echo "<div class=\"card-footer text-center mb-1\">";
echo "<button target=\"_self\" url=\"".$a_row['CardLink']."\" class=\"btn btn-".$a_row['CardClass']." links float-right\">".$a_row['LinkTitle']."</button>";
echo "</div></div>";
}
}
?>
</div>
<!-- Flickity HTML End -->
<!-- BOTTOM CADS START -->
<div class="card-deck">
<?php
$config = new SiteConfig;
$cardnum = $config->PagesBotCards;
$sSqlWrk = "SELECT * FROM cards WHERE CardType = 'P' AND FIND_IN_SET(".$_GET['PID'].",PagesID) AND IsActive = 'Y' AND CardPlace = 'B' AND flickity = 'N' ORDER BY rand() LIMIT $cardnum";
$all_rows = ExecuteRows($sSqlWrk);
if(is_array($all_rows) || is_object($all_rows)){
foreach($all_rows as $a_row){
echo "<div class=\"card card-widget shadow rounded\">";
echo "<img class=\"card-img-top\" src=\"cards/".$a_row['CardPhoto']."\" alt=\"".$a_row['CardTitle']."\" title=\"".$a_row['CardTitle']."\">";
echo "<blockquote class=\"quote-".$a_row['CardClass']."\">";
echo "<h4 class=\"text-".$a_row['CardClass']." useTitr\">".$a_row['CardTitle']."</h4>";
echo "<p>";
echo $a_row['CardText'];
echo "</p>";
echo "</blockquote>";
echo "<div class=\"card-footer\">";
echo "<p class=\"card-text\"><small class=\"text-muted\"><a href=\"".$a_row['CardLink']."\" class=\"btn btn-".$a_row['CardClass']." btn-sm float-right\">".$a_row['LinkTitle']."</a></small></p>";
echo "</div>";
echo "</div>";
}
}
?>
</div>
<!-- BOTTOM CADS END -->
<!-- Comments Section-->
<?php
if ($myRow['AllowComment'] == "Y"){
$botclass = "";
$textareadisabled = "";
}else{
$botclass = "disabled";
$textareadisabled = "disabled = disabled";
}
?>
<!-- COMMENT FORM -->
<div class="card mb-2 card-widget rounded">
<blockquote class="quote-danger">
<h3 class="text-info useTitr">شما Ú†Ù‡ Ùکر Ù…ÛŒ کنید؟</h3>
<p><small>لطÙا نظر خود را در خصوص این مطلب ثبت نمائید.</small></p>
</blockquote>
<!-- /.card-header -->
<div class="card-body">
<input type="hidden" id="PageID" name="PageID" value="<?php echo $_GET['PID']; ?>"/>
<input type="hidden" name="CommentType" id="CommentType" value="Pages"/>
<input type="hidden" name="token" value="<?php echo CurrentPage()->Token; ?>"/>
<div class="input-group input-group-sm mb-3">
<div class="input-group-append">
<div class="input-group-text"><span class="fas fa-user"></span></div>
</div>
<input type="text" class="form-control" size="30" id="SenderName" placeholder="نام و نام خانوادگی" <?php echo $botclass; ?>>
</div>
<div class="input-group input-group-sm mb-3">
<div class="input-group-append">
<div class="input-group-text">@</div>
</div>
<input type="email" class="form-control" size="30" id="SenderEmail" placeholder="آدرس ایمیل" <?php echo $botclass; ?>>
</div>
<div class="input-group input-group-sm mb-3">
<div class="input-group-append">
<div class="input-group-text"><span class="fas fa-tasks"></span></div>
</div>
<textarea class="form-control" name="comment" id="comment" placeholder="نظرتان را اینجا بنویسید" <?php echo $textareadisabled; ?> required></textarea>
</div>
<button id="sendform" class="btn btn-success btn-circle shadow rounded mb-3" <?php echo $botclass; ?>>ثبت نظر</button>
<div id="mybox" style="display: none;"></div>
</div>
</div>
<!-- COMMENT FORM END -->
<!-- COMMENTS -->
<div class="card mb-2 card-widget rounded">
<div class="card-header text-muted">
<h3 class="card-title text-info useTitr text-center">دیدگاه کاربران</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<?php
$RecNo = ExecuteScalar("SELECT * FROM pagecomments WHERE PageID = '".$_GET['PID']."'");
switch ($RecNo){
case 0:
echo "<h5 class=\"text-warning\"><i class=\"fas fa-exclamation-triangle fa-2x text-warning\"></i> تاکنون برای این مطلب نظری ثبت نشده است</h5>";
break;
default:
$sSqlWrk = "SELECT * FROM pagecomments WHERE PageID = '".$_GET['PID']."' ORDER BY CommentID DESC";
echo "<div class=\"direct-chat-messages\" id=\"chats\">";
$all_rows = ExecuteRows($sSqlWrk);
if(is_array($all_rows) || is_object($all_rows)){
foreach($all_rows as $a_row){
echo "<div class=\"direct-chat-msg\"><div class=\"direct-chat-warning clearfix\"><span class=\"direct-chat-name float-left\"><a href=\"mailto:".$a_row['SenderEmail']."\">".$a_row['SenderName']."</a></span><span class=\"direct-chat-timestamp float-right\">".$a_row['PostDate']."</span></div><div class=\"direct-chat-text\">".$a_row['Comment']."</div></div>";
}
}
echo "</div>";
}
?>
</div>
</div>
<!-- COMMENTS END -->
<!-- Comments Section End-->
<script>
loadjs.ready("load", function() {
$(document).ready(function(){
$("#pedra").flickity({
cellAlign: 'right',
wrapAround: true,
draggable: true,
rightToLeft: true,
pageDots: true,
contain: false
});
$("#pedra2").flickity({
cellAlign: 'right',
wrapAround: true,
draggable: true,
rightToLeft: true,
pageDots: true,
contain: false
});
$("button.links").click(function(e){
e.preventDefault();
var link = $(this).attr("url");
var target = $(this).attr("target");
window.open(link , target);
});
// Print Page
$( "#PrintList" ).click(function() {
$(this).printThis("PrintArea");
});
// Purchase Page
$("#PurchaseIT").click(function(e){
e.preventDefault();
$(this).html("<i class=\"fas fa-spinner text-success fa-spin fa-2x\"></i>");
var pushedBtn = $(this);
var Page = $(this).val();
var Price = $(this).attr("price");
$.ajax({
type: "POST",
url: "purchasepage.php",
data: {
Page:Page,Price:Price
},
success: function(res) {
pushedBtn.html("<i class=\"far fa-check-circle fa-2x text-success\"></i>");
$("#message").html(res);
setTimeout('$("#message").empty()',7000);
},
error: function(res) {
pushedBtn.html("<i class=\"fas fa-cart-plus text-success fa-2x\"></i>");
$("#message").html(res);
setTimeout('$("#message").empty()',7000);
}
});
});
<?php
$siteconf = new SiteConfig();
$sitedesc = $siteconf->AppendTitle($myRow['PageTitle']);
$pagetitle = $myRow['PageTitle'];
?>
$("#ew-page-caption").text("<?php echo $pagetitle; ?>");
$(this).attr("title", "<?php echo $sitedesc; ?>");
$("#sendform").click(function(e){
e.preventDefault();
$('#mybox').show();
//check required fields
if($('#SenderName').val() == ''){
$( "#SenderName" ).focus();
$('#mybox').html("<div class=\"alert alert-warning\" role=\"alert\"><i class=\"fas fa-exclamation-triangle fa-5x text-danger\"></i> لطÙا نام Ùˆ نام خانوادگی خود را وارد کنید</div>");
exit;
}
if($('#SenderEmail').val() == ''){
$( "#SenderEmail" ).focus();
$('#mybox').html("<div class=\"alert alert-warning\" role=\"alert\"><i class=\"fas fa-exclamation-triangle fa-5x text-danger\"></i> آدرس ایمیل خود را وارد کنید</div>");
exit;
}
if($('#comment').val() == ''){
$( "#comment" ).focus();
$('#mybox').html("<div class=\"alert alert-warning\" role=\"alert\"><i class=\"fas fa-exclamation-triangle fa-5x text-danger\"></i> لطÙا نظرتان را در Ùیلد مربوطه وارد کنید</div>");
exit;
}
var SenderName = $("#SenderName").val();
var SenderEmail = $("#SenderEmail").val();
var PageID = $("#PageID").val();
var Comment = $("#comment").val();
var CommentType = $("#CommentType").val();
$.ajax({
url:"savecomment.php", //the page containing php script
data: {
Comment:Comment,PageID:PageID,SenderName:SenderName,SenderEmail:SenderEmail,CommentType:CommentType
},
type: "POST", //request type
success:function(result){
$('#mybox').html(result);
$("#comment").val("");
setTimeout('$("#mybox").empty()',7000);
}
});
});
});
});
</script>
arbei
December 25, 2020, 1:17am
9
If you need to show HTML like a normal page, you use Custom File with Include common files.If you use Custom File, there is no route parameters, you may continue to use http://site/MyCustomFile?ID=2 and keep your code (e.g. $_GET[“ID”]) in the page.If you just need to return some result of an action (e.g. a value by ExecuteScalar() or a row by ExecuteRow()), it is better and simpler to use Route_Action server event, then you can define your parameters in the route and get the value in your code by $args[“xxx”] or Route(“xxx”).
mansour
December 26, 2020, 8:00pm
10
Hi,
Please take a look at the following code and tell me what’s wrong with my work.
1- I added a custom field to my AAA table.
2- I added the following code to my Row_Rendered server event for table AAA.
$this->ViewButton->ViewValue = "<button type=\"button\" class=\"btn btn-success m-1 shadow ViewButton\" data-patientid=\"".$this->PatientID->CurrentValue."\" data-doctorid=\"".$this->User->CurrentValue."\" data-patientname=\"".$this->PatientID->ViewValue."\" value=\"".$this->ID->CurrentValue."\"><i class=\"fas fa-check-double\"></i></button>";
3- I added the following code to the startup script for the view page (table AAA)
$(document).ready(function(){
$(".ViewButton").click(function(e){
var pushedBtn = $(this);
var PatientID = $(this).data('patientid');
$.ajax({
type: "GET",
cache: false,
url: "/test",
data: {
PatientID:PatientID
},
success: function(res) {
pushedBtn.html(res);
},
error: function(res) {
alert(JSON.stringify(res));
}
});
});
});
4- I created a custom file (included common file) named as test.php and putted the following code inside it :
<?php
echo $_GET['PatientID'];
?>
When I click on the BUTTON mentioned above I receive an error message as object.
{“readyState”:4,“responseText”:“\n\n404 Not Found\n\n
Not Found \n
The requested URL was not found on this server.
\n
\nApache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.2.33 Server at 127.0.0.1 Port 80\n\n”,“status”:404,“statusText”:“Not Found”}What’s wrong? is there any other step to do ?Thanks
arbei
December 27, 2020, 3:37am
11
As explained:
If you need to show HTML like a normal page, you use Custom File with > Include common files> .
If you use Custom File, there is no route parameters, you may continue to use > http://site/MyCustomFile?ID=2 > and keep your code (e.g. $_GET[“ID”]) in the page.
but you wrote:
I created a custom file (included common file) named as test.php and putted the
following code inside it :
<?php
echo $_GET['PatientID'];
?>
>
Then the output of your Custom File has header and footer and output patient ID only if the querystring of your URL includes ?PatientID=xxx. (Again, if you use Custom File, there is no route parameters.)In addition, the error is 404, which means your URL /test is incorrect. If you app has base path, it should be /myBasePath/test.To use Custom File or Route_Action depends on what you want to return. As explained:
> If you just need to return some result of an action (e.g. a value by > ExecuteScalar() > or a row by > ExecuteRow()> ), it is better and simpler to use > Route_Action > server event, then you can define your parameters in the route and get the value in your code by > $args["xxx"] > or > Route("xxx")> .
In such case you should use Route_Action server event to create an action name "test" with parameter, see https://discourse.hkvstore.com/t/using-route-action-server-event-v2021/3393/1 e.g.
```text
$app->get('/test/{patientId}', function ($request, $response, array $args) {
$patientId = $args['patientId'];
$myResult = ... your code to use the $patientId and get the result ...;
$response->getBody()->write($myResult); // Write to response body
return $response; // Return the response
});
Note: If you want to return JSON, read Returning JSON .Then you can access the action by URL like /myBasePath/test/1234 where 1234 is a patient ID.