你好,
我正在尝试在轨道上创建一个ruby的网站,我正在建立一个帮助,以显示5个星级的评级.到目前为止我有:
def stars(score)
html = ""
if score >= 1
image_tag "star.png", :alt => 'one'
else
html << ""
end
if score >= 2
html << (image_tag "star.png", :alt => 'one')
else
html << ""
end
if score >= 3
html << (image_tag "star.png", :alt => 'one')
else
html << ""
end
if score >= 4
html << (image_tag "star.png", :alt => 'one')
else
html << ""
end
if score >= 5
html << (image_tag "star.png", :alt => 'one') …Run Code Online (Sandbox Code Playgroud) 在控制器中,我可以像这样调用viewRenderer帮助器:
$this->_helper->viewRenderer->setNoRender(true);
Run Code Online (Sandbox Code Playgroud)
如何在控制器动作助手中调用viewRenderer?假设我有一个Controller动作助手:
class Zend_Controller_Action_Helper_Ajaxrequest extends Zend_Controller_Action_Helper_Abstract{
public function test(){
//what I should do here
}
}
Run Code Online (Sandbox Code Playgroud) if (annual <= lowincome && aChar == 'S')
owe = annual * .25;
else if ( annual > lowincome || annual < medincome && aChar == 'S')
owe = annual * .50;
else if (annual > medincome && Char == 'S')
owe = annual * .75;
else if (aChar == 'M' && annual <= lowincome)
owe = annual *.24;
else if(annual > low income || annual < medincome && aChar == 'M')
owe = annual * .49;
else if(annual > …Run Code Online (Sandbox Code Playgroud) 我的点子:
我的控制器代码如下(application/controllers/registration.php):
callback_min_length[2] 是我尝试将值发送到辅助函数
// 加载助手 $this->load->helper(array('form', 'url', 'error'));
// Load library
$this->load->library('form_validation');
// Set form rules
$rules = array(
array(
'field' => 'firstName',
'label' => 'firstName',
'rules' => 'callback_min_length[2]|trim'
)
);
$this->form_validation->set_rules($rules);
// Set custom error messages
if ($this->form_validation->run() == FALSE)
{
$this->load->view('header');
$this->load->view('view_registration');
$this->load->view('footer');
}
else
{
$this->load->view('header');
$this->load->view('view_registration');
$this->load->view('footer');
}
Run Code Online (Sandbox Code Playgroud)我的自定义助手代码如下(application/helpers/error_helper.php):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function min_length($str, $val) {
// Load CI instance to be able to load …Run Code Online (Sandbox Code Playgroud) 我想创造eq帮手.它已经存在于ember-truth-helpers插件中,但我只需要eq帮助,所以我决定自己在我的插件中创建它.
我assets/javascripts/discourse/helpers/eq.js.es6在我的插件中创建了包含以下内容的文件:
import { registerHelper } from 'discourse/lib/helpers';
registerHelper('eq', function(params) {
return params[0] === params[1];
});
Run Code Online (Sandbox Code Playgroud)
并以这种方式在模板中使用它:
{{#if (eq param1 param2)}} <h1>hello</h1> {{/if}}
Run Code Online (Sandbox Code Playgroud)
但是eq没有定义.
创建助手的正确方法是什么?
我们如何在Symfony1.4中使用其他应用程序模块的帮助程序?
我想重用相同的帮助程序类而不重复内容.
我想要一个小的字符串转换器(翻译)辅助方法.例如,我想从控制器传递我的字符串并获得结果,所以我不想重复将相同的辅助函数写入控制器.
所以我可以使用它像:
$oldStr = '12 May?s 2014'; // which means 12 May in English
$englishStr = custom_date_translator($oldStr);
Run Code Online (Sandbox Code Playgroud)
并且它在辅助方法上做了它.
服务提供商是否为此目的?学习正确的方法是很好的.
例如help(list),如果您编写,您将获得有关列表对象的帮助.如果你写help(+),你会得到SyntaxError: invalid syntax
为什么这?
正在网上寻找计算增值税的方法,但似乎找不到。
decimal subTotal = FinalInvoice.Hold_Back_Value;
decimal VAT = //calculate vat at 20% for subtotal using helper method
decimal TOTAL = subtotal + VAT;
Run Code Online (Sandbox Code Playgroud) helper ×9
action ×1
c# ×1
controller ×1
discourse ×1
ember.js ×1
image ×1
java ×1
laravel ×1
laravel-5.4 ×1
php ×1
python ×1
symfony-1.4 ×1
viewhelper ×1