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

  • SEARCH
  • Home
  • 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 6567805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:22:49+00:00 2026-05-25T14:22:49+00:00

symfony 1.4 passing variables between templates and actions I’ve got an index page which

  • 0

symfony 1.4 passing variables between templates and actions

I’ve got an index page which includes a call to a series of partials through a switch statement; and it works. I now need to restrict access to the partial dependent upon the user’s type; furthermore, I believe my switch statement should be in the actions class according to MVC, but I can’t get that to work either. This might be better explained through example:

Here’s my file structure for the dashboard module:

..dashboard
    ..actions
    ..config
    ..templates
        _admins.php
        _employers.php
        _employees.php
        _guest.php
        indexSuccess.php

Here is my current indexSuccess template (which currently works… but without restricting access if the logged user’s type doesn’t match the page type):

$type = sfContext::getInstance()->getUser()->getGuardUser()->getProfile()->getType()->getName();
switch($type)
{
case ('Employer'): 
    include_partial('dashboard/employers');
    $page_user_type = "employer";  //this example line currently does not exist, it's for example purpose below
    $break;
case ('Employee'):
    include_partial('dashboard/employees');
    break;
case ('Administrator'):
    include_partial('dashboard/admins');
    break;
default: include_partial('dashboard/guest');
    break;
}

Here’s my actions class (currently empty):

public function executeIndex(sfWebRequest $request)
{

}

Basically, what I need is the switch statement moved to the action (I think), and a forward404Unless() method added that does the following:

$logged_user = sfContext::getInstance()->getUser()->getGuardUser()->getId(); 
$this->forward404Unless($logged_user == $page_user_type);   //where the $page_user_type variable is retrieved by the switch statement in the example line above.  

I’ve tried using the getAttribute() and setAttribute() with no success… and I’d rather not share attempts due to embarrassment. Just a beginner here…

Any help would be appreciated. Thanks in advance.

UPDATE:

Here’s more information about the switch and the different partials:

The switch renders a different partial based upon the user’s type. What it doesn’t do is keep other logged-in users of a different type from accessing all the other partials… which in my design, is very bad. For example: logged-in users of type “employer” may not view the partial of type “employee”. Currently they can (by explicitly typing in the other url), even though they are being redirected to the appropriate page during the the index action.

The 404 page should be called when a user of the wrong type tries to access the other partial by explicitly typing in the url. That’s why I was attempting to add a variable to the switch statment when the appropriate partial is called and then passing that variable to the index action which would then evaluate it and either permit the partial to be rendered, or if the user_type and partial_type did not match -> forward to a 404 page. Make sense? I hope I explained that thouroughly enough. I’m sure there is an easier way… I’m just not schooled enough to know what that might be.

I sure do appreciate your response and attempt to resolve my issue.

  • 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-05-25T14:22:50+00:00Added an answer on May 25, 2026 at 2:22 pm

    You should play with the credential system to block not authorized user to access a ressource.
    The ‘type’ of your user can become the name of a credential. Then you just have to create the security.yml to handle that.

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

Sidebar

Related Questions

My symfony projects work veeery slow, between 4 and 8 seconds per page (I'm
In Symfony 1.2, how do you create variables in actions.class.php so that they are
Symfony 2, Doctrine 2.1. I've got 3 entities, one of them intermediate (join table).
In my Symfony/Doctrine app, I have a query that orders by RANDOM(). I call
Symfony 2 dies and gives me blank page. Disclaimer: I hate blank pages. Anyway,
My symfony project has an object A which has a one-to-many relationship with object(s)
Using symfony framework, which code is best to query database table to check if
my symfony project at production when an actions does not exist is throwing error
I'am new to symfony. I need to build a static web page. The page
With Symfony's Action Security if a user has not been identified he will be

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.