Calling Controller Method from URL in a Single Page

Permalink
Ok, I have never got this to work so apparently I'm not understanding "how" this is supposed to work.

According to the documentation in order to call a controller method from within a single page I should be able to do either:

<a href=<?php echo $this->url('mypage','method', 'param')?></a>


or

<a href=<?php echo $this->action('mypage','method', 'param')?></a>


However all I ever get is the page redirecting to me a "page not found" as it attempts to load the page and my controller method never gets called.

<a href="http://www.mysite.com/mypage/method/param"></a>


Umm.. eh? What am I missing here?

Any help is appreciated.

 
johndorsay replied on at Permalink Reply
johndorsay
Here is the exact code that works for me.

<a href="<?php echo $this->url('/dashboard/clients/reservation', 'add', $client['custID'])?>">Add new reservation</a>


By default, you should make sure that the controller and the single page are named the same and reside in the same directory structure:
controllers/dashboard/clients/reservation
single_pages/dashboard/clients/reservation
sid replied on at Permalink Reply
Nope. Still nothing. I know I have the controller setup correctly because i'm calling it within the same page by way of instantiating its class object. However, whenever I attempt to link to the controller I get Page Not Found as it directs to a path that obviously doesn't exist.

For instance; using your example I would get this in my address bar:

http://www.mysite.com/dashboard/clients/reservation/add/1...

instead of just executing the function and returning to the same page I'm on.
ScottC replied on at Permalink Reply
ScottC
i'm not following you.

$this->action('method'); will call the controller's method name of method.

You should always start with a function on_start(){print "I am running";} //so you know your controller is being loaded


Then go from there.
sid replied on at Permalink Reply
Well thats the thing that's driving me batty. I know the controller is getting loaded because I have code within my single page that calls other methods within it. Meaning I have no problem accessing the controller by way of :

$m = new MyController();
$mData = $m->doSomethingMethod(param);
echo $mData;  // yay i have data here!


The above works all day long.

Now, if I want to execute that method via href from within the same page I'd expect to be able to do this...

<a href="<?php echo $this->action('doSomethingMethod', 'param')?> ">yadda</a>


But no dice. What happens is I get directed to

http://www.mysite.com/doSomethingMethod/param/...

with a Page Not Found message and no code execution. As if concrete5 is physically looking for a path of that nature and can't find it.

I also have this within my controller class
public function on_start() {
      print "I am running";
   }


When I load the single page I do "not" get the print message????

I'm probably just not understanding how this method should work. arg!
jordanlev replied on at Permalink Reply
jordanlev
Random thought here: does your theme have a view.php file?
sid replied on at Permalink Reply
Yep it does.
ScottC replied on at Permalink Reply
ScottC
ah well in that case do a switch on either the $this->post or $_GET var in the on_start method), or a sequence of ifs(the latter is more typing)

sorry i get really dense when i type :)

so say if you have a action var you need to actually have a method that accepts the url var, otherwise you need to default to $_GET or $_REQUEST or $this->post('your_named_post_thing');

and act on that.

so the first thing after the absolute path say siteurl/blog/posts/2010 (sorry)

blog has to be a singlepage, posts has to be a method in that singlepage's controller, and it'd have to accept 2010 as a method arg, or

blog/posts/ posts is a singlepage, 2010 has to be a method name, sucks, no wildcarding as far as i know.

That is probably your issue. Let me know. Method has to exist, otherwise you get a $do404.
sid replied on at Permalink Reply
Ok guys I think I've narrowed down the issue that I'm having and I believe it has nothing to do with the way the methods get called via URL. I'm using some additional rewrite rules via htaccess and I think the addition of these rules are tripping up the page load and giving me the Page Not Found error. Rather than spend anymore time on this issue I ended up implementing an Ajax query call.

Thanks to everyone for trying to help me out with this. I hope I didn't waste too much of your guys time.