Using methode of the block's controller in a tool file
Permalink
Hi all,
I'm writing a package includes blocks. The block file consists one tool file and two elements. The block's view.php loads the two element files. The first is a kind of search form, and the second one displays the filtered results.
The requested objects loaded by the block's controller file (controller.php). It is working fine when no filter selected, because the process in this case:
view.php --> loading element file, than
controller --> pass objects to the element file.
But after filtering, the process should be:
element1 file --> pass the form elements to the view.php controller then ajax should be load the element2 file (with filtered objects) using tool file.
This isn't work.
I can load the tool file in jQuery, and tool file loads the element2 file, but I can't refer to the block's controller file from the tool script, so the element2 file can't receive the requested objects.
This is the code in the tool file:
As I see the problem is that the Loader::controller('whatever') didn't find the block's controller.
How can I reference the block's controller file?
Many thanks!
I'm writing a package includes blocks. The block file consists one tool file and two elements. The block's view.php loads the two element files. The first is a kind of search form, and the second one displays the filtered results.
The requested objects loaded by the block's controller file (controller.php). It is working fine when no filter selected, because the process in this case:
view.php --> loading element file, than
controller --> pass objects to the element file.
But after filtering, the process should be:
element1 file --> pass the form elements to the view.php controller then ajax should be load the element2 file (with filtered objects) using tool file.
This isn't work.
I can load the tool file in jQuery, and tool file loads the element2 file, but I can't refer to the block's controller file from the tool script, so the element2 file can't receive the requested objects.
This is the code in the tool file:
$block_controller = Loader::controller('rpn_ecommerce'); $product_list = $block_controller -> get(); $products = $product_list -> requested_products(); Loader::element('product_list_block_search_results', array('product_list' => $product_list , 'products' => $products),'rpn_ecommerce/blocks/rpn_products' );
As I see the problem is that the Loader::controller('whatever') didn't find the block's controller.
How can I reference the block's controller file?
Many thanks!
![Remo](/files/avatars/26.jpg)
Wouldn't it be cleaner if you move that functionality into a "library"?
When you load the block controller, it is an instance of the block type, not the specific instance of the block.
If you are using the block data, you need that specific block instance.
You don't say if you are doing this from add/edit or view. When you do load a specific block instance there are complications in add/edit because the block instance may not yet exist during add.
There are some examples of this in my combined howto and addon AJAX Lessons. Its getting a little dated, but still works and the principles of what works where are still valid.
As Remo suggest, moving the common processing to a package library would be a cleaner solution. If there is common data, you could put that in a model called from both.
EDIT: What you are doing may also have issues with the 5.6.1 cache.
If you are using the block data, you need that specific block instance.
You don't say if you are doing this from add/edit or view. When you do load a specific block instance there are complications in add/edit because the block instance may not yet exist during add.
There are some examples of this in my combined howto and addon AJAX Lessons. Its getting a little dated, but still works and the principles of what works where are still valid.
As Remo suggest, moving the common processing to a package library would be a cleaner solution. If there is common data, you could put that in a model called from both.
EDIT: What you are doing may also have issues with the 5.6.1 cache.
Thanks the answer both of you. I'm using models for the orders, products, users. There are functions as well (add_new, delete, modify etc...).
Right now I need to make a so called search function without refresh the page in a block. So I like to submit the form via ajax, do the filtering, and load back the results into a div.
I'd like to keep this functionality in the block. This is the reason why I don't want to use the package level element, library, controller ...
I modified the process, and now the form send the filtering values to the block controller then in the controller.php the action_filtering() method processing the form.
The result loading is not work properly yet, but maybe this will the right way.
What do you think about this? Is it a clean solution?
Right now I need to make a so called search function without refresh the page in a block. So I like to submit the form via ajax, do the filtering, and load back the results into a div.
I'd like to keep this functionality in the block. This is the reason why I don't want to use the package level element, library, controller ...
I modified the process, and now the form send the filtering values to the block controller
$this->action("filtering")
public function action_filtering(){; $product_list = $this->get_filtered_result_list(); // I catch the posted elements in this function $products = $product_list -> get(); Loader::element('product_list_block_search_results', array('product_list' => $product_list , 'products' => $products),'rpn_ecommerce/blocks/rpn_products' ); exit; }
The result loading is not work properly yet, but maybe this will the right way.
What do you think about this? Is it a clean solution?
Sorry, I can't remove the "best answer" flag. I click there in mistake.
Don't get me wrong! I am grateful to for the answer, but it not solved the issue :).
Don't get me wrong! I am grateful to for the answer, but it not solved the issue :).