Using your views with basic conditional logic that will show different content based on global values like a user’s IP address or their incoming referrer address is easy through “the app.request.server” object.  You don’t need to involve your controller to produce basic web page behaviors, especially those that are global in nature you’d normally use in your views where there’s one-way display of information and NO BUSINESS LOGIC.  In other words, the behavior based on global conditions can often wait until it reaches your site’s view to produce the intended results.

Let’s say your business has its own static IP.  It’s safe to say that anyone in the building is accessing the site through the same IP address.  So here’s a simple example of how you can switch or block certain content by reading the user’s IP address:

{%  if app.request.server.get("REMOTE_ADDR")=='your.ip.address.here'  %}
  Conditional content here if in building.
{% else %}
  Content to show if not in building.
{% endif %}

If you are an business in the Jacksonville, FL, Northeast Florida, or Southeast, GA area looking for open source PHP developers or other open source web developers with experience in Symfony, Magento, Drupal, WordPress, Magento, marketing automation, or API integration experts, please contact me.  I have a list of competent open source web developers who I can recommend here in Jacksonville, Southwest Florida, and throughout the US, Canada, UK, Australia, and Germany as temporary web development solution providers or remote web developers!


Okay, so Sensio Lab’s Symfony is great, but those repositories are a bit limiting in their design scope.  I mean, how often do you need to access data through custom database queries and other cross referencing between database tables and not only use one table?  Of course, you’re going to have to combine database tables in even mildly complex website but Symfony’s repositories are designed to deal with one table and one “entity” referencing that table.

One way to make sure you are accessing other repositories from an entity’s repository is to overload the parent’s constructor by calling on the parent constructor first.  I actually stumbled onto this solution because I wanted to see what Symfony’s base Repository class’s constructor looked like.  Look familiar?  It passes in the entity manager ($em) and the repository’s class ($class).

protected $yourEntityRepo;

function __construct($em, $class){

   parent::__construct($em, $class);
   $this->yourEntityRepo=$this->getManager()->getRepository(YourBundle:YourEntity');

}

Connect as many repositories as you need to this way.   Keep in mind that without the parent __construct params, you can still access the entity manager and get the repositories with $this->getManager(), this is just a convenient way to do it automatically and make other repositories available within the repository if you make those repositories class variables which would then be available in any method in the repository.