View Helper, Partial View or Something Else - zend-framework

I am new to Zend Framework and I have a question about something I am trying to do.
The main content of most pages of the application that I am working on will consist of 1 or more div elements that need to be styled the same.
Here is an example of the HTML that I want to generate:
<div id='admin-locations' class='panel'>
<header class="panel-header">
<h2>Locations</h2>
</header>
<div class='panel-content'>
<div id='locations-table' class='google-vis-table'></div>
<form id='locations'>
...
</form>
</div>
</div>
I know I can easily do this by pushing the form to my view script in my controller then adding this code to my controller.
<div id='admin-locations' class='panel'>
<header class="panel-header">
<h2>Locations</h2>
</header>
<div class='panel-content'>
<div id='locations-table' class="google_vis_table"></div>
<?php
echo $this->formLocations;
?>
</div>
</div>
But that is not DRY.
The example I used here has a Google Visualization Table and a Zend Form in it's content. Sometimes the panels will need to contain a form. Sometimes they won't, so I don't think form decorators are the way to go. So basically, the id of the panel, the panel header text and the content of div class='panel-content' need to be dynamic. Everything else will stay the same from panel to panel.
What is my best option here?

You might want to consider using partials:
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.partial
For example, you could have an admin-locations.phtml partial that contains:
<div id='admin-locations' class='panel'>
<header class="panel-header">
<h2>Locations</h2>
</header>
<div class='panel-content'>
<div id='locations-table' class="google_vis_table"></div>
<?php echo $this->form; ?>
</div>
</div>
Now you can simply repeatedly call the partial within a view, with or without supplying a form:
...
echo $this->partial('admin-locations.phtml');
echo $this->partial('admin-locations.phtml', array('form' => $this->yourForm);
echo $this->partial('admin-locations.phtml');
...
Hope this helps.

Related

add new attribute on html through xslt

Let's say I have a ditamap file.I have published into html5.after published let's say my html file look like
<body id="SampleTopic">
<h1 class="title topictitle1" id="ariaid-title1">Sample topic</h1>
<div class="body">
<p class="p">some<strong class="ph b">bold</strong><span class="ph special">text</span></p>
<div class="p">
<dl class="dl">
<dt class="dt dlterm">Term</dt>
<dd class="dd">Defination</dd>
</dl>
</div>
</div>
</article>
</body>
here in Html file, I want to add some new attribute on the body element like
<body id="SampleTopic" class="test">
so can anyone help me with how to solve this????
can I add some plugin, if yes how to write the code???
If all you need is the HTML #class attribute, then there's no need to develop a custom plug-in.
You can just specify a value for the #outputclass attribute on an element in your DITA source files, and the value will be passed to the HTML #class attribute in the output.

moving columns from left to right on homescreen

I'm working on magento and I want the categories that appear on left to be appeared on right side. I tried many tutorial, but didnt get it. Please help me on this. I'm new to magento. Thanks.
To add categories into the sidebar firstly go to:
app/design/frontend/default/YOURTHEME/template/catalog/navigation
and create a .phtml file, for example: left-nav.phtml
In left-nav.phtml put this:
<div class="category-nav">
<div class="block-content">
<p class="block-subtitle"><?php echo $this->__('Categories') ?></p>
<ul id="nav_category" class="nav_category">
<?php foreach ($this->getStoreCategories(true) as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
</div>
This just loops through all the enabled categories and outputs them into a list.
Now you need to link up the list so firstly go into /public_html/app/design/frontend/default/sbs/layout/page.xml
Find the bit for 2columns-left, or right if you want it to output on the right. In the layout you are using find:
<block type="core/text_list" name="left" as="left" translate="label">
Inside the block add a line of code like this:
<block type="catalog/navigation" name="category.listing" as="left_nav" before="-" template="catalog/navigation/left_nav.phtml" />
The before=”-“ just adds it before everything else.
Finally go into:
/public_html/app/design/frontend/default/YOURTHEME/template/page/2columns-left.phtml and add:
<?php echo $this->getChildHtml('left_nav') ?>
Note:
You will need to clean the cache for this to work.
I have written a more in depth answer on my website http://brideo.co.uk/moving-categories-to-left-collumn-magento/

How to handle Multiple DOM elements with iScroll (while using jQTouch)

I've my markups as
<div id="home" class="current">
<div class="header">iScroll</div>
<div class="wrapper">
<div id="scroller">
<ul id="thelist" class="plastic"><!-- li items --></ul>
</div>
</div>
<div class="footer">Footer</div>
</div>
<!-- Events Details -->
<div id="events">
<div class="header">iScroll</div>
<div class="wrapper">
<div id="scroller"> <!-- stuffsss --></div>
</div>
<div class="footer">Footer</div>
</div>
For iScroll (http://cubiq.org/iscroll) to work, I need the #scroller as ID (as per the javascript Code I'm using to initialize iScroll.
//for iScroll
var myScroll = new iScroll('scroller', {desktopCompatibility:true});
// Load iScroll when DOM content is ready.
document.addEventListener('DOMContentLoaded', loaded, false);
But since I can't have two different elements with the same ID (please notice I've got two elements with same id scroller in my markup above), some conflicts are there and the iScroll isn't working properly.
I want to be able to implement the iScroll on the markup by changing the id as classes. I tried to change them into classes and see if it works but I couldnt get it right.
Can anyone help me change the codes so that it works by implementing classes instead of the the id??
Rob is right, but you can change your code to scroller classes as you said.
Then initialise your scrollers within unique wrappers like this:
var scroll1, scroll2;
function loaded() {
scroll1 = new iScroll('wrapper1');
scroll2 = new iScroll('wrapper2');
}
I'm not totally clear on what you are trying to achieve but if you want two parts of your page to scroll I would suggest changing the IDs to be unique and instantiate two iScrolls with the different IDs.
I am sure you have figured it out, but for other users still struggling with similar layout (multiple scrollers) and want to make them work. Here is the answer from other thread
https://stackoverflow.com/a/7584694/1232232
but for this to work you need to assign ID's to your classed (div containers)
like
<div id="home" class="current">
<div class="header">iScroll</div>
<div id="wrapper-1" class="scrollable">
<div class="scroller">
<ul class="thelist" class="plastic"><!-- li items --></ul>
</div>
</div>
<div class="footer">Footer</div>
</div>
<div id="home2" class="current">
<div class="header">iScroll</div>
<div id="wrapper-1" class="scrollable">
<div class="scroller">
<ul class="thelist" class="plastic"><!-- li items --></ul>
</div>
</div>
<div class="footer">Footer</div>
</div>
Note: Remember not to assign same ID to multiple elements, always use classes for that purpose.

Zend controller/view newbie puzzle: $_GET & $_POST empty - on receipt from HTML form within view

Zend newbie here ... And just to make it better, my mission is to build on top of someone else's pre-existing Zend site.
(BTW: zf show version --> Zend Framework Version: 1.11.1 -- I seem to have Zend_Form).
Here's the curious bit. All the forms are built in HTML within views. They seem to work, although I can't figure out how -- especially given what I am seeing.
I followed the convention and created a view for a test form and wrote the form:
<form action="<?php echo $this->url(array('controller'=>'ControllerName','action'=>'submit'));?>" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
<input class="text" type="text name="custEmail"/>
</div>
<div class="field">
<input class="button" value="Submit and be free!" type="submit"/>
</div>
</form>
The submitAction member in the controller is firing correctly. No problem.
But ALL the places I could look for the POST data appear to be empty!
echo "obj custEmail = [" . $this->_request->getPost('custEmail') . "]\n";
echo "GET custEmail = [" . $_GET['custEmail'] . "]\n";
echo "POST custEmail = [" . $_POST['custEmail'] . "]\n";
if ($this->_request->isPost()) {
$data = $this->_request->getPost();
Zend_Debug::dump($data);
}
They all produce nothing.
I'd be much obliged for a solution or even a clue about what is going wrong.
Thanks for reading.
Your form is not in the correct format.As it's PHP you can use form like this or you can even generate a ZEND_FORM(which is profound way to do it).It's always a good practise to work around with ZEND_FORM.If you still want to use this and the go by your way,here is th snippet I modified for you.
I am modifying the Code for you.Your View should have this form in it;
<form action="" method="post" style="margin-left:20px">
<p class="bold setmgr">Your email here:</p>
<div class="field">
<input class="text" type="text" name="custEmail"/>
</div>
<div class="field">
<input class="button" value="Submit and be free!" type="submit" name="submit"/>
</div>
</form>
<?php
echo $this->custEmail;
?>
Now write the following one on your ACTIOn,i.e. submitAction;
public function submitAction()
{
if ($this->getRequest()->isPost())
{
$custEmail = $this->getRequest()->getPost('custEmail');
echo $custEmail;
$this->view->custEmail = $custEmail;
}
}
Now check if it works for you or not.
Create a form using Zend_Form. When ZF already has a way to create forms, you should use that. Your method is like a hack and is not a recommended way to do things.
Check here on how to create a Zend_Form
http://framework.zend.com/manual/en/zend.form.html

jQuery: getting current selector's inner html PLUS selector's header (outer html)

Using jQuery, I've got a selector -- call it $('#someDiv1') -- that I'd like to get the inner HTML for, but also the header of the tag as well. So given this HTML structure..
<div id="parentDiv">
<div id="someDiv1">
<div id="innerDiv1_1"></div>
<div id="innerDiv1_2"></div>
</div>
<div id="someDiv2">
<div id="innerDiv2_1"></div>
<div id="innerDiv2_2"></div>
</div>
</div>
If I've got the selector $('#someDiv1') in a variable -- call it $someDiv1 -- I'd like to be able to use that variable to get a string that is:
"<div id='someDiv1'>
<div id='innerDiv1_1'></div>
<div id='innerDiv1_2'></div>
</div>"
I thought about just saying $someDiv1.parent().html(), but that would give me the div's sibling(s) as well (someDiv2, etc..). Any ideas? Thanks.
You also try
$('#parentDiv').clone().find("> :not(#someDiv1)").remove().end().html();
You can try something like this:
$('<div></div>').append($('#someDiv1').clone()).html()