我想在我的助手中访问TempData以获取flash消息(比如在ruby中)
我得到一个运行时错误
The name 'TempData' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
我的Flash.cshtml如下
@helper Show()
{
var message = "test message";
var className = "info";
if (TempData["info"] != null)
{
message = TempData["info"].ToString();
className = "info";
}
else if (TempData["warning"] != null)
{
message = TempData["warning"].ToString();
className = "warning";
}
else if (TempData["error"] != null)
{
message = TempData["error"].ToString();
className = "error";
}
<script>
$(document).ready(function () {
$('#flash').html('@HttpUtility.HtmlEncode(message)');
$('#flash').toggleClass('@className');
$('#flash').slideDown('slow');
$('#flash').click(function () { $('#flash').toggle('highlight') });
});
</script>
} …Run Code Online (Sandbox Code Playgroud) 从views/scripts /中的脚本调用views/helpers / file中的函数时,我收到此错误:
消息:在注册表中找不到名称为"SetBlnCompany"的插件; 使用的路径:My_View_Helper_:/ www/zendserver/htdocs/development/application/views/helpers/Zend_View_Helper_:Zend/View/Helper /:/ www/zendserver/htdocs/development/application/views/helpers /
bootstrap.php中
protected function _initConfig()
{
Zend_Registry::set('config', new Zend_Config($this->getOptions()));
date_default_timezone_set('America/Chicago');
}
protected function _initAutoload() {
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'My',
'basePath' => dirname(__FILE__),
));
return $autoloader;
}
Run Code Online (Sandbox Code Playgroud)
的application.ini
resources.view.helperPath.My_View_Helper = APPLICATION_PATH "/views/helpers"
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/助理/ DropdownHelper.php
class Zend_View_Helper_Dropdownhelper extends Zend_View_Helper_Abstract
{
public $blnCompany = false;
public function getBlnCompany() {
return $this->blnCompany;
}
public function setBlnCompany($blnCompany) {
$this->blnCompany = $blnCompany;
}
}
Run Code Online (Sandbox Code Playgroud)
脚本导致错误
<?php
$this->setBlnCompany(true);
//...etc...
?>
Run Code Online (Sandbox Code Playgroud)
编辑以添加更多背景信息到我的帖子.
理想情况下,我会使用这个"dropdown …
使用Url视图助手构建链接时,如果当前页面在url中包含参数,则Url视图助手生成的url也将包含参数.
例如在页面/ controller/action/param/value /中,代码如下:
<a href="<?php echo $this->url(array(
'controller' => 'index',
'action' => 'index'
)) ?>">Dashboard</a>
Run Code Online (Sandbox Code Playgroud)
将输出:
<a href="/index/index/param/value/">Dashboard</a>
Run Code Online (Sandbox Code Playgroud)
是否可以清除参数助手输出的url?
在我的App_code,我有一个叫做辅助函数FormatTelephone(string number)在Formatter.cshtml.我尝试在局部视图中访问它@Formatter.FormatTelephone(number).当我测试它时,它说
编译器错误消息:CS0103:当前上下文中不存在名称"Formatter"
可能的原因是什么?谢谢!
我是Zend Framework2的新手,我正在寻求以下情况的建议:
我正在使用ZF2 Breadcrumbs Helper在我的项目中创建面包棒和这段代码:
//breadcrumbs.phtml
echo $this->navigation('Navigation')
->breadcrumbs()
->setLinkLast(false) // link last page
->setMaxDepth(7) // stop at level 7
->setMinDepth(0) // start at level 0
->setSeparator(' »' . PHP_EOL); // separator with newline
Run Code Online (Sandbox Code Playgroud)
渲染时看起来像这样:
主页»Lorem Ipsum1»Lorem Ipsum2»当前面包屑
探索源代码:
<div id="breadcrumbs">
<a href="/">Home</a>
»
<a href="/">Lorem Ipsum1</a>
»
<a href="/">Lorem Ipsum2</a>
» Current Crumb
</div>
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是:使用Breadcrumb Helper如何获得以下源代码,以便能够按照我想要的方式设置Breadcrumbs样式?
<div id="breadcrumbs">
<ul id="breadcrumbs">
<li><a href="">Home</a></li>
<li><a href="">Lorem Ipsum1</a></li>
<li><a href="">Lorem Ipsum2</a></li>
<li><a href="" class="current">Current Crumb</a></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud) 我写了一些我想在几个模块中使用的部分.我认为最好的方法是将它放入我的自定义库中.
但不幸的是,我无法找到一种方法来包含这个部分而不使用非常丑陋的路径,如:
echo $this->partial('/../../../../vendor/myvendor/library/MyVendor/View/Views/FormPartial.phtml'
, array(...));
Run Code Online (Sandbox Code Playgroud)
有什么想法如何从我的视图链接到我的供应商目录?
我想在我的视图中构建一个链接,指向与放置它的那个页面相同的页面.我希望能够给出一个参数.
例如,我想改变语言.我有一条路线
domain.com/{lang}/xyz
Run Code Online (Sandbox Code Playgroud)
在我看来,我想做点什么
<a href="{{ URL::action(this, ['lang' => 'en']) }}">EN</a>
Run Code Online (Sandbox Code Playgroud)
所以我可以轻松地重新加载页面,但只需更改"lang"参数.
希望它可以理解.请尽力帮助我.
(另一个问题:是否没有资源,例如Laravel中所有视图助手的列表?我在哪里知道哪些视图助手可用?)
我有几个块助手,这是我正在做的一个简单的例子:
def wrap_foo foo, &block
data = capture(&block)
content = "
<div class=\"foo\" id=\"#{foo}\">
#{data}
</div>"
concat( content )
end
Run Code Online (Sandbox Code Playgroud)
我只是尝试erubis,它给了我以下错误:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
Run Code Online (Sandbox Code Playgroud)
删除调用以concat删除错误但最终导致我的包装器没有被渲染
使用:
布尔属性,在html 5草案规范中定义:
http://dev.w3.org/html5/spec/Overview.html#boolean-attributes
元素上存在布尔属性表示真值,缺少属性表示false值.
如果该属性存在,则其值必须是空字符串,或者是属性的规范名称的ASCII不区分大小写匹配的值,没有前导或尾随空格.
我的页面使用的是html5 DTD.我试图在我自己的帮助器中使用content_tag视图助手,但是遇到了将布尔属性传递给它的问题.
具体来说这是我的帮手:
def itemscope(type, options = {}, &block)
content_tag(
:div, {
:itemscope => true,
:itemtype => data_definition_url(type)
}.merge(options),
true,
&block
)
end
def data_definition_url(type)
"http://data-vocabulary.org/#{type}"
end
Run Code Online (Sandbox Code Playgroud)
在我看来,假设我称之为(我正在使用haml):
= itemscope("Organization") do
%h1 Here's some content
Run Code Online (Sandbox Code Playgroud)
这是我希望它呈现的内容:
<div itemscope itemtype='http://data-vocabulary.org/Organization'>
<h1>Here's some content</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
但这就是我实际得到的:
<div itemscope='true' itemtype='http://data-vocabulary.org/Organization'>
<h1>Here's some content</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
根据w3规范,这是无效标记.布尔属性的合法值是属性本身的名称,或者根本没有值.
这很烦人,因为我可以更改:itemscope => trueto :checked => true,它将正确地呈现checked='checked'div元素的属性列表中的属性.
我宁愿它呈现的只是最小化版本itemscope...但我不知道怎么做是使用content_tag选项.我可以很容易地发送:itemscope =>'itemscope',但很难说谷歌是否会正确解释它,因为他们的所有示例和规范都显示了最小化的版本.请参阅此处:http: //www.google.com/support/webmasters/bin/answer.py?answer = 146861,了解这些属性是什么以及我使用它们的原因(微数据格式) …
我正在尝试访问视图助手中的服务定位器,以便我可以访问我的配置.我正在使用此视图助手进行递归功能,因此我不知道在哪里声明服务定位器.
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
use CatMgt\Model\CategoryTable as RecursiveTable;
class CategoryRecursiveViewHelper extends AbstractHelper
{
protected $table;
public function __construct(RecursiveTable $rec)
{
$this->table = $rec;
}
public function __invoke($project_id, $id, $user_themes_forbidden, $level, $d, $role_level)
{
$config = $serviceLocator->getServiceLocator()->get('config');
//So i can access $config['templates']
$this->__invoke($val->project_id, $id, $user_themes_forbidden, $level, $d, $role_level);
}
}
Run Code Online (Sandbox Code Playgroud)
我试过解决方案给这里链接
但它没有帮助,这样做是否可行?
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
use CatMgt\Model\CategoryTable as RecursiveTable;
use Zend\View\HelperPluginManager as ServiceManager;
class CategoryRecursiveViewHelper extends AbstractHelper
{
protected $table;
protected $serviceManager;
public function __construct(RecursiveTable $rec, ServiceManager $serviceManager) …Run Code Online (Sandbox Code Playgroud) view-helpers ×10
php ×5
html-helper ×2
view ×2
asp.net-mvc ×1
breadcrumbs ×1
c# ×1
erubis ×1
html5 ×1
laravel ×1
razor ×1
zend-view ×1