0

I'm using Codeigniter, and this is my issue:

I display some information about a product and this includes the name, date and description of it. In the description I use a "..See More" when it's longer than 100 characters.

The thing is that in my code when users click on "See More" in order to see complete product description, I'm facing the problem that I don't know how to send whole product object from one function to another. See the snippet:

foreach ($this->data['smallprizes'] as $key => $value) {

            if(strlen($value->description)>100){
                $stringCut = substr($value->description, 0, 100);
                $string = substr($stringCut, 0, strrpos($stringCut, ' ')).'...'; 
            }else{
                $string = $value->description;
            }

            $string = $string .'<a href= benefitSummary/'.$value->id.'>Leer Más</a>';
            $sp[$value->id]['id'] = $value->id;
            $sp[$value->id]['title'] = $value->title;
            $sp[$value->id]['descrip'] = $string;
            $sp[$value->id]['creation_date'] = $value->creation_date;
            $sp[$value->id]['start_date'] = $value->start_date;
            $sp[$value->id]['end_date'] = $value->end_date;
            $sp[$value->id]['stock'] = $value->stock;

            if ($value->status == 1) {
                $status = 1;
            }else{
                $status = 0;
            }

            $sp[$value->id]['status'] = $status;

            $this->data['sp'] = $sp;
        }

the function that I want to send whole object is benefitSummary. I'm sending product ID in the href.

How do I do to get whole product object inside benefitSummary function?

Thanks in advance.

J.

Limon
  • 1,772
  • 7
  • 32
  • 61
  • Fetch it, just like you're fetching it in the function you showed here? – Shomz Mar 05 '14 at 18:34
  • @Shomz What do you mean? – Limon Mar 05 '14 at 18:46
  • In the benefitSummary function, you'll have to query the database to get the product information based on the provided ID. – Samutz Mar 05 '14 at 19:01
  • of course. But what about passing an object? (supose i need this for a future case) – Limon Mar 05 '14 at 19:02
  • To get it the same way you're getting it in the function you've shown. And you can't pass an object via URL, but you can load it and build it from the database data. – Shomz Mar 05 '14 at 19:04
  • 1
    You can't send an object through a URL. You'd have to store it somewhere first (session, database) and then retrieve it on the benefitSummary page. You could use post or get data, but you'd also have to convert it to a format that either can accept. – Samutz Mar 05 '14 at 19:07
  • Another way to do it would be to pass the entire text and then hide / show the full text with jquery. http://stackoverflow.com/questions/5270227/how-to-hide-show-more-text-within-a-certain-length-like-youtube – cartalot Mar 05 '14 at 21:01
  • @Shomz can you please post your comments as answers? so I can choose that as the solution for my problem – Limon Mar 11 '14 at 15:00
  • Yes, sure, in a minute. – Shomz Mar 11 '14 at 16:47

2 Answers2

0

As far as I know you can serialize an object and send it through the URL (or as a POST request).

link to the docs : http://us2.php.net/manual/en/function.serialize.php

Basically this turns an object into a coded string, which can be interperted on the other side to get it's values.

Patrick
  • 3,289
  • 2
  • 18
  • 31
0

You can get it the same way you're getting it in the function you've shown. And you can't pass an object via URL, but you can load it and build it from the database data. There's no need to send all the data anyway because you have that data elsewhere already.

So it means you'll send an id as a parameter to your benefitSummary controller method (which is what you're already doing), and then use it there to fetch the appropriate database entry with all the data you need (preferably using a model to communicate with the database).

Shomz
  • 37,421
  • 4
  • 57
  • 85