Added faq start

This commit is contained in:
DESKTOP-GBA0BK8\Admin
2023-04-09 18:01:01 -04:00
parent a4a0345055
commit dcb016d180
3 changed files with 109 additions and 37 deletions
+3
View File
@@ -36,6 +36,9 @@ $routes->get('/', 'Home::index');
$routes->get('/wp/', 'Dengine::index');
$routes->get('/en/floatweb/api/v1/blogdata/', 'FloatWeb::blogData');
$routes->get('/en/floatweb/api/v1/blogdata/(:any)', 'FloatWeb::blogData/$1');
$routes->get('/en/floatweb/api/v1/faq', 'FloatWeb::website');
$routes->post('/en/floatweb/api/v1/contact', 'FloatWeb::website');
//CHIEFSOFT WEBSITE
+31
View File
@@ -8,6 +8,8 @@ use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use CodeIgniter\Cache\CacheInterface;
/**
* Class BaseController
@@ -49,4 +51,33 @@ class BaseController extends Controller
// E.g.: $this->session = \Config\Services::session();
}
public function runCache($cacheKey,$data){
$cache = \Config\Services::cache();
if (! $foo = cache($cacheKey)) {
echo 'Saving to the cache!<br>';
cache()->save($cacheKey, $this->data_stringify($data), 3000);
}
// $foo = $cache->get('foo');
}
private function data_stringify($data) {
switch (gettype($data)) {
case 'string' : return '\''.addcslashes($data, "'\\").'\'';
case 'boolean': return $data ? 'true' : 'false';
case 'NULL' : return 'null';
case 'object' :
case 'array' :
$expressions = [];
foreach ($data as $c_key => $c_value) {
$expressions[] = $this->data_stringify($c_key).' => '.
$this->data_stringify($c_value);
}
return gettype($data) === 'object' ?
'(object)['.implode(', ', $expressions).']' :
'['.implode(', ', $expressions).']';
default: return (string)$data;
}
}
}
+75 -37
View File
@@ -5,7 +5,6 @@ namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Cache\CacheInterface;
class FloatWeb extends BaseController
{
@@ -530,47 +529,86 @@ variations from the norm, and in addition other reproductive organ issue
return $resJson;
}
private function runCache($cacheKey,$data){
$cache = \Config\Services::cache();
if (! $foo = cache($cacheKey)) {
echo 'Saving to the cache!<br>';
cache()->save($cacheKey, $this->data_stringify($data), 3000);
}
// $foo = $cache->get('foo');
}
private function data_stringify($data) {
switch (gettype($data)) {
case 'string' : return '\''.addcslashes($data, "'\\").'\'';
case 'boolean': return $data ? 'true' : 'false';
case 'NULL' : return 'null';
case 'object' :
case 'array' :
$expressions = [];
foreach ($data as $c_key => $c_value) {
$expressions[] = $this->data_stringify($c_key).' => '.
$this->data_stringify($c_value);
}
return gettype($data) === 'object' ?
'(object)['.implode(', ', $expressions).']' :
'['.implode(', ', $expressions).']';
default: return (string)$data;
}
}
public function index()
{
// $rawData = $this->apiData();
// // $res1= $rawData[0]['payload'];
// $res1= $rawData; //['payload'];
//
// // var_dump($res1);
//
// return $this->response->setJson($res1);
// $cache = \Config\Services::cache();
// $foo = $cache->get('foo');
}
public function website()
{
//$request = service('request');
header('Access-Control-Allow-Origin: *');
//header("Access-Control-Allow-Origin: http://localhost:9057 ");
header('Access-Control-Expose-Headers: Access-Control-Allow-Origin');
//header('Access-Control-Allow-Credentials: true ');
//header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
header('Content-type: application/json');
// what is the endpoint
$uri = urldecode(current_url(true));
$findme = '?';
$pos = strpos($uri, $findme);
if ($pos > 5) {
$uri = substr($uri, 0, $pos);
}
$pieces = explode('/', $uri);
$psc = count($pieces);
$endpoint = $psc > 0 ? $pieces[$psc - 1] : '';
log_message('critical', "Enpoint-> ".$endpoint );
$endpoints = [
'faq' => ['get'],
'blogdata' => ['GET'],
'contact' => ['POST']
];
$res1 = [];
if (array_key_exists($endpoint, $endpoints)) {
} else {
http_response_code(404);
// tell the user product does not exist
echo json_encode([
'message' => 'Endpoint not found.',
'URI' => $uri,
]);
}
// echo "EXYTACT INPUT DATA HERE";
$raw_json = file_get_contents('php://input');
$raw_array = json_decode($raw_json, true);
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$get_param = $_GET['reqData'] ?? null;
$raw_array = json_decode($get_param, true);
}
// $raw_array['fff'] = json_decode($this->request->getJSON(), true);
log_message('critical', "Enpoint LOC2-> ".$endpoint );
switch ($endpoint) {
case 'faq':
//$res1 = $this->dummyData($raw_array);
$res1 = $this->apiData();
break;
case 'blogdata':
// $res = $this->dummyData($raw_array);
break;
case 'contact':
$res1 = $this->dummyData($raw_array);
break;
}
return $this->response->setJson($res1);
}
//this is dummy function to establish the endpoints before real implementations
private function dummyData($raw_array)
{
return [
'msg' => 'Not implemented yet',
'raw_data' => $raw_array,
];
}
}