0

Is there a way to carry over a variable after a redirect ?

For example on a projects.php

foreach ($projects as $key=>$project) : ?>
    <li class="">
        <a href="<?= root_url('project/'.$project->url_title) ?>/" title="<?= $project->name ?>">
            <? if ( isset($project->images[0]) ) :
                $thumb_image_path = $project->images[0]->getThumbnailPath(310, 276, true, array('mode'=>'fit'));
            else :
                $thumb_image_path = '//placehold.it/320x285/ffffff/000000';
            endif ?>
            <? // echo $thumb_image_path; ?> 
            <img src="<?= $thumb_image_path ?>" alt="<?= $project->name ?>">
            <div class="caption">
                <h4><?= $project->name ?></h4>
                <h5 class="hide-for-small-only">Not dynamic</h5>
                <p class="hide-for-small-only"><?= $project->description ?></p>
            </div> 
        </a>
    </li>
<? endforeach ?>

When redirected to project/nameoftheproject , is there a way to still have access to the variable $project ? So I could use it to do $project->title

Thanks for your answers

2
  • 3
    stuff it into a session, or send it over via cookie or query string. Commented Mar 3, 2014 at 3:23
  • Session or cookie would be the best option. Compressing an object into a query string would be messy. Commented Mar 3, 2014 at 3:26

1 Answer 1

2

To expand on @MarcB, you can add the variable to a query string:

your_url?variable=foo

Or add it to a session

$_SESSION['variable'] = 'foo';

or a cookie (mmmm)

$_COOKIE['variable'] = 'foo'; setcookie('variable', 'foo');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.