Zend ‘Page Tile’ view helper

I’ve created a ZF2 view helper PageTitle (extending ZendViewHelperAbstractHelper). As the name of the helper suggests , it is responsible for rendering the page title for each action view script.

So within each action view script (not layout) I would call :

 echo $this->pageTitle('My Page Title', 'some-icon-class-name');

This would render the required HTML output

 <div class="page-title">
   <h1><span class="some-icon-class-name"></span> My Page Title</h1>
 </div>

The plugin also contains another view helper (button) within it; its job is to render zero or more form button elements.

My trouble comes when I need to pass these page specific buttons/links. My current solution is to provide an array of ‘buttons’ as a third parameter.

$this->pageTitle('My Page Title', 'some-icon-class-name', array(
  'button label 1' => array(
    'attributes' => array(
      'class' => array('some-class-name', 'another-class'),
      'data-foo' => 'bar',
    ),
 )));

(Above is just an example of what I have tried to demonstrate the issue. This is in fact numerous buttons, each with several ‘attributes’ each)

I think the above approach is messy, certainly within the view. It also defeats the purpose of even having a view helper as I will need to provided this config again each time I need to reuse the page header (some pages may use other views as children).

Some solutions I have considered.

Create a page title service factory, per page

Each factory will create a new PageTitle plugin and inject the ‘button’ config into it. This is then registered ti the view plugin manager under a unique plugin name.

So, as an example, I would change the call in my view to:

echo $this->mySpecificPageTitle(); // no args as pre-constructed

The downside here is that I then need to create allot of factories (just so I can provide very slightly varied arguments).

Provided a ‘service’ name to the plugin

(this is similar to the navigation view helper) then then helper calls this service and it returns the required configuration.

For example:

echo $this->pageTitle('My Page Title', 'some-icon-class-name', 'MyButtonService');

So within the helper:

$buttonConfig = $serviceManager->get('MyButtonService');

This however again means that I would need to create a factory for each ‘MyButtonService’ I need.

I would migrate the plugin code out of the __invoke method and instead return an instance of your view helper object. From there provide methods for adding buttons which store the data temporarily in an internal data store (array). From there you then just need a render method which uses all the stored data to build the output. This way you don’t have an ever increase list of parameters and can provide easier to call methods which have a specific purpose.

Sample Usage:

echo $this->pageTitle()->setTitle('My Title')->setIcon('some-icon')->addButton('Test Btn')->addButton('Another Button', array('class' => 'some-class'))->render();

All that is required for this is an __invoke that simple does return $this and the methods above saving their inputs to internal class parameters. Your existing code can be dropped in the render method and slightly re-factored and you should be set.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật