Passing a Task to Standard Pages

Permalink
I am wondering if it is possible to pass a task to a regular page in the same way you would pass a task to a single page and if so, how to do that in 5.4.

For example, with single pages, you can do /path/to/page/-/taskToRun and rather than running the view function in the controller, it runs the taskToRun function.

Even more I guess than specifically how to get the requested task (I think I've got that figured out), I'd like to know if it's even possible to pass a task to regular pages in 5.4. It seems like in pre-5.4, you can add /-/taskToRun to regular pages, and it just loads the pages like normal. However, with 5.4, I get the 404 page when trying to do that. I know the method for passing tasks has changed (no dash needed), but I of course still get a 404 when passing it without the dash (I assume cause it's looking for a page named /path/to/page/taskToRun).

Anyways...anyone have any thoughts on this?

jgarcia
 
mose replied on at Permalink Reply
mose
Is taskToRun a public function in the controller for the page?
jgarcia replied on at Permalink Reply
jgarcia
Kind of. I am wanting to pass it to a block controller though. I just want to be able to do it using pretty URL's rather than have to use a URL parameter in the form of ?var=whatever
mose replied on at Permalink Reply
mose
I believe it will go to the page controller. There could be tons of blocks on a page. They could even all be the same block. I don't know how you would single out a specific block on a page and pass it something directly to call one of the public functions in its controller. I would think that the solution would be to pass the information to the page and have the block check the page's information. I would be curious, though, if there is a solution with pretty URL's.
jgarcia replied on at Permalink Reply
jgarcia
Yeah, I've thought about those things. I kind of imagine that it doesn't automatically cause a particular class to run in a block controller, but as long as I can get the URL to look "pretty" I'm fine with parsing it myself to run a particular task. It just doesn't seem like there's a way to do it in 5.4. Even when I set ENABLELEGACYCONTROLLER_URLS to true in my site.php, I still am unable to do /page/-/task. It just give me a 404. This is with pretty URL's turned on.

So really, I guess the question is, is it even possible to add additional information in the URL in 5.4.
mose replied on at Permalink Reply
mose
I assume you've read the section about page types and how to call a controller method.

http://www.concrete5.org/documentation/developers/pages/mvc-approac...

Have you written the controller for the page type you are using? If not, that is likely why it is not working. There's nothing to handle the task.
ScottC replied on at Permalink Reply
ScottC
yeah beta had it good for a while here.

basically to accomplish this you would need to check to see if you are in the dashboard section(the reason for this not being as wild as it once was) and then using page_type controllers and some switching based on the request task and request task parameters.

here's some code as to what i had working before it changed, one could probably get it going by overriding the controller finding that by searching the project for $do404 i think

<?php 
class BlogController extends Controller{
    protected $type;
    protected $year;
    protected $month;
    protected $day;
    protected $blog_post_requested;
    protected $blog_requested; //maybe later
    protected $rtask;
    protected $metaSet;
function on_start(){
$html = Loader::helper('html');
$this->addHeaderItem($html->javascript('tiny_mce/tiny_mce.js'));
$req = Request::get();
$this->set('request',$req);
jgarcia replied on at Permalink Reply
jgarcia
Thanks for the responses guys. I'm still having a little trouble on one issue though: I cannot pass a task to a page in 5.4. I have set ENABLE_LEGACY_CONTROLLER_URLS to true in config/site.php, but I still get a 404 when I go to my/page/-/myTask. This seems to work just fine in 5.3. Any thoughts?
ScottC replied on at Permalink Reply
ScottC
i dunno, least path of resistance is to imo just search for action=""

and do a echo $this->action('method_name');
or $this->url('pathTopage','method_name');

for the form action stuff.

the method name absolutely has to exist in the controller as defined via myTask in your example and accept your parameters via reflection.

:-/