I have a populated list, and I want to utilize a custom function to shorten row names which are too long to display. The rows from the list are generated from an object passed from the action/controller. How/where do I include my custom function for to achieve the above mentioned purpose?
Any advice appreciated.
I guess you need helpers:
http://www.symfony-project.org/book/1_2/07-Inside-the-View-Layer
Use this function in _toString method of the object to display its name.
Related
I'm trying to create a service where a user needs to operate over a data and can manipulate it in numerous ways, so I'm not aware of the manipulations at the time of compiling of my program. One way to achieve this is to give the user a function with data as param. Which landed me in the following direction.
Dynamically create a function
Dynamically linking a function after compiling it separately.
I'm open to suggestions. If you have other ways to achieve the end goal.
If you don't like this as an answer I can move to the comment section, but it's rather long that's why I put here in the answer section.
Dynamically Dispatched Method: The only way to have dynamically dispatched methods is through an interface. Methods on a struct or any other concrete type are always resolved statically.
Closure: Go supports anonymous functions, which can form closures. Anonymous functions are useful when you want to define a function inline without having to name it.
Dyncamically call method on Interface:
Please let me know if that helps you to understand the concept in golang.
Following the tutorial how to create a joomla 2.5 component I'm stucked to pass arguments from view.html.php to my model.
$items = $this->get('TableData');
and my TableData model would expect to get the following arguments
public function getTableData($table, $index_column, $columns) {}
You can not do this using the view's get method. Instead you would have to grab the model into the view and call the function directly in the view:
$model = $this->getModel();
$items = $model->getTableData($table, $index_column, $columns);
Alternately, you could create different entry points in the model that would be able to figure these input options either from state information or preset. Many would argue that this would lead to a better application design, since using my code above is putting what should be model logic in the view.
This is just an addon to David's answer.
Because most of the data usually comes from POST / GET methods, depending on your application, you may want to look at how loadFormData() from loadFormData JModelForm or populateState gets overridden in specific Joomla components.
Basically the state of model is set directly from POST data, using JInput.
Also, although it's not a rule or something, 3 parameters is a maximum I would pass to a method. For flexibility I would rather pass an array with can be later extended without changing the method signature.
Is it possible to call directly from a model method from another model of the same component?
Is there any default Joomla option to call in such a way.
Yes You can
It will not break MVC architecture,
You can check like this
if(!class_exists('VirtueMartModelUser')) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'user.php');
$usermodel = VmModel::getModel('user');
$currentVMuser = $usermodel->getUser();
First you should include the model file in the required model then create the object.
then call like above.
This example is Virtue-mart using method
According to the my knowledge NO. Otherwise it will break the MVC architecture.
What you can do is
Replicate the function you want to use.
Make the call from the controller to the both method.
My Advice is to you is even if you figure out a way to do it, Don't do it. It will mess up your whole architecture.
If you have any issues please ask.
I was wondering if its possible to have one or more functions within a funciton like in jQuery? I need to add an inline function that performs a simple task but I really don't need it anywhere except the function I'm calling it from.
Not possible, but you could create a class with the functions you need.
Is there any event like OnValidate in LINQ where I can add my business validation rules so that they are ALWAYS called whenever I use Add() or Update()?
If not: What do you suggest to do? I could add a partial class and wrap the Add/Update methods with own ones but then one could still use the original ones ignoring any business validation rules.
Thanks in advance and keep up the excellent work with subsonic!
I haven't used much of the LINQ parts of SubSonic3, but the ActiveRecord.tt file allows you to customize the code so you could insert an validate method. We talked about it over at How to intersept the save method on ActiveRecord?
Can you modify the tt file to add in your validation call before saving the record?