Call Block method directly.
Permalink
Hey everyone,
So here's what I got. I have a block (yes it's enabled) and within the controller I have this:
Now, how do I call that from a URL? I need to send in an ID and then have it do the work and spit back "Test! 1" if I send it the param of 1. How do I do that?
I tried:
mydomain.com/Mysuperblock/view_layout/1 and that's not it.
Also the block is in:
/blocks/mysuperblock
It installed fine so I know there's no issues there, just need to learn the finer points of how the dispatcher works.
thanks!
So here's what I got. I have a block (yes it's enabled) and within the controller I have this:
Now, how do I call that from a URL? I need to send in an ID and then have it do the work and spit back "Test! 1" if I send it the param of 1. How do I do that?
I tried:
mydomain.com/Mysuperblock/view_layout/1 and that's not it.
Also the block is in:
/blocks/mysuperblock
It installed fine so I know there's no issues there, just need to learn the finer points of how the dispatcher works.
thanks!
Hmm, still not working I went to:
http://mydomain.com/index.php/mysuperblock/dosomething...
What am I missing?
http://mydomain.com/index.php/mysuperblock/dosomething...
<?php defined('C5_EXECUTE') or die("Access Denied."); class MysuperblockBlockController extends BlockController { var $pobj; protected $btTable = 'btMysuperblock'; protected $btInterfaceWidth = "600"; protected $btInterfaceHeight = "465"; public function getBlockTypeDescription() { return t("My super block for doing super things"); } public function getBlockTypeName() { return t("Super Block"); } public function __construct($obj = null) { parent::__construct($obj);
Viewing 15 lines of 30 lines. View entire code block.
What am I missing?
$this->action('dosomething')
How can I call that directly from the URL? Are you saying I have to load a different page to then have it call the controller?
nah honestly chad this is a bit screwy, your block methods you want to call via $this->action need the action_ appended to the method name, and still for me it has been a bit hit and miss. Here's one that worked for me, (and it did take an hour to track down, luckily no sheets of drywall were ruined in the process
That's it.
<form method="post" id="save-map-center" action="<?php echo $this->action('update_map_center'); ?>"> //in view //controller method public function action_update_map_center(){}
That's it.
Thanks Scott,
I guess I wanted a similar CakePHP way of doing this. Something where you could just do: /controller/method/param1/2/3/4/5/6 ect. I just don't think that's possible with the dispatcher that's shipped right now.
Then within your controller you have:
I've opted to go with a different way all together and hopefully will be able to move my application around to use the block.
More like I should say I'm still learning the in's and out's of what makes this framework tick.
I guess I wanted a similar CakePHP way of doing this. Something where you could just do: /controller/method/param1/2/3/4/5/6 ect. I just don't think that's possible with the dispatcher that's shipped right now.
Then within your controller you have:
public function mymethod($p1,$p2,$p3){ }
I've opted to go with a different way all together and hopefully will be able to move my application around to use the block.
More like I should say I'm still learning the in's and out's of what makes this framework tick.
http://mydomain.com/index.php/mysuperblock/save...
This is not very documented on the site, but try to look into the blocks that comes with concrete5 under the directories concrete/blocks, there you will find the best help actually. :)