I am building a theme template page that calls up all the child categories of a particular parent and displays them so that they look like this:
The only trouble is that when any row has less than 3 posts, it looks like this:
I need to display 1-3 posts and move on to the next category if there are either more OR less than 3 posts, and not have it look like crap.
$taxonomy = 'category'; // e.g. post_tag, category
$param_type = 'category__in'; // e.g. tag__in, category__in
$term_args=array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 13
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
foreach( $terms as $term ) {
$args=array(
"$param_type" => array($term->term_id),
'post_type' => 'candidate',
'post_status' => 'publish',
'showposts' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<div class="val-postcontent val-post"><h4 >' . $term->name. ' Candidates</h4></div> ';
while ($my_query->have_posts()) : $my_query->the_post();
get_template_part('content', 'overview');
endwhile;
echo '<div class="test"><a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>Click here to view all ' . $term->name. ' Candidates</a></div>';
}
}
}
I too belive this is a CSS issue, so it probably belongs on StackExchange instead, but here it goes:
The easiest, quickest (and probably ugliest) fix is to add <div style="display:block; clear: both;"> before each <div class="val-postcontent val-post">.
A quick way to make this a little bit cleaner: move the display:block; clear: both; into a separate css class, for example .clearfix {...}.
edit: I was to quick on the trigger. The div should be added before the div
Related
How can I disable only the parent item link and leave its children clickable ? For example - when I click on my parent it should open the submenu and not redirect to somewhere else. And if I click on children it should redirect me.
P.S I red the documentation, searched around google but nothing comes out.
This is my code:
<?php
use backend\models\PageAdmin;
use backend\helpers\BackendPrefix;
use yii\widgets\Menu;
$menu_pages = PageAdmin::find()->where('active=1 AND id_in IS NULL')->all();
$widget_menu_content = [];
foreach ($menu_pages as $key => $page){
$related_pages = PageAdmin::find()->where(['active' => 1, 'id_in' => $page->id])->all();
$widget_menu_content[$key]['label'] = "<i class='{$page->icon}'></i>";
$widget_menu_content[$key]['icon'] = $page->icon;
$widget_menu_content[$key]['url'] = BackendPrefix::PREFIX .'/'. $page->url;
if(!empty($related_pages)){
foreach ($related_pages as $key2 => $rel_page) {
$widget_menu_content[$key]['items'][$key2]['label'] = $rel_page->title;
$widget_menu_content[$key]['items'][$key2]['icon'] = "caret-right";
$widget_menu_content[$key]['items'][$key2]['url'] = BackendPrefix::PREFIX . "/" . $rel_page->url;
}
}
}
?>
<div class="side-mini-panel">
<?=
Menu::widget([
'encodeLabels' => false,
'options' => [
'class' => 'mini-nav',
],
'activeCssClass' => 'selected',
'items' => $widget_menu_content,
'submenuTemplate' => "
\n<div class='sidebarmenu'>
\n<h3 class='menu-title'>{label}</h3>
\n<div class='searchable-menu'>
\n<form role='search' class='menu-search'>
\n<input type='text' placeholder='Search...' class='form-control' />
\n<a href='javascript:void(0)'><i class='fa fa-search'></i></a>
\n</form>
\n<div>
\n<ul class='sidebar-menu'>
\n{items}
\n</ul>
\n</div>",
'linkTemplate' => "<a href='javascript:void(0)'>{label}</a>",
'activateParents' => true,
])
?>
</div
Whit my 'linkTemplate' I am disabling all the links which obviously is not my goal :) ( It should disable the parents only ). Alsom, with what token ( or some other option, because I think items is the only token for the children ) I should append the child item label on this line : \n<h3 class='menu-title'>{label}</h3>. In my case what I get echoed is just {label} like a string.
Many thanks!
Hi there:) i've got a problem with decorators and form which would be in table and in this table want to have also data from database... I dont have any idea how to do this to have a structure like something below, lets say
<table>
<tr>
<td><?php echo array[0]['name']?>
//and here input from zend form
<td>
<select name='foo' id='bar'>
<option value='something'>Foo</option>
<option value='something2'>Foo2</option>
</select>
</td>
</tr>
</table>
Ofcourse tr will be more and generated with foreach or some loop.
I have something like this:
<?php
class EditArticles_Form_EditArticles extends Zend_Form
{
protected $uid;
public function render()
{
/* Form Elements & Other Definitions Here ... */
$this->setName('editarticles');
$data = new EditArticles_Model_DbTable_EditArticlesModel();
$datadata = $data->GetArticlesToEdit($this->getUid()); //here is my data from db
for ($i=0;$i<count($datadata);$i++)
{
$do = new Zend_Form_Element_Select(''.$i);
$do->addMultiOption('0', 'Aktywny');
$do->addMultiOption('1', 'Nieaktywny');
$this->addElements(array($do));
}
$submit = new Zend_Form_Element_Submit('updateart');
$this->addElement($submit);
//and here are decorators for array, and i would like to have in this table also data from array containing data from database
$this->addDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'table', 'id' => 'aaaa', 'style' => 'width:500px;')), 'Form',
));
$this->setElementDecorators(array(
'ViewHelper',
array( array('data' => 'HtmlTag'), array('tag' => 'td', 'style' => 'width:200px;')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
),
//wykluczenie submita z overrida stulu
array('submit'), false);
return parent::render();
}
//setting user id for get content from db
public function setUid($uid) {
$this->uid = $uid;
return $this;
}
public function getUid() {
return $this->uid;
}
}
?>
output of code above is something like this: (in red marked where i would like to have that selects from form. In this image the table with data is an other table generated in phtml, but i would like to generate that table by form od just insert only the form elements to that table generated in phtml view).
http://img14.imageshack.us/img14/9973/clipboard01pw.png
Something found here:
Zend_Form: Database records in HTML table with checkboxes
but i dont know how to start with that...
Several comments:
Typically, adding elements to the form is done in init(), rather than render().
If a consumer object (this is this case, the form) needs a dependency (in this case, the article model) to do its work, it is often helpful to explicitly provide the dependency to the consumer, either in the consumer's constructor or via setter method (ex: $form->setArticleModel($model)). This makes it easier to mock the model when testing the form and clearly illustrates the form's dependence on the model.
Re: rendering other content in the form via decorators: Maybe, take a look at the AnyMarkup decorator. It looks like (sorry, can't fully understand the Polish) you want a select box on each row you output. So, you get your rows using the model, loop through the rows, creating your select box on each row. When you assign decorators to the select element - ViewHelper, Errors, probably an HtmlTag decorator to wrap it in a <td> - you also add the AnyMarkup decorator to prepend the a bunch of <td>'s containing your row data, finally wrapping the whole row in <tr>.
Perhaps something like this (not fully tested, just to give the idea):
class EditArticles_Form_EditArticles extends Zend_Form
{
protected $model;
public function __construct($model)
{
$this->model = $model;
parent::__construct();
}
public function init()
{
$rows = $this->model->GetArticlesToEdit($this->getUid());
$numRows = count($rows);
for ($i = 0; $i < $numRows; $i++) {
$do = new Zend_Form_Element_Select('myselect' . $i);
$do->addMultiOption('0', 'Aktywny');
$do->addMultiOption('1', 'Nieaktywny');
$do->setDecorators(array(
'ViewHelper',
array(array('cell' => 'HtmlTag'), array(
'tag' => 'td'
)),
array('AnyMarkup', array(
'markup' => $this->_getMarkupForRow($i, $row),
'placement' => 'PREPEND',
)),
array(array('row' => 'HtmlTag'), array(
'tag' => 'tr'
)),
));
$this->addElement($do);
}
}
protected function _getMarkupForRow($i, $row)
{
return '<td>' . $i . '</td>' .
'<td>' . $row['nazwa'] . '</td>' .
'<td>' . $row['typ'] . '</td>' .
'<td>' . $row['rozmiar'] . '</td>';
}
}
A final note: Remember to register an element decorator prefix path as follows (in the form, probably in init()):
$this->addElementPrefixPath('My_Decorator', 'My/Decorator', self::DECORATOR);
This allows the element to resolve the short name AnyMarkup into a full classname My_Decorator_AnyMarkup.
Weird title, yes, but the problem is simple; simply aggrevating. I have a form, that I built without using Zend_Form, and it has two file uploads:
<input name="image" type="file" />
<input name="file" type="file" />
Here is the chunk of code from my controller that is handling the upload. There's actually a little more, but this is the relevant piece:
$data['image'] = (isset($_FILES["image"]) && $_FILES["image"]["name"] ? $_FILES["image"]["name"] : NULL);
$data['file'] = (isset($_FILES["file"]) && $_FILES["file"]["name"] ? $_FILES["file"]["name"] : NULL);
$options = array('ignoreNoFile' => TRUE);
$upload = new Zend_File_Transfer();
$upload->setOptions($options)
->addFilter('Rename', array('target' => RESOURCES_IMG . $data['image'], 'overwrite' => TRUE), 'image')
->addFilter('Rename', array('target' => RESOURCES_FILES . $data['file'], 'overwrite' => TRUE), 'file')
->addValidator('ImageSize', false, array('minwidth' => 100,
'maxwidth' => 100,
'minheight' => 100,
'maxheight' => 100), 'image')
->addValidator('Extension', false, 'jpg', 'image');
if (!$upload->isValid())
{
echo '<h1>Oops</h1><p>Please correct the following errors: <hr /></p>';
foreach ($upload->getMessages() as $key => $val)
{
echo '<p><strong>' . $key . '</strong><br />' . $val . '</p>';
}
die;
}
else
{
$upload->receive();
} // if (!$upload->isValid())
It's pretty straight forward. The $data stuff is just me grabbing the filename if it's there or setting the variable to NULL. I have my addFilter() and addValidator() segmented out to only affect their relevant files in this case "image" or "file" - the names of the form fields.
The "file" upload always works! However, the "image" upload doesn't and what's more it puts the temporary file into the RESOURCES_FILES directory which makes no sense at all. So that directory has PDFs and whatever else in addition to files like php8TJT13, phpXmOzQM, etc.
I have been staring at this code and searching through Stack Overflow and whatever Google will turn up and I can't find anyone having this problem. Help!
Alright, so I did more digging and it turns out there may be an issue with the way I was chaining addFilter() so I decided to move in a different direction, trying to isolate each file and handle it's upload individually. So far it appears to be working. Here is the revised code:
$data['image'] = (isset($_FILES["image"]) && $_FILES["image"]["name"] ? $_FILES["image"]["name"] : NULL);
$data['file'] = (isset($_FILES["file"]) && $_FILES["file"]["name"] ? $_FILES["file"]["name"] : NULL);
$upload = new Zend_File_Transfer();
$files = $upload->getFileInfo();
$options = array('ignoreNoFile' => TRUE);
$upload->setOptions($options);
foreach ($files as $field => $contents)
{
if(!strlen($contents["name"]))
{
continue;
}
// upload instructions for image
if ($field == 'image')
{
$upload->addFilter('Rename', array('target' => RESOURCES_IMG . $data['image'], 'overwrite' => TRUE), 'image')
->addValidator('ImageSize', false, array('minwidth' => 100,
'maxwidth' => 100,
'minheight' => 100,
'maxheight' => 100), 'image')
->addValidator('Extension', false, 'jpg', 'image');
}
// upload instructions for file
if ($field == 'file')
{
$upload->addFilter('Rename', array('target' => RESOURCES_FILES . $data['file'], 'overwrite' => TRUE), 'file');
}
if(!$upload->receive($field)) {
echo '<h1>Oops</h1><p>Please correct the following errors: <hr /></p>';
foreach ($upload->getMessages() as $key => $val)
{
echo '<p><strong>' . $key . '</strong><br />' . $val . '</p>';
}
die;
//return;
}
} // foreach
Pseudo Explanation
I use the getFileInfo() to grab an array of the files available to me then I loop over each. At the beginning of my first for loop I check to see if this file has a name, if it doesn't have a name I assume that field was left blank and is NULL so I tell the loop to skip over that and continue.
Once I'm in the loop I'm just matching my upload directives with the appropriate form field using a simple conditional. The rest should be fairly self-explanatory if you're into Zend stuff.
Hopefully this helps someone else that was in my predicament. If you are a Zend guru maybe you can comment on my solution or fix the bug that's causing the issue. There may be a more "Zend" way of doing it, but it's working now and that feels damn good.
References
Why I thought it was the chaining of the addFilter() method, see the note under Example #3 (below):
Note: Note that even though setting the same filter multiple times is allowed, doing so can lead to issues when using different options for the same filter.
http://framework.zend.com/manual/1.11/en/zend.file.transfer.filters.html
A random blog article that inspired me to try isolating each, I'm calling it, "upload directive" although I'm not sure if that's what it's called:
http://www.pc-freak.net/blog/tag/uploading-multiple-files-from-a-form-with-zend-framework-zf-storing-uploaded-zf-files-with-unique-name/
I want to show number of row : paginator zend framework
Example:
number productname price
1. pen 25.00
2. Pencil 10.00
3. Booklet 12.00
i want show number of row the exaple (number row). (get from paginator ok)
At the moment I can think of three ways you can get current item number from/using paginator:
using foreach's $key => $item. In this case $key should be your item number.
using normalizeItemNumber method of Zend_Paginator
using partialView helper
All the three methods are illustrated in the following example:
testAction
public function testAction() {
$input = array(
array(
'productname' => 'somename',
'price' => 23
),
array(
'productname' => 'somename2',
'price' => 657
)
);
$paginator = Zend_Paginator::factory($input);
$paginator->setCurrentPageNumber(1);
$this->view->paginator = $paginator;
}
test.phtml view script
<div>
<?php foreach ($this->paginator as $key => $item): ?>
Item Number (Method 1): <?php echo $key; ?> </br>
Item Number (Method 2): <?php echo $this->paginator->normalizeItemNumber($item); ?> </br>
<?php endforeach; ?>
Third Method through partialLoop view helper:
<?php echo $this->partialLoop('_partials/testPartial.phtml', $this->paginator); ?>
</div>
Where testPartial.phtml is as follows:
<div>
Item Number (Method 3): <?php echo $this->partialCounter; ?> </br>
<!-- Other values can be accessed as $this->productname -->
</div>
Hope this is what you are looking for in your case.
I am not sure what you want exactly, but give this a try
$pages = $paginator->getPages();
var_dump($pages);
echo $pages->pageCount;
getPages() has some useful information in which you can use about the paginator object. It will output something like:
object(stdClass)[201]
public 'pageCount' => int 4
public 'itemCountPerPage' => int 10
public 'first' => int 1
public 'current' => int 1
public 'last' => int 4
public 'next' => int 2
public 'pagesInRange' =>
array
1 => int 1
2 => int 2
3 => int 3
4 => int 4
public 'firstPageInRange' => int 1
public 'lastPageInRange' => int 4
public 'currentItemCount' => int 10
public 'totalItemCount' => int 33
public 'firstItemNumber' => int 1
public 'lastItemNumber' => int 10
Failing that you might need to do something inside the loop while iterating over the object. For example in your view:
$row = 0;
foreach($this->paginator as $rowNumber => $data)
{
echo "I am row " . $rowNumber . "<br />";
}
Hope that helps.
If the number in front of the row is not related to the id of the item, you could simply increment a counter through each iteration of your data display.
$i = 1;
echo '<ul>';
foreach ($this->paginator as $item){
echo '<li>' . $i . ' | ' . $item['name'] . ' | ' . $item['price'] . '</li>';
$i++;
}
echo '</ul>';
The very same counter could be used to make a Zebra table (alternating background colors) with the use of modulo.
$i = 1;
echo '<ul>';
foreach ($this->paginator as $item){
if($i % 2 == 0){
$class = 'even';
}else{
$class = 'odd';
}
echo '<li class = "' . $class . '">' . $i . ' | ' . $item['name'] . ' | ' . $item['price'] . '</li>';
$i++;
}
echo '</ul>';
I have a sfWidgetFormChoice which renders checkboxes in Symfony 1.4. The problem I have is that I want to rend each choice as a row in a table. So my html would ideally be something like this:
<tr><td>Choice 1</td></tr>
<tr><td>Choice 1</td></tr>
<tr><td>Choice 1</td></tr>
.
.
.
So that it would render as a table instead of a list.
Thanks!
In your form called MyForm create the following widget:
$this->widgetSchema ['my_widget'] = new sfWidgetFormChoice(array('multiple' => true, 'expanded' => true, 'choices' => my_choices, 'renderer_class' => 'sfWidgetFormSelectCheckbox', 'renderer_options' => array('formatter' => array('MyForm', 'MyFormatter'))));
$this->validatorSchema ['my_widget'] = new sfValidatorChoice(array('multiple' => true, 'choices' => array_keys(my_choices), 'required' => false));
Then add the following formatter method called MyFormatter:
public static function MyFormatter($widget, $inputs) {
$result = '<table>';
foreach ($inputs as $input) {
$result .= '<tr><td>' . $input ['label'] . ' ' . $input ['input'] . '</td></tr>';
}
$result .= '</table>';
return $result;
}
I used for choices to be rendered as checkboxes by setting renderer_class option to sfWidgetFormSelectCheckbox in widget definition you can use sfWidgetFormSelectRadio to render it to radio buttons and you can call another formatter from another form by changing array('formatter' => array('MyForm', 'MyFormatter')).