Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:45+00:00 2026-06-16T00:11:45+00:00

In ProjectsController.php I’m setting a session variable as I’d like that info to be

  • 0

In ProjectsController.php I’m setting a session variable as I’d like that info to be accessible in ALL controllers, models and views:

$this->Session->write('Project.title', $this->Project->title);

Now, when I try access it from Projects view, like this:

        <p>Project: <strong>
        <?php if (isset($session->read('Project.title'))): 
            $session->read('Project.title');
        ?>
        <?php else: ?>
            Not selected
        <?php endif; ?>
        </strong></p>       

I’m getting the following error:

Fatal error: Can't use method return value in write context 

Which refers to the second line of above code.

I’ve been through CakePHP documentation and also searched SO, what am I doing wrong here?

Thanks!

EDIT:

I’ve also tried using:

$this->Session->read('Project.title')

resulting in the same error message.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:11:46+00:00Added an answer on June 16, 2026 at 12:11 am

    You should do what PHP tells you once in a while 🙂
    The error message is pretty clear. You cannot use isset() and empty() this way.
    They only work with variables direcly, not methods. So use

    <?php if ($this->Session->check('Project.title')) {
        echo $this->Session->read('Project.title');
    } ?>
    

    as documented in the cookbook

    you could also do

    <?php
    $title = $this->Session->read('Project.title');
    if ($title) {
        echo $title;
    } ?>
    

    or even

    <?php if ($title = $this->Session->read('Project.title')) {
        echo $title;
    } ?>
    

    the last one is not cakephp coding convention, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to declare a variable in my application_controller.rb controller that is accessible
My models looks something like this (stripped down to the bare minimum for this
I've got routes that look like this: resources :projects do resources :tasks end Which
Hi all I have a project that i reference the services for my graphs...and
I have a controller called ProjectsController . Its actions, by default, look for views
My Project Model looks like this: # == Schema Information # Schema version: 20101117094659
I use params in my controller like this: class ProductsController < ApplicationController def create
I have a page that lists all of the projects that has sortable headers
I have 2 controllers: Projects and Users . Both models have no relation at
I have this code in my products_controller.php: <?php class ProductsController extends AppController{ var $name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.