I have a View that can vary significantly, depending on the 'mode' a particular user has chosen.
I thought I would extract the different behavior into two different Helpers, and then have code like this in the Controller:
class MyController < ApplicationController
case mode
when 'mode1'
helper "mode1"
when 'mode2'
helper "mode2"
e...
When using the Url view helper to build links, if the current page has parameters in the url, the url generated by the Url view helper will contains parameters as well.
For instance in the page /controller/action/param/value/ the following code:
<a href="<?php echo $this->url(array(
'controller' => 'index',
'action' => 'index'
...
Hi,
I'm using Zend Framework 1.8. I have a problem with headMeta() duplicating my meta keywords.
In my layout.phtml, I have
<?php echo $this->headMeta(); ?>
I have a Custom Controller_Plugin_ViewSetup (extending Zend_Controller_Plugin_Abstract) that has the following code in it, in the dispatchLoopStartup() function:
$view->h...
My question needs a bit of setup, so please bear with me:
I became a convert to using View Helpers for getting data from a model rather than sprinkling it all over the controllers (hat tip to Eric Clemmons). It's much more reusable and flexible there. I just love it!
What I usually do, is lay out the template in the index.phtml, and th...
I have a couple of block helpers, here's a simple example of what I'm doing:
def wrap_foo foo, &block
data = capture(&block)
content = "
<div class=\"foo\" id=\"#{foo}\">
#{data}
</div>"
concat( content )
end
I'm just trying out erubis and it's giving me the following error:
You have a nil object when...
Hi,
I begin with ZF (1.9.7), and I want to use View Helpers from a library shared between all my projects. But I can't find how to add it directory to the helpers path. My herpers works fines when I put them in application's helpers path.
Here is the error, where I find the path to ZF helpers, and path to the applications ones.
objec...
Hi all,
I have a controller that is called with AJAX (sends JSON data), so I don't use a view.
I need to use a personnal view helper to format my data, but in my controller.
Is that possible ?
Or maybe I am doing it wrong (maybe I should have a view, but how with JSON) ?
...
I want to access the value of a specific variable (in the url) in my view helper. How can I do this?
I'm able to get my controller name with: Zend_Controller_Front::getInstance()->getRequest()->getControllerName(); , but I have no idea for the variable ...
Thanks in advance!
...
I'm using Zend_View_Helper_HeadScript to add JavaScript code inside the <head> tag.
$view->headScript()->appendScript($javascript);
$view->headScript()->appendScript($javascript2);
This works fine, except that my code is full of <script> tags (one for each appendScript call). How to add $javascript2 to the same <script> tag? I just wa...
I tried to create a view helper which takes a DateTime object and returns a string. If the DateTime object equals a new DateTime(0), the function returns an empty string. Otherwise return a formatted DateTime string. This works so far.
public static string DateTimeOrEmpty(this HtmlHelper htmlHelper, DateTime dateTime)
{
return date...
Hello
I'm fairly new to Zend Framework and MVC in general so I'm looking for some advice. We have a base controller class in which we have some methods to obtain some user information, account configurations, etc.
So I'm using some of those methods to write out code in various controllers actions, but now I want to avoid duplicating th...
Hi,
I am putting together a modular application in Zend Framework and am struggling to get module specific View Helpers to load.
My directory structure is like this...
application
---configs
---controllers
---forms
---layouts
---models
---modules
------user
---------controllers
---------forms
---------modules
---...
Hi,
I have this route setup in one of my bootstrap files...
$route = new Zend_Controller_Router_Route_Regex(
'user/(\d+)',
array(
'module' => 'user',
'controller' => 'view',
'action' => 'index'
),
array(
1 => 'id'
),
'user/%d'
);
$router->addRoute('user', $rou...
I am trying to write a view helper but it's not returning the correct thing.
def table_layout_for(object, *attrs)
content_tag :table, :class => "layout" do
for a in attrs
content_tag :th do
object.class.human_attribute_name(a)
end
content_tag :td do
object.send(a) if object.respond_to?(a)
en...
Hey guys,
I am using Zend Framework 1.6 hence I'm not utilizing Zend_Application.
I have a simple, normal View Helper (extending Zend_View_Helper_Abstract). It works perfectly fine as long as I add it to the view in my action controller. But I want to be able to use it in every view in every module. I figured it should be easy to jus...
In Rails 3 I use the following helper in order to get a even-odd-coloured table:
def bicolor_table(collection, classes = [], &block)
string = ""
even = 0
for item in collection
string << content_tag(:tr, :class => (((even % 2 == 0) ? "even " : "odd ") + classes.join(" "))) do
yield(item)
end
even = 1 - even
e...
Hi!
I'd like to have a URL like this:
/payroll/region/1
and I'd like it to map to the Tasks Controller's payroll_list function. I'd also like to use REST. What's the best way to do this?
Many thanks!
...
If a project is running Rails 2.2.2, and it uses controller.helper and the helper is not defined, then how can it be solved? (this is for the Facebooker2 gem http://github.com/mmangino/facebooker2)
details:
error shown:
=> Rails 2.2.2 application starting on http://0.0.0.0:3000
Exiting
/Library/
Ruby/
Gems/1.8/gems/facebooker2-...
I've a view helper method which generates a url by looking at request.domain and request.port_string.
module ApplicationHelper
def root_with_subdomain(subdomain)
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
end
I would like to...