Codeigniter pass form value as url segment - codeigniter

I have an issue with codeigniter. I want to pass a form value (from a dropdown) as URL segment in the next page. However I have searched high and low but could not find the solution.
Here is my view:
<?= form_open('admin_gallery_upload/upload_images/'); ?>
<?= form_label('Gallerij', 'gallery_id'); ?><br/>
<?= form_dropdown('gallery_id', $select_dropdown); ?>
<?= form_submit('submit', 'Volgende', 'class="submit"'); ?>
<?= form_close(); ?>
My controller:
function upload_images() {
$gallery_id = $this->input->post("gallery_id");
echo $gallery_id;
}
So instead of echoing the $gallery_id as done in the controller, it should become the third url segment

Try this and put select box id as gallery_id:
function redirectFunction(){
var val = document.getElementById("gallery_id").value;
alert(val); //see if alerts the correct value that is selected from the dropdown
window.location.href = '<?php echo base_url()?>admin_gallery_upload/upload_images/'+val;
}
Change the following lines, to add the id of the dropdown as I said,
$js = 'id="gallery_id" onChange="redirectFunction();"';
form_dropdown('gallery_id', $select_dropdown,'',$js);

You can pass in form open function extra parameter by default it is post see below code :-
<? $arr = array('method'=> 'GET');?>
<?= form_open('admin_gallery_upload/upload_images/',$arr); ?>
And get on controller using :-
$this->input->get();

Related

Codeigniter 4 Passing Array to view

Fairly new to codeigniter and i just cant find the right way to load an array into a view.
for example lets say i have an array like
$data = [
'title' => 'my title,
'desc' => 'my desc,
];
i can pass that to my view like
return view('myview',$data);
then simply echo it out in my view like
<h1><?= $title ?></h1>
<p><?= $desc ?></p>
That works fine. but now lets say i have another array like :
$moredata =[
'more_data' => 'some more data',
'even_more_data' => 'even more data',
];
if i try to add that to my data array like
$data[] = $moredata
when i try to access 'more_data' or 'even_more_data' in my view like
<?= $more_data ?>
i get a undefined variable error for $moredata. So how do i access the variables within that new array? am i declaring them properly?
also if i wanted to loop through the secondary array how do i do that. trying
<?php foreach($moredata as $items){ ?>
<li><?php echo $items; ?></li>
<?php } ?>
also gives me an undefined variable error for $moredata
any help on how to do this correctly in codeigniter 4 appreciated.
Codeigniter uses the key of the array you're giving him to create variables name.
You should init it this way :
$moredata =[
'more_data' => 'some more data',
'even_more_data' => 'even more data',
];
// key of your array will be a variable name in your view
$data['my_var_name_in_view'] = $moredata
return view('myview',$data);
Then in your view you will be able to perform this :
<?php foreach($my_var_name_in_view as $items){ ?>
<li><?php echo $items; ?></li>
<?php } ?>

Show Joomla article tags in override of newsflash module

We would like to create an override for the Joomla newsflash module which should be able to display the individual Joomla article tags on the frontend:
"tag 1, tag 2, tag 3 etc.."
RokSproket from rockettheme.com is able to achieve exactly that output. But we would like to have the same result with the newsflash module. We currently have the following code saved in our new _item.php override. There is no error message on the frontend but also no tags are visible. Any help is much appreciated.
<?php if ($params->get('show_tags', 1) && !empty($item->tags)) : ?>
<?php $item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $item->tagLayout->render($item->tags->itemTags); ?>
<?php endif; ?>
Here's how we've solved that question:
<?php
$itemtags = (new JHelperTags)->getItemTags('com_content.article', $item->id);
$taglayout = new JLayoutFile('joomla.content.tags');
$tags='';
if( !empty($itemtags) )
$tags = '<div class="itemtags">'.str_replace(',','',$taglayout->render($itemtags)).'</div>';
?>
<?php echo $tags; ?>

Codeigniter and Tank_auth sending validation to view not working

Hi I am new to Codeigniter but have hit a brick wall.
I am trying to see if a user already exists.
First I upload the data via a form to a controller which does its validation etc but breaks on only that issue. I managed to find where it breaks but cant fix it from there.
Prior to all this it querys the database finds there is in fact a match username and then reaches the snippet below
$errors = $this->tank_auth->get_error_message();
//find the correct error msg
foreach ($errors as $k => $v) $data['errors'][$k] =$this->lang->line($v);
//loop and find etc
$temp_mess = $data['errors'][$k];
//stores relevant stuff in the string
}
}
//echo $temp_mess; it outputs to the html so i can see it "says user exists"
$data['temp_mess'] = $tempmess; /// put this into a array
$this->load->view('layout', $data); ///send
}
}
Now for the view, it then calls the layout view etc but alas there is no output
$username1 = array(
'name' => 'username1',
'id' => 'username1',
'value' => set_value('username1'),
'maxlength' => $this->config->item('username_max_length', 'tank_auth'),
'size' => 30,
);
<?php echo form_open('register', $form_reg_id ); ?>
<fieldset>
<legend align="center">Sign up</legend>
<?php echo form_label('Username', $username1['id']); ?>
<?php echo form_input($username1); ?>
<?php $tempmess; ?>
<div class="error"><?php echo form_error($username1['name']); ?>
<?php echo isset($errors[$username1['name']])?$errors[$username1['name']]:''; ?>
<?php echo form_close(); ?>
</fieldset>
Thanks for any help on this
also could some one explain this line please. (for a really dumb person)
<?php echo isset($errors[$username1['name']])?$errors[$username1['name']]:''; ?>
Tank_auth automatically returns an error when the username exists. Juste have to check the errors array.

Wordpress The Events Plugin wp_query not paginating

I've got an issue with Modern Tribe's "The Events Calendar" plugin not paginating properly. It displays the first page fine, but refuses to go to any secondary pages (using wp-pagenavi). Ideally, I'm trying to have it load via AJAX, but at this point pagination would be a miracle. I've exhausted an entire day here. Basically, this is the query:
<?php
$wp_query = new WP_Query();
$wp_query->query( array(
'post_type'=> 'tribe_events',
'eventDisplay' => 'upcoming',
'posts_per_page' => 5)
);
$max = $wp_query->max_num_pages;
$paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) :
$wp_query->the_post();
?>
<li><!-- do stuff --> </li>
<?php
endwhile;?>
</ul>
<?php
endif;
wp_reset_query(); // important to reset the query
?>
There are quite a number of issues with your loop:
You say you're using wp_page_navi, however I'm not seeing any references to the plugin in any of your code. Also, you have list items being generated in your loop along with a closing ul tag, but I don't see any opening ul tag anywhere, which could also be contributing to some of your problems.
I'm also noticing in your list of arguments that you're trying to set 'eventDisplay' to 'upcoming'. 'eventDisplay' is not a valid WP_Query parameter. I'm guessing you probably have a registered Taxonomy of eventDisplay? If so, you will need to use Tax Query instead. I've removed this parameter in the example, but feel free to replace it when you're comfortable with setting the parameters you need.
Lastly, query arguments should be made when you call WP_Query, not through $query->query.
Here's something I came up with using standard Wordpress Paging and the arguments you have in your code. I'm not familiar with wp_page_navi, but this should help get you started on the right track:
<?php
global $paged;
$curpage = $paged ? $paged : 1;
$query = new WP_Query(array(
'post_type'=> 'tribe_events',
'paged' => $paged,
'posts_per_page' => 5
));
if ($query->have_posts()) :
?>
<ul>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php
echo '<div id="wp_pagination">';
echo '<a class="first page button" href="'.get_pagenum_link(1).'">«</a>';
echo '<a class="previous page button" href="'.get_pagenum_link(($curpage-1 > 0 ? $curpage-1 : 1)).'">‹</a>';
for($i=1;$i<=$query->max_num_pages;$i++)
{
echo '<a class="'.($active = $i == $curpage ? 'active ' : '').'page button" href="'.get_pagenum_link($i).'">'.$i.'</a>';
}
echo '<a class="next page button" href="'.get_pagenum_link(($curpage+1 <= $query->max_num_pages ? $curpage+1 : $query->max_num_pages)).'">›</a>';
echo '<a class="last page button" href="'.get_pagenum_link($query->max_num_pages).'">»</a>';
echo '</div>';
endif;
wp_reset_query();
?>
This will set your loop to display 5 post titles in your list. Below it will be a series of numbered links based on how many posts you have. When you click on a number, it reloads the page with its corresponding titles.
Let me know if this helps.

Best way for creating dynamic sidebar section in Symfony 1.4

I have few frontend modules which has own sidebar menu link. I want to create those links in actions class of module:
public function preExecute()
{
$items['plan/new'] = 'Create Plan';
$items['plan/index'] = 'Plans Listing';
$this->getResponse()->setSlot('sidebar', $items);
}
Slot file sidebar.php
#apps/frontend/templates/sidebar.php
<?php slot('sidebar') ?>
<ul>
<?php foreach($items as $url => $title) : ?>
<li><?php echo link_to($url, $title) ?></li>
<?php endforeach ?>
</ul>
<?php end_slot() ?>
layout.php:
<?php if (has_slot('sidebar')): ?>
<div id="sidebar"><?php include_slot('sidebar') ?></div>
<?php endif ?>
but my output is Array, how can I render my slot?
You seem to be mixing slots and partials. In your action, you set your slot to an array, later you call include_slot, and the string representation is Array, that is correct.
You should pass items via $this->items = $items, then in your action see if isset($items) is true, and call include_partial("sidebar", array("items" => $items)) if neccesary. This will look for a file called _sidebar.php.
For more detailed information of how this stuff works, read the Inside the View Layer: Code fragments part of the sf1.4 book.

Resources