Where do I put controller code in a theme (for redirecting to another page)?

Permalink
For a page type in the theme I created (contact.php) I need to have a page of this type redirect to one of its children, based upon certain attribute values. I was writing this bit of code in the contact.php view itself, but came to a hold when I found that I can't redirect to another page from the view.

It makes more sense to do this in controller code anyway, but I'm having a hard time finding where to "put controller code" in a theme. What is the best way to do this?

plindelauf
 
mhawke replied on at Permalink Reply
mhawke
[root]/controllers/page_types/your_page_type_handle.php

This might help get you going:

http://www.concrete5.org/community/forums/customizing_c5/page-type-...
plindelauf replied on at Permalink Reply
plindelauf
Thanks Michael. I did find that post already, but it hasn't gotten me there quite yet.

So in my theme folder, I created controllers/page_types/contact.php with the following test content:

<?php  defined('C5_EXECUTE') or die(_("Access Denied."));
class ContactPageTypeController extends Controller {
  function view() {
    $this->redirect("/");
  }
}


But that code does not get hit (or executed), since there is no redirect happening. Maybe I'm using the wrong function to do this in?
mhawke replied on at Permalink Best Answer Reply
mhawke
"So in my theme folder..." is incorrect. [root] is not your theme folder. [root] is the base folder where concrete5 is installed. Perhaps I should have referred to the location for the controller as [public_html]/controllers/page_types/contact.php
plindelauf replied on at Permalink Reply
plindelauf
Darn, you're right Michael. That was exactly the problem. Now that I have put it in my [concrete5 root]/controllers/page_types, it works.

Thanks for helping me out!
mhawke replied on at Permalink Reply
mhawke
Happy to help.