Php - Multiple Pages Same Url Different Ids? - php

I've been working on a project for which i want to create a page leading to different pages but i want to use same URL i have created all the pages but now i am stuck...
the Thing i want is.
i have pages **
index324.php , index34.php , index378.php , index345.php ,
index365.php , index334.php
What i want is to use a url -
index.php?product_id=21
index.php?product_id=23
Something Like Shown Above.

On your index.php, check if $_GET['product_id'] is set. If it is, use it to retrieve the desired ID which in turn you will use for checking against a database/file/whatever.
if (isset($_GET['product_id']))
$product_id = $_GET['product_id'];
Of course, you'll want to do some validation on the fetched ID to be sure it won't harm anything in your system since it can be altered by anyone issuing a GET request to your page.

Suppose that you have product detail pages for each product like: product1.php, product2.php etc ... You can include your desired file in index.php by passing GET parameter. e.g. (index.php?product_id=21) :
if(isset($_GET['product_id'])){
$product_id = $_GET['product_id'];
include('product' .$product_id. '.php');
}
else{
// product_id is not set ...
// do more stuff...
}

Related

Get access to $item->getNumberOfDownloadsUsed() function on Download.php

I need to get the number of downloads bought and used, that's two methods that are available on $item object. But I can't instance $item on the file that I'm working:
app/code/core/Mage/Downloadable/Helper/Download.php
On this file, I need to retrieve the number of boughts and used of the download purchased.
I'm also trying to get the order ID or at least the link hash to identify that number of boughts/used downloads with the unique id of the purchase.
For example, I try this:
Mage::getModel('downloadable/link_purchased_item')
->load($this->getOrderItem()->getOrder()->getId(), 'order_id');
But $this->getOrderItem() is not available on Download.php file. I was trying this:
Mage::getModel('downloadable/link_purchased_item')->getCollection()
->addFieldToFilter('order_item_id', $this->getOrderItem()->getId());
But obviously getOrderItem() is unavailable.
Fatal error: Call to undefined method Mage_Downloadable_Helper_Download::getOrderItem() in /[...]/app/code/core/Mage/Downloadable/Helper/Download.php on line 135
But I'm able to use the customer singleton to retrieve client data like this:
$cliente = Mage::getSingleton('customer/session')->getCustomer();
So on this file I'm able to access others methods, but I'm unable to get the following details:
Number of downloads bought
Number of downloads used
Order ID or Link hash ID.
So please, I'm requesting how to get the current order instance and / or the current link instance, on the Download.php related with the file downloading.
Thank you!
You are doing it wrong, you can not get any object like this $this->getOrderItem() without set/declaring them. As you are trying to get order_id and item_id in the helper, which you are using on a custom page redirected from customer downloadable products. Here is what you have to do
Step - 1
From customer My Downloadable products, in the redirect url you have to pass that products order_id and item_id as parameter. You can get them from below code
$orderId = $_item->getPurchased()->getOrderId();
$itemId = $_item->getId();
Step -2
Now in your template file while using your helper function pass this order_id and item_id to method parameter. Like below code
$orderId = $this->getRequest()->getParam('order_param');
$itemId = $this->getRequest()->getParam('item_param');
//Your helper function
Mage::helper('your_helper')->yourMethod($orderId, $itemId);
Step - 3
In your helper file you can use below code
public function yourMethod($orderId, $itemId)
{
$linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')
->load($orderItem, 'order_id');
$LinkPurchaseOrderItemId = Mage::getModel('downloadable/link_purchased_item')->getCollection()
->addFieldToFilter('order_item_id', $itemId);
}
Note: Do not make any changes in core files, instead override them

get and add php variable in wordpress page

hi i create one custom page in WordPress like page-download.php
i access this page like
http://example.com/download
its word fine but i want access this page like
http://example.com/download?n=skype
http://example.com/download?n=firefox
etc every time n value change.
and also i want get n value in page-download.php
please tell me how to do it . i know how to work in php simple but in wordpress its not work
Why just not use, echo $_GET['n'] ?
When you hit this page directly from the URL like below, please change your parameter, because of that I have tried same method few days ago and I can't get the parameter value.
http://example.com/download?from_browser=skype
http://example.com/download?from_browser=firefox
You can get the value like below or as per the reference :
$blah = get_query_var( 'from_browser');
if(isset($blah)) // Your code will be here
Hope this help!!!

In Wordpress: How do I get Page Template “page ID” to match “URL ID”

I am new to PHP in general, so I’m not entirely sure what syntax to write.
I want to get the URL from the top browser (which will change when I click Next or Previous) example: (where the number after - # is the ID)
/gallery-1/, /gallery-2/, /gallery-3/,
Based on the Page URL I want to: Get the matching "page content" which is in it’s own directory file and titled (where the number after - # is the ID)
page-gallery/gallery-1.php
page-gallery/gallery-2.php
If the URL [ID#] && Filename[ID#] == the same/Match, I want to
display template name filename[#].With an exception of null for error (Else: Error).
get_template_part( 'page-gallery/gallery', '{MATCHING-ID#}' );
Wordpress has the following features that I know of (but don't know how to apply):
- get page uri (top-level-page/sub-page/current-page) where current-page is what I am trying to get + The ID. So I don't just want the current-page I want the current-page-[#].
- wp_parse_url (string $url) , is another feature that Wordpress has which may be helpful for breaking and splitting the url, but I'm not sure how to tell it to get the /current-page-# and if I'd have to compile an array to manually tell Wordpress of all the gallery-pages the site contains.
-Pagination - could be what I am attempting to do, where instead of breaking the gallery into multiple pages containing it all into a single page and using something like but the pages I have are very long in general and I would have to merge all my separate files back into one.
-Basename - in relation to getting filename directories that I might have to use basename. Not sure how to do this but imagine it would follow the same pattern as URL and getting/splitting the ID that I need.
My current code is:
while ( have_posts() ) : the_post();
//if URL-[ID#] && Template[#] ==
//Then Display Template[#] that == URL [ID#] else, error.
// <-- Not sure how to write this,
//and if I need an array of my template_parts.
get_template_part( 'page-gallery/gallery', '[Same # as URL]' );
endwhile; // End of the loop.
?>
<?php getPrevNext(); ?>
I know this is something simple, but I don't know how to write the syntax for it. Any help would be greatly appreciated.

Laravel ajax pagination set page

In my laravel project i use hashes in the url to keep track on selections of the user, so they are able to go back to a filter result. I dont want the page to refresh so I DONT UPDATE THE URL with Page=someid (except the hash) the response of the server looks like.
if ($request->ajax()) {
//The page I want to select posted with ajax
$paginaId = $request->input('page');
//some query like
$query = Table::Query();
//get 9 items
$rooms= $query->paginate(9);
//Return the response
return Response::json(View::make('front.rooms.render', array('rooms' => $rooms))->render());
}
The $paginaId represents the selected pagination page. Everything works fine except one part. I cant set the current page of the pagination. I viewed the documentation but couldn't find any solutions.
Try the following:
$rooms = $query->paginate(9, ['*'], 'page', $paginaId);
In this case you can set $paginaId manualy

urls with item title

I was used to putting id's in the URL to map to an item in the database:
/hotels/1
but what if I want to get the name of the hotel with an id of 1 and put it in the URL and replace spaces with hyphens?
/hotels/hotel-bianca
I am using Kohana and there is the concept of routing (which is pretty much present in all MVC frameworks), but I can't seem to get it working
How do I go about doing this?
Since I know nothing about kohana, I am going to present a possible PHP answer.
Could you pass the id through the URL and request it with PHP, and if you're passing the name of the hotel, have that correspond to the item in the database with the hotel-name as its field?
For this purpose I use special field in db table named url :)
So for example /controller/open/urladress will look for url field with 'urladress' inside to open :D
I don't think you can change uri on fly)
In the controller you could search the database for the name. I am used to Kohana 2.3.4 with ORM so this is how I would do it:
// first you need to replace all hyphens with spaces
$name = str_replace('-', ' ', $parameter);
// search your db for the hotel by name
$hotel = ORM::factory('hotel')->where('name', $name)->find();
// check to make sure it is loaded
if ( ! $hotel->loaded)
{
// Do something i.e. 404 page or let them know it wasn't found
}
This would let you specify by name. You could also add a check to see if the parameter was integer or not and search by id if it was.

Categories