Zend Framework - Flashmessenger - Only one character - zend-framework

I have a little problem with FlashMessenger. When I want to retrieve the messages in my layout, it writes the first letter of the message... example "test" displays "t".
I tried a solution posted in this question, but nothing changed for me.
I use php 5.3.6
Here is my code:
In my method :
$message = 'test';
$this->_helper->FlashMessenger($message);
Call in the Layout
<div id="message_box">
<?php echo $this->flashMessages(); ?>
</div>
Can someone help me?

Try this:
In controller:
$this->_helper->FlashMessenger->addMessage("Your message", 'actions');
// you can redirect to another controller ...
$this->view->messages = $this->_helper->FlashMessenger->getMessages('actions');
In phtml file:
<!-- some html code -->
<div id="message_box">
<?php echo $this->messages[0]; ?>
</div>

Related

joomla get input setting the date format in calendar tag

I have a calendar input box in my joomla component. The XML for the calendar element is:
<field name="dob" type="calendar"
label="COM_OPTICAL_DATABASE_FORM_LBL_PATIENTDETAIL_DOB"
description="COM_OPTICAL_DATABASE_FORM_DESC_PATIENTDETAIL_DOB"
format="%d-%m-%Y"
filter="raw" />
Which has the right date format. However the input box in the form shows up as
Y-m-d
I want to reformat it to the correct date
I found this which puts in the current date:
<div class="tablecol1 zebra1">
<?php echo $this->form->getLabel('dob'); ?>:
</div>
<div class="tablecol2 ">
<?php echo $this->form->getInput('dob', '', date('d-m-Y')); ?>
but I want it to put in the date I retrieved from the database.
Try the following:
<?php
echo $this->form->getInput('dob', '', JFactory::getDate('dob')->format('d-m-Y'));
?>
OR:
<?php
echo $this->form->getInput(JFactory::getDate('dob')->format('d-m-Y'), '');
?>
Please note I haven't tested it so let me know if it works
I made a work around since no one seems to have the answer. I think Joomla either doesn't allow this or there is some way of doing it buried somewhere in the documentation. Anyway for anyone else struggling to make this work:
<?php
$birthDate1 = $this->form->getValue('dob');
$birthDateHolder = explode("-", $birthDate1);
$changed = $birthDateHolder[2]."-".$birthDateHolder[1]."-".$birthDateHolder[0];
echo $this->form->getInput('dob', '', $changed);
?>
I've tested this and it works correctly.

ZF2 ViewModel addChild(). How to read it on layout (not template)?

I have problem with Zend Framework 2 and ViewModel with which i can not deal.
I want to do really simple thing, but this framework is not helping with that...
I have for example simple layout:
<html>
<div id="window">
<?php echo $this->window;
// or whatever working....
?>
</div>
<div id="content">
<?php echo $this->content; ?>
</div>
</html>
I want to add content of window in a place, where $this->window is printed.
I have tried by:
$view = new ViewModel();
$window = new ViewModel();
$window->setTemplate('window/window_error222'); // Template with error to include on layout
$view->addChild($window, 'window');
It works fine on content file, but i cannot access 'window' variable in layout file. Is there any solution for that? I dont want to create another template for window div.
I have resolved my problem by this:
$layout = $this->layout();
$layout->addChild($window, 'window');

Yii model method addError is not working

I have an issue about displaying error in a yii form.
This is my controller:
$custom_user->attributes = $_POST['CustomUser'];
if($custom_user->validate())
{
...
save
...
}
else
{
$custom_user->addError('username', 'Error X');
$this->redirect(array('access/index'),
array('user'=>$custom_user,
'tab'=>$tab_person,
));
}
This is my index view:
<?php $form=$this->beginWidget('BaseForm', array(
'id'=>'user-form',
'action'=>Yii::app()->createUrl('person/createUser'))); ?>
<?php echo $form->errorSummary($user);?>
<div class="right">
<?php echo $form->textField($user,'username',array('size'=>30,'maxlength'=>255)); ?>
<br/><?php echo $form->error($user,'username'); ?>
</div>
...
...
<div style="float: left;">
<?php echo $form->dateField($user,'valid_from',null,'valid_from_formated'); ?>
<br/><?php echo $form->error($user,'valid_from'); ?>
</div>
Here is my BaseForm
public $enableClientValidation = true;
public $enableAjaxValidation = true;
public $clientOptions = array( 'hideErrorMessage'=>false,
'validateOnSubmit'=>true,
'validateOnChange'=>false,
'validateOnType'=>false,
'afterValidateAttribute' => 'js:enableSubmitAV',
'afterValidate' => 'js:submitFormAV'); // always fires this after
Here is the problem:
"$form->errorSummary($user);" is empty
and noting is display under "$form->error($user,'username');"
But if I look in Firebug I can see that under "response" tab:
{"CustomUser_valid_until":["Valid Until must be
greater than \"20121127\"."]}
it's a good thing because it means my rules work great. But none errors are displayed. Not this one and even the error "Error X" I add in my controller is not diplayed... (I'm sure I pass throught the else statement, i tried it).
So, does anyone could have an idea?
Thanks for reading me and sorry for my approximate English.
Have a good day :)
Michaƫl
You are redirecting, meaning a whole new request is called, and any responses are deleted.
Why are you redirecting to "access/index" rather than just calling the view? If you do need to redirect, which you definitely can, try setting a flash variable as it is store in the browser's session and will persist through redirects:
Yii::app()->user->setFlash('username', "Error X");
Then on the access/index page:
<?php if(Yii::app()->user->hasFlash('username')):?>
<div class="error">
<?php echo Yii::app()->user->getFlash('username'); ?>
</div>
<?php endif; ?>
Ok finally I got what was wrong. It was the configuration in my CActiveForm. The option "enableAjaxValidation" seems to make some problem when it's on "true". I don't know really why but I've already had this problem with a login form befor. I'll try to work out this problem.

Is there a 'kosher' way to display options in a select tag as a list of links, and NOT a drop-down?

My problem is that I am making a dynamic generated form using codeigniter. I need my dynamic results to be made into links. These 'links' are contained within a form and when clicked, should pass an item_id. The displayed link however should portray the item_name. I have both the id and name of every product within a foreach, gathered from a query. The reason I am doing it like this and not having them as a radio/drop-down, is because I'm attempting to make this touchscreen friendly. I need to have them list out as links. I am trying to stay away from javascript on this if I can. Just wondering if anyone had an idea of what I could do here. As I asked in my title, what I am looking for is a way to make form inputs as if they where select/option but listed as links. I also tried them as submit tags, but then I cannot display the name and have the value as the id.
EDIT:
I should also add that $key is the id of each product and $info is the name.
foreach($products as $key => $info):
?>
<div class="field_row clearfix">
<?php
/* NEED THE FORM ELEMENTS HERE */
?>
</div>
<?php
endforeach;
You could use jquery and js metadata to achieve this.
N.B. untested code of the top of my head.
<?php
foreach ($products as $key => $info)
{
?>
<div class="product-link {item_id: <?php echo $key; ?>}">
<?php echo $info; ?>
</div>
<?php
}
?>
<script type=text/javascript">
/*<![CDATA[*/
$(document).ready(function() {
// listen event on drop down
$(".product-link").click(function () {
var item_id = $(this).metadata().item_id;
// do what ever you want here, maybe a redirect
window.location.href = "/products/items/"+item_id;
});
});
/*]]>*/
</script>

how can strips html tags in joomla

hi i am working on joomla. and i used the latest news module but it emerging a problem that the new display on page having the tags like paragraph i wanna remove that tags from the news
my code is
<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<?php $i=1 ;?>
<?php foreach ($list as $item): ?>
<?php if($i==1) {echo "<div class='latestnews_ttl'> <p>".$item->cat_title." </p></div>";} $i++; ?>
<div class="news_box">
<p style=" padding:0px;"><strong><?php echo $item->text; ?> </strong></p>
<p><?php if(strlen($item->introtext)>100)
{
$txt = str_split($item->introtext, 100);
echo $txt['0']."...";
}
else{
echo $item->introtext;
}
?></p>
<div class='readmore'>read more</div></div>
<?php endforeach; ?>
It will give news with prefix tag "<p>" so please give the solution of it.
thanks in advance
Tried strip_tags() ?
Always remember in Joomla! never to modify core code, always overwrite the core templates by following the following guide http://docs.joomla.org/Tutorial_talk:Template_overrides
1: http://docs.joomla.org/Tutorial_talk:Template_overrides or a quick how to http://www.techportal.co.za/joomla/joomla-tutorials/124-how-to-modify-the-appearance-of-the-category-list-page-without-having-modifications-done-to-the-joomla-core-code
If you do this in the core it will work, but once you may upgrade your changes could be gone.
Since joomla is written in php you could use strip_tags