I have an array, that I want to retrieve the values from.
When I test the array with a print_r, it says that it has the right values. But when I want to show them in their right places, it says that it has no values.
function employees_items($nodeid, $language)
{
$query = db_query(//SOME QUERY);
$rows = array();
foreach ($query as $row) {
$rows[] = array(
$row->nid,
$row->title,
$row->field_service_nummer_value,
$row->field_support_email_value,
$row->uri,
);
}
return $rows;
}
Here I want to retrieve the values...I want the value in $row->uri. The errormessage: Trying to get property of non-object i employees_block_view()
function employees_block_view($delta = '')
{
if (array_key_exists($brandpage_id_page, $medarbejder_brandpages))
{
switch ($delta)
{
case 'employees':
$employees = employees_items($brandpage_id_page, $lang_name);
foreach ($employees as $row)
{
$block['content'] .= '<div class="img">';
$block['content'] .= '<img style="width: auto; height: 100px;" src="'.file_create_url($row->uri). '" alt="Vores support medarbejder" />';
}
return $block;
}
I found the answer. This is the way it must be written to read the value of 'uri'.
$block['content'] .= '<img style="width: auto; height: 100px;" src="'.file_create_url($row['uri']). '" alt="Vores support medarbejder" />';
Related
How can i keep the selected checkboxes checked, after the form submit on error? Now, i get this error message: Warning: in_array() expects parameter 2 to be array, string given in
Thanks!
function runsql_array($sql)
{
global $kapcs;
$res = mysqli_query($kapcs , $sql) or die(mysqli_error( $kapcs));
if (mysqli_num_rows($res) == 0)
{
return array();
}
else
{
$out = array();
while ($a = mysqli_fetch_assoc($res))
{
$out[] = $a;
}
return $out;
}
}
<td>
<?php
$ertek = isset($_POST["termek_tul_tipusok"]) ? $_POST["termek_tul_tipusok"] : '' ;
$values = runsql_array("SELECT termek_tipus_id, termek_tipus_nev FROM termek_tipusok WHERE termek_tipus_status = 1
ORDER BY termek_tipus_nev ASC");
foreach($values as $val=>$szoveg)
{
$checked = in_array($val, $ertek) ? ' checked ' : '' ;
echo '<div style="margin:4px 0;"><label style="cursor:pointer;" for="tulajdonsag-'.$val.'">';
echo '<input id="tulajdonsag-'.$val.'" type="checkbox" name="termek_tul_tipusok[]" '.$checked.' value="'.$val.'" />';
echo $szoveg['termek_tipus_nev'];
echo '</label></div>';
}
?>
</td>
the line
$ertek = isset($_POST["termek_tul_tipusok"]) ? $_POST["termek_tul_tipusok"] : '' ;
defines $ertek. And in the case that the post dosnt exist its defined as an empty string. You should use an empty Array.
$ertek = isset($_POST["termek_tul_tipusok"]) ? $_POST["termek_tul_tipusok"] : array() ;
I have no idea why it will return all the values I'm looking for with echo, but only 1 set with "return".
I removed all the code within the first foreach statement to see if there was some conflict between the foreach statements, but it returns with the same result.
I've tried some of the suggestions on here that I thought might be relevant, but without any luck.
What could I possibly be doing wrong?
function getInvoiceTimeLog($project_unique_id, $user_id, $user_timezone, $time_format)
{
global $db;
$query = "SELECT t.task_id, t.unique_id, t.name, t.description, t.sub_total, p.project_id, p.user_id FROM task as t, task_project as tp, project as p WHERE t.task_id = tp.task_id AND tp.project_id = p.project_id AND p.unique_id = ".$db->prep($project_unique_id)." AND p.user_id = ".$db->prep($user_id)." ORDER BY t.name";
$res = $db->query($query,'assoc');
if($res != false)
{
foreach($res as $row1):
$date = '';
$prevDate = '';
$return = '';
$query = "SELECT a.track_id FROM task_track a INNER JOIN track_time b ON a.track_id = b.track_id WHERE a.task_id =".$db->prep($row1['task_id'])." ORDER BY FROM_UNIXTIME(b.time_start,'%Y-%m-%d %H:%i:%s') DESC";
$resT = $db->query($query,'assoc');
$return .= '<div class="table" id="InvoicetimeLog"><div class="thead"><div class="th date">Date</div><div class="th start">Start</div><div class="th stop">Stop</div><div class="th hours">Hours</div></div><ul class="list">';
$return .= '<li>'.$row1['description'].'</li>';
if($resT != false)
{
foreach($resT as $row):
$track_id = $row['track_id'];
$query = "SELECT comment_id FROM track_comment WHERE track_id = ".$db->prep($track_id);
$resComLink = $db->query($query,'assoc');
if($resComLink != false)
{
$query = "SELECT comment,time_left FROM comment WHERE comment_id = ".$db->prep($resComLink[0]['comment_id']);
$resComment = $db->query($query,'assoc');
$comment_class = 'comment_has';
}
else
{
$comment = '';
$comment_class = 'comment';
}
$query = "SELECT time_start,time_end FROM track_time WHERE track_id = ".$db->prep($track_id);
$resTime = $db->query($query,'assoc');
$date = format_time($resTime[0]['time_start'],'m/d/y');
if($date != $prevDate)
{
$prevDate = format_time($resTime[0]['time_start'],'m/d/y');
$timeLog_ex = '<div class="date bold">'.$prevDate.'</div>';
$group = 'grp_shw';
}
else
{
$timeLog_ex = '<div class="date bold"></div>';
$group = 'grp_no';
}
if($time_format == 'g')
{
$the_time_format = 'g:i a';
}
else
{
$the_time_format = 'G:i';
}
if(empty($resTime[0]['time_end']))
{
$return .= '<li class="'.$group.'" id="rtrack_'.$track_id.'">'.$timeLog_ex.'<div class="start inlineEdit">'.date('m/d/y - '.$the_time_format,$resTime[0]['time_start']).'</div><div class="stop" title="The current time is at '.date($the_time_format,$db->nowUnix($user_timezone)).'">Current</div><div class="hours">'.getTimeDifference($resTime[0]['time_start'],$db->nowUnix($user_timezone)).'</div></li>';
}
else
{
$return .= '<li class="'.$group.'" id="rtrack_'.$track_id.'">'.$timeLog_ex.'<div class="start inlineEdit">'.date('m/d/y - '.$the_time_format,$resTime[0]['time_start']).'</div><div class="stop">'.date('m/d/y - '.$the_time_format,$resTime[0]['time_end']).'</div><div class="hours">'.getTimeDifference($resTime[0]['time_start'],$resTime[0]['time_end']).'</div></li>';
}
endforeach;
$return .= '<li class="grp_no"><div class="date bold">Total Time</div><div class="total">'.tot_time($unique_id,$user_id, $user_timezone).'</div></li>';
}
$return .= '</ul></div>';
endforeach;
}
return $return;
}
What a dope I am. It's simple....just move the variable declarations OUTSIDE of the foreach loop!
Move these guys to above the first foreach:
$date = '';
$prevDate = '';
$return = '';
I am trying to add two classes to drupal7's primary tab element. I tried overriding theme_menu_local_tasks by adding this to my template.php:
function {{proj}}_menu_local_tasks(&$variables) {
$output = '';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
$variables['primary']['#prefix'] .= '<ul class="nav nav-tabs">';
$variables['primary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['primary']);
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
$variables['secondary']['#prefix'] .= '<ul class="nav nav-tabs">';
$variables['secondary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['secondary']);
}
return theme_menu_local_tasks($variables);
}
Although, this never seems to be get called. What am I doing wrong?
I added the following function in template.php and called it instead or render($tabs) in the page template:
function {{proj}}_render_nav_tabs() {
$output = '';
if ($primary = menu_primary_local_tasks()) {
$output .= '<ul class="nav nav-tabs space-bottom">' . drupal_render($primary) . '</ul>';
}
if ($secondary = menu_secondary_local_tasks()) {
$output .= '<ul class="nav nav-tabs space-bottom">' . drupal_render($secondary) .'</ul>';
}
return $output;
}
The value of my select tag doesn't seem tto post to my controller, no matter what I try
The select tag
<select name="whatever">
<?php
foreach($packs as $packName => $pack) {
echo " '<option value=" . $packName . '">' . $packName . '</option>';
}
?>
</select>
Where I try to use it in controller
function procedures() {
$errors = array();
$otsing= "";
if (!isset($this->data)) {
App::import('Helper', 'Formatter');
$formatter = new FormatterHelper();
$this->data['start'] =
$formatter->FormatDate($this->Dating->Now());
$this->data['end'] = $formatter->FormatDate($this->Dating->Now());
if(!empty($_POST['whatever']))
{
$otsing = $this->$_POST['whatever'];
}
}
}
The select name should be wriiten like
data[Formname][selectname]
if you want to give it in HTML format or you should use cakephp way to define dropdwon:
<?php
echo $form->select(‘whatever’,$packs)
?>
I have copied the SesionHelper from the core into myapp/View/Helper so I can alter the div structure around the message outputted.
My problem is that I cant seem to detect if the message is an error or success message from the default cakephp message. I know I can set a flash message in my controller and add an attribute. But there doesn't seem to be any extra data that I can see from the core messages.
Example if the data is saved to the database i wish to show the message as green. Or if the data could not be saved then as red message.
public function flash($key = 'flash', $attrs = array()) {
$out = false;
if (CakeSession::check('Message.' . $key)) {
$flash = CakeSession::read('Message.' . $key);
$message = $flash['message'];
unset($flash['message']);
if (!empty($attrs)) {
$flash = array_merge($flash, $attrs);
}
if ($flash['element'] === 'default') {
$class = 'message';
if (!empty($flash['params']['class'])) {
$class = $flash['params']['class'];
}
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>';
} elseif (!$flash['element']) {
$out = $message;
} else {
$options = array();
if (isset($flash['params']['plugin'])) {
$options['plugin'] = $flash['params']['plugin'];
}
$tmpVars = $flash['params'];
$tmpVars['message'] = $message;
$out = $this->_View->element($flash['element'], $tmpVars, $options);
}
CakeSession::delete('Message.' . $key);
}
return $out;
}
What you are doing is reinventing the wheel as far as CakePHP is concerned.
You can specify an element as the second argument when you set a flash message in your controller method:
$this->Session->setFlash('Your record has been saved', 'flash_success');
Then in elements create an element Element/flash_success.ctp like this:
<div class="alert-success"><?php echo $message;?></div>
And finally in your view:
<?php echo $this->Session->flash()?>
Here is the section that deals with this in detail from the official documentation:
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages