slug its not working in codeigniter - php

i want url slug like this
tkd/index.php/article/77/Kejurnas-2013
but when i click button like this
tkd/index.php/article/77/Kejurnas%202013
what wrong with my code. this is my view
<div class="post-buttons-wrap">
<div class="post-buttons">
<a href="<?php echo base_url('index.php/article/' . intval($dt->id) . '/' . e($dt->slug)) ; ?>" class="ui black label">
Read More
</a>
</div><!-- end .post-buttons -->
</div>
and this is my controller
public function index()
{
$this->data['berita'] = $this->mberita->get_berita();
$this->data['halaman'] = $this->mhalaman->get_profil();
dump('Page!');
// Fetch the page template
$this->data['page'] = $this->page_m->get_by(array('slug' => (string) $this->uri->segment(1)), TRUE);
count($this->data['page']) || show_404(current_url());
// Fetch the page data
$method = '_' . $this->data['page']->template;
if (method_exists($this, $method)) {
$this->$method();
}
else {
log_message('error', 'Could not load template ' . $method .' in file ' . __FILE__ . ' at line ' . __LINE__);
show_error('Could not load template ' . $method);
}
$this->data['contents'] = $this->data['page']->template;
$this->load->view('template/wrapper_mahasiswa', $this->data);
}
please help me what to do. thank you.

You have to use the helper "URL" and use the functions "url_title()" and "convert_accented_characters()" if you need to convert some special characters.
http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html for more info
Example:
In your controller code, you will capture your form inputs. then you have to create the slug with a line like this:
$event['slug'] = url_title(convert_accented_characters($event['eventName']),'-',TRUE);
This line will return you a slug separated by "-", setting all the words to lowercase and deleting all special characters too.

try this- use rawurlencode while working with strings in url-
<a href="<?php echo base_url('index.php/article/' . intval($dt->id) . rawurldecode('/') . e($dt->slug)) ; ?>" class="ui black label">
Read More
</a>

Related

return acf image src in twig

i cant get the acf images to return.
in my single-work.twig (view file) i have
<img src="{‌{ Image(post.meta(‘laptop_image')).src }}" />
and in the single-work.php (controller file) template i have
$context[‘laptop_image'] = get_field(‘laptop_image’);
i also tried
in single-work.php (controller file)
$post->laptop_image = new Timber\Image($post->laptop_image);
in single-work.twig (view file)
<img src="{‌{ post.laptop_image.src | resize(500, 300) }}" />
most of the time i get “unknown” as the result.. I used to get the image id returned but i cant remember how i got that… Any help would be great.
full single-work.php
$context = Timber::context();
$timber_post = Timber::query_post();
$context['post'] = $timber_post;
$context['text_with_image_title'] = get_field('headline');
$context['text_with_image_text'] = get_field('description');
$post->laptop_image = new Timber\Image($post->laptop_image);
$context['ipad_image'] = get_field('ipad_image');
$context['iphone_image'] = get_field('iphone_image');
$context['text_with_image_btn_link'] = get_field('work_url');
$context['text_with_image_btn_label'] = 'Go to ' . $timber_post->post_title . ' Website';
$context['text_with_image_btn_target'] = '_blank';
if ( post_password_required( $timber_post->ID ) ) {
Timber::render( 'single-password.twig', $context );
} else {
Timber::render( array( 'single-' . $timber_post->ID . '.twig', 'single-' . $timber_post->post_type . '.twig', 'single-' . $timber_post->slug . '.twig', '/pages/single-work.twig' ), $context );
}
var_dump($post->laptop_image); //returns image id
full code of work.twig
<div class="col-6 text-with-image__column text-with-image__column--image">
<div class="text-with-image__wrapper">
<img src="{{ post.laptop_image.src | resize(500, 300) }}" />
{{dump(post.laptop_image)}} //returns nothing
</div>
</div>
i realized i was using a macro and therefore
<img src="{‌{ Image(post.laptop_image).src }}" /> works fine, though it needs to be applied as the macro value of the new instance. Not just apart of the template.

Creating re-usable ACF fields that can be inside various elements/classes

I have the following code which is inside its own file, which gets an ACF field and outputs it.
<?=get_field('text') ?>
I then include this in another template file using PHP include, meaning I have re-usable fields throughout my site. This has worked well in the past, as I can create consistent 'text' fields such as: <h1>My Text field</h1>
However, I'd like to further extend this by writing some kind of fucntion that allows me to call the PHP include, whilst also assigning the container tag (h1,h2 etc), as well as optional classes:
<h1>My Text field</h1>
<h2>My Text field</h2>
<p>My Text field</p>
<h1 class="myClass">My Text field</h1>
Is this possible?
You can do it this way:
<?php
class functions{
public static function get_field($text = 'Default', $tag = 'p', $class = false){
if($class){
$class = ' class="' . $class . '"';
}
return '<' . $tag . $class . '>' . $text . '</' . $tag . '>';
}
}
echo functions::get_field('My Text', 'h1', 'my-class');
?>
in HTML
<h1 class="my-class">My Text</h1>
Hope it will give you an idea on how to expand this method.

placeholder picture wordpress

How to display a placeholder image if there's no image set up in WordPress? The picture is displayed by the $property_image var. It is a featured image from a custom post (not a WordPress original one).
It is defined by the code below, displays the featured image of the post if set up, if not, only shows the alt tag content ("Upcoming picture..."):
$property_image = dreamvilla_mp_get_device_image($property_ID);
Below my code from a WordPress theme:
$html .= '<div class="property-list-list property-listing-list-full">
<div class="col-xs-12 col-sm-4 col-md-4 property-list-list-image">
<a href=' . esc_url(get_permalink($property_ID)) . '>
<img '. $property_image . ' alt="Upcoming picture..." class="img-responsive">
</a>
' . $featured_proeprty_label . '
' . $featured_proeprty_label_icon . '
' . dreamvilla_mp_agent_favorites_property_icon($property_ID) . '
</div>
I'd place this:
if( empty( $property_image ) ) {
$property_image = 'src="your_fallback_image"';
}
directly after:
$property_image = dreamvilla_mp_get_device_image($property_ID);
What to be used to determine if the variable is empty depends on what is stored in the variable.
Directly before the img tag, you could insert this:
<?php
if($property_image == '') {
$property_image ="scr='http://placehold.it/300x200/f0a'";
}
?>
It checks whether that variable is empty and if yes, puts a links to a placeholder image into it, including the src attribute.

How to hide logo in product page in Open Cart?

I need to hide logo in product page. Logo is placed in header HTML.
So, I tried to add new variable $data['product_page_logo'] in header.php controller before loading template like as:
$data['product_page_logo'] = false;
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/header.tpl', $data);
} else {
return $this->load->view('default/template/common/header.tpl', $data);
}
After in header.tpl I check this variable:
<? if(isset($data['product_page_logo']) && $data['product_page_logo'] == false) {
echo "Logo";
}?>
But it does not work, I get error undefined variable product_page_logo
You can use route, in catalog/controller/common/header.php find:
$class = '-' . $this->request->get['product_id'];
before or after it add:
$data['logo'] = '';
tested on opencart 2.3.0.2

Not Picking Up Image If False

In my codeigniter form, I am trying to set an else if for my data image. Currently it picks up if when image exists. But need it to pick up my no_image.png, if no image exist using the same code below.
<?php
class Users extends MX_Controller {
public function index() {
$this->getForm();
}
protected function getForm($user_id = 0) {
$this->load->model('admin/user/users_model');
$user_info = $this->users_model->getUser($user_id);
if (trim($this->input->post('image'))) {
$data['image'] = $this->input->post('image');
} elseif (!empty($user_info)) {
// This Location Image Works Fine.
$data['image'] = config_item('base_url') . 'image/catalog/' . $user_info['image'];
} else {
// Should Display If No Image Present In Database Does Not Work.
$data['image'] = config_item('base_url') . 'image/'. 'no_image.png';
}
}
$this->load->view('user/users_form', $data);
}
View Page :
<div class="form-group">
<label for="input-image" class="col-lg-2 col-md-12 col-sm-2 col-xs-12"><?php echo $entry_image; ?></label>
<div class="col-lg-10 col-md-10 col-sm-10 col-xs-12">
<a href="" id="thumb-image" data-toggle="image" class="img-thumbnail">
<img src="<?php echo $image; ?>"/>
</a>
</div>
</div>
Make sure that in image folder the no_image.png exists. And it is accessible directly.Like
, you can try directly open the link in your browser as http://www.yoursiteurl/image/no_image.png.
If it opens then there is two possibilities
in your config file there is no end slash for baseurl.
The code never executes the else block
If the dierct link does not open then a htaccess problem may exists.
Hope this will help you.
Or your elseif condition may be like this
elseif(!empty($user_info) && $user_info['image'] && file_exists(config_item('base_url') . 'image/catalog/' . $user_info['image'])){
...
}
// + so your user info is valid but user picture is not available
I had to create a if statement below to make it work for no_image.png now works this way.
if (trim($this->input->post('image'))) {
$data['image'] = $this->input->post('image');
} elseif (!empty($user_info)) {
$data['image'] = config_item('base_url') . 'image/catalog/' . $user_info['image'];
} else {
$data['image'] = '';
}
if ($user_info['image'] == FALSE) {
$data['image'] = config_item('base_url') . 'image/'. 'no_image.png';
}

Categories