PageTypeController Action
Permalink
Hi All,
I'm having difficulty with a PageTypeController.
I've created the following files :
/controllers/page_types/dash.php
/themes/theme/dash.php
My Controller looks like this :
class DashPageTypeController extends Controller {
public function view() {
$color = red;
$this->set('selectedColor', $color);
}
public function loggedinuser() {
Log::addEntry('Logged in user called');
}
}
I know that my controller is working correctly as the view() event is working and I can access the $selectedColor from my theme page.
However - on my page I'm trying to get the following form to post to the loggedinuser function :
<form method="post" action="<?php echo $this->action('loggedinuser');?>">
<input type="text" name="uName" value="" />
<input type="submit" value="Search" />
</form>
This doesn't work. $this->action('loggedinuser') returns "/" and nothing seems to hit the function in my controller.
Does anyone know what I'm doing wrong ?
Cheers,
Mike
I'm having difficulty with a PageTypeController.
I've created the following files :
/controllers/page_types/dash.php
/themes/theme/dash.php
My Controller looks like this :
class DashPageTypeController extends Controller {
public function view() {
$color = red;
$this->set('selectedColor', $color);
}
public function loggedinuser() {
Log::addEntry('Logged in user called');
}
}
I know that my controller is working correctly as the view() event is working and I can access the $selectedColor from my theme page.
However - on my page I'm trying to get the following form to post to the loggedinuser function :
<form method="post" action="<?php echo $this->action('loggedinuser');?>">
<input type="text" name="uName" value="" />
<input type="submit" value="Search" />
</form>
This doesn't work. $this->action('loggedinuser') returns "/" and nothing seems to hit the function in my controller.
Does anyone know what I'm doing wrong ?
Cheers,
Mike
Hi John,
No joy with that.
If I echo out $this->action('loggedinuser') all I get is "/"
This feels wrong as how would the controller know to call the function by posting to the root of the site ?
In this example there is only one page on my site (the homepage) that I'm working with.
Any ideas ?
No joy with that.
If I echo out $this->action('loggedinuser') all I get is "/"
This feels wrong as how would the controller know to call the function by posting to the root of the site ?
In this example there is only one page on my site (the homepage) that I'm working with.
Any ideas ?
Just spotted something. $this in the view does not refer to the controller object.
You could try
or
You could try
$controller->action(...);
or
$this->controller->action(...);
Hi John,
I've just tried both and sadly both result in :
Fatal error: Call to a member function action() on a non-object.
Am I trying to do something a bit weird by wanting to use a controller for a theme file ? It feels like it's the right thing to do from an MVC perspective. I want to put a bit more functionality into the theme and don't feel it quite warrants going down the single page route.
I've just tried both and sadly both result in :
Fatal error: Call to a member function action() on a non-object.
Am I trying to do something a bit weird by wanting to use a controller for a theme file ? It feels like it's the right thing to do from an MVC perspective. I want to put a bit more functionality into the theme and don't feel it quite warrants going down the single page route.
Hi biomaj,
I've been actually trying to do something similar and have encountered the same issues you had.
Out of interest what solution did you end up developing?
I've been actually trying to do something similar and have encountered the same issues you had.
Out of interest what solution did you end up developing?
Sorry figured it out. Forgot to add 'exit' to the end of the function.
Just for completeness I thought I'd post to say I didn't ever achieve a solution to this.
It's a real pity as controllers for theme pages would be really powerful however I reverted to single pages and the controllers are all working as they should.
If anyone ever puzzles out how to get controllers working for theme pages I'd love to know !
Cheers,
Mike
It's a real pity as controllers for theme pages would be really powerful however I reverted to single pages and the controllers are all working as they should.
If anyone ever puzzles out how to get controllers working for theme pages I'd love to know !
Cheers,
Mike
(I am only 50% on that, the need to prefix actions with 'action_' differs between block and page controllers, one of them requires the prefix and the other does not and I can never remember which)