How add multiple actions In URL? - url-action

How can I add more than one action to a URL? As I described in the title, I want to add more than one action to a URL. How do I do that?
As a further clarification, I define actions for some parts in an HTML file, and by setting an action, I handle the request in the php file!
Example:
example.com/?order=1&price=high
I appreciate your help.

As i ask and get help from my friend, we can use function like this to solve our problem:
function shapeSpace_add_var($url, $key, $value) {
$url = preg_replace('/(.*)(?|&)'. $key .'=[^&]+?(&)(.*)/i', '$1$2$4', $url .'&');
$url = substr($url, 0, -1);
if (strpos($url, '?') === false) {
return ($url .'?'. $key .'='. $value);
} else {
return ($url .'&'. $key .'='. $value);
}
}
example:
$url = 'http://example.com/whatever/?hello=world';
shapeSpace_add_var($url, 'goodbye', 'nightclub');
Result:
http://example.com/whatever/?hello=world&goodbye=nightclub

Related

How to show POST data from external url api to my blade file

External site data to be displayed on my blade
MerchantCode
MerchantRefNo
Particulars
Amount
PayorName
PayorEmail
Status
RefNo
Here's my Controller
function getPaymentDetail()
{
$data = Http::get('https://external.com/api')->json();
return view('paymentdetails',['data'=>$data]);
}
I would code it like this.
In your controller.
function getPaymentDetail() {
$res = Http::get('https://external.com/api')->json();
$temp_data = json_decode($temp_data, TRUE);
foreach($temp_data as $key => $value) {
$data[$key] = $value;
}
return view('paymentdetails', $data);
}
In your blade file, you can access by {{ $MerchantCode }}

Find a Session by ID Substring in Laravel 8

Im trying to find a session by PART of its ID in laravel.
I only have the first part of the id, and I need to find if the session has a key/value associated with it.
I have tried various forms of the below code. Its fairly simple but not sure if possible in laravel.
Note
Im not sure if this helps or not, but the laravel system is using file based sessions, not DB based sessions.
$value = 'do i have this value';
// Session::all()->whereLike('id','aVhN8u' . '%')->get();
foreach( Session::all()->where('id')->startsWith('aVhN8u') as $session)
{
if($session->has('key', $value)
{
// Do something interesting
}
}
Something like this should work.
use Illuminate\Support\Str;
$value = 'my cool value';
$prefix = 'aVhN8u';
$stored = session()->all();
$filtered = collect($stored)->filter(function ($session, $key) use ($prefix, $value) {
return Str::startsWith($key, $prefix) && $session == $value;
})->all();

joomla - router change url when getting the name of product

I have build my own component in joomla and client wants now a friendly urls f.e
website.com/someplace/{product-id}-{product-name}. So i Build my own router like this.
function componentBuildRoute(&$query)
{
$segments = [];
if (isset($query['view'])) {
$segments[] = "szkolenie";
unset($query['view']);
}
if (isset($query['product_id'])) {
$productName = JFilterOutput::stringURLSafe(strtolower(getProductName($query['product_id'])));
$newName = $query['product_id'] . '-' . $productName;
$segments[] = $newName;
unset($query['product_id']);
}
return $segments;
}
and parse route function
function componentParseRoute($segments)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$item =& $menu->getActive();
$count = count($segments);
switch ($item->query['view']) {
case 'catalogue' : {
$view = 'training';
$id = $segments[1];
}
break;
}
$data = [
'view' => $view,
'product_id' => $id
];
return $data;
}
While on the end of buildroute function segments are ok I have exactly what I want that on the beginning of parse route I have something like
website.com/szkolenie/1-krakow <-- I dont know wtf is this krakow( I know it is city i Poland) but still where is it get from ? The getProductName function implementation is
function getProductName($productId)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('#__component_training.id as id, #__component_product' . name)
->from($db->quoteName('#__component_training'))
->where('#__s4edu_product.product_id = ' . $productId)
->leftJoin('#__component_product ON
#__component_training.product_id=#__component_product.product_id');
$training = $db->loadObject();
return trim($training->name);
}
So taking all this into consideration I think that something is happening between the buildRoute and parseRoute, something what filters the $segment[1] variable, but how to disable that and why is it happening ?
P.S
Please do not send me to https://docs.joomla.org/Joomla_Routes_%26_SEF
I already know all the tutorials on joomla website which contains anything with sef.
P.S.S
It is built on joomla 3.7.0
You do not have a product named "krakow" ?
If not you can try to remove the $productName from the build function, just to check if this "krakow" is added automaticaly or it's from the getProductName() function.
Also i noticed that you have an error i guess in the function getProductName()
->where('#__s4edu_product.product_id = ' . $productId)
It's should be
->where('#__component_product.product_id = ' . $productId)

Magento remove param and redirect to same url

I want to remove some URL parameter (like utm_source, but whatever), put it in session and redirect to same page with URL clean of this specific param
I've done in controller_front_init_before like this:
$frontController = $observer->getEvent()->getFront();
$params = $frontController->getRequest()->getParams();
$myParams = array("b");
foreach($myParams as $myParam) {
if (isset($params[$myParam])) {
$customerSession->setData(
$myParam, $params[$myParam]
);
unset($params[$myParam]);
}
}
$frontController->getRequest()->setParams($params); // <- I don't know what to do with that
Now what is the best method to redirect to the same page in request ?
For example redirect http://example.com?a=1&b=2&c=3 to http://example.com?a=1&c=3
Thanks!
$frontController = $observer->getEvent()->getFront();
$params = $frontController->getRequest()->getParams();
$shouldRedirect = false
foreach($params as $key => $value) {
if ($key !== 'b') {
$customerSession->setData($key, $value);
}
else{
unset($params[$key]);
$shouldRedirect = true;
}
}
if($shouldRedirect){
//$url = get url and redirect
//see http://magento.stackexchange.com/questions/5000/add-query-parameters-to-an-existing-url-string
Mage::app()->getResponse()->setRedirect($url);
}

Codeigniter - configure enable_query_strings and form_open

I want to be able to user query strings in this fashion. Domain.com/controller/function?param=5&otherparam=10
In my config file I have
$config['base_url'] = 'http://localhost:8888/test-sites/domain.com/public_html';
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';
$config['enable_query_strings'] = TRUE;
The problem that I am getting is that form_open is automatically adding a question mark (?) to my url.
So if I say:
echo form_open('account/login');
it spits out: http://localhost:8888/test-sites/domain.com/public_html/?account/login
Notice the question mark it added right before "account".
How can I fix this?
Any help would be greatly appreciated!
The source of your problem is in the Core Config.php file where the CI_Config class resides. The method site_url() is used by the form helper when you are trying to use form_open function.
Solution would be to override this class with your own. If you are using CI < 2.0 then create your extended class in application/libraries/MY_Config.php, otherwise if CI >= 2.0 then your extended class goes to application/core/MY_Config.php.
Then you need to redefine the method site_url().
class MY_Config extends CI_Config
{
function __construct()
{
parent::CI_Config();
}
public function site_url($uri='')
{
//Copy the method from the parent class here:
if ($uri == '')
{
if ($this->item('base_url') == '')
{
return $this->item('index_page');
}
else
{
return $this->slash_item('base_url').$this->item('index_page');
}
}
if ($this->item('enable_query_strings') == FALSE)
{
//This is when query strings are disabled
}
else
{
if (is_array($uri))
{
$i = 0;
$str = '';
foreach ($uri as $key => $val)
{
$prefix = ($i == 0) ? '' : '&';
$str .= $prefix.$key.'='.$val;
$i++;
}
$uri = $str;
}
if ($this->item('base_url') == '')
{
//You need to remove the "?" from here if your $config['base_url']==''
//return $this->item('index_page').'?'.$uri;
return $this->item('index_page').$uri;
}
else
{
//Or remove it here if your $config['base_url'] != ''
//return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
return $this->slash_item('base_url').$this->item('index_page).$uri;
}
}
}
}
I hope this helps and I think you are using CI 2.0 that wasn't officially released, this was removed in the official CI 2.0 version
Simpler might be to just set follwing in your config.php
$config['enable_query_strings'] = FALSE;
Was the solution in my case.
If you want to use query string in your url structure, then you should manually type your url structure in the following order:
<domain.com>?c={controller}&m={function}&param1={val}&param2={val}
in the action of the resepective controller you should get the parameter as $_GET['param1']
your code now should look like this
form_open(c=account&m=login&param1=val)
Please let me know if it doesnt work for you.

Resources