how to make navigation dropdown menu in Pyro CMS - php

I have file "header.html" in partial folder, here my code
<ul class="sf-menu" id="mainMenu">
{{ shoesmart:showMenu group="header" indent="tab"}}
<li>{{ name }}
{{ if children }}
<ul>
{{ children }}
<li>{{ name }}</li>
{{ /children }}
</ul>
{{ endif }}
</li>
{{/shoesmart:showMenu}}
</ul>
and I have file "shoesmart.php" in plugins folder, here my code :
function showMenu()
{
$return = '';
$menu_list = $this->db->select('*,CONCAT(pua.type,"/",pua.keyword) as path',false)
->from('menu mn')
->join('product_url_alias pua','mn.url_alias_id=pua.url_alias_id','LEFT')
->where('status',1)
->get()
->result_array();
foreach ($menu_list as $result) {
$return[] = array(
'name' => $result['name'],
'url' => BASE_URL.'home/'.$result['path']
);
}
return $return;
}
and my table name in database is "default_menu" that have structure:
menu_id url_alias_id name status parent_id
1 868 Men 1 0
2 869 woman 1 0
but when I refresh in browser, just show main menu, its mean that the submenu didn't show. Should I change my code ? or I also add new table for submenu in my database ?So please help me .. I have deadline project tomorrow T.T

Related

How can I fetch/print the path or url of an entity reference to my twig template (Drupal 8)?

I have been trying to figure out how I can pull the url of a node content type using an entity reference.
Apparently using {{ links.entity.uri }} or {{ links.entity.url }} does not work
<div>
{% for links in node.field_related_items %}
<h2>{{ links.entity.label }}</h2>
<a href="{{ links.entity.uri }} " ></a>
{% endfor %}
</div>
This worked for me:
This will only take you to /node/entity_id though and not /entity_name/entity_id
I would like to expand upon this answer by saying that you should add a Drupal::entityQuery() to your .theme file. Inside of this query, you'll want to grab the "alias" which is the link to the content. In your case this will give you these links /migrations and /aboutiom.
Here's an example of what that might look like...
function theme_name_preprocess_node(&$variables) {
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'related_links')
$nids = $query->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
$related_links = [];
foreach ($nodes as $item) {
$alias = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$item->id());
$related_links[] = [
'title' => $item->getTitle(),
'id' => $item->id(),
'field' => $item->get('field_name')->value,
'alias' => $alias,
];
}
$variables['related_links'] = $related_links;
}
Now in your twig template you can do something like this...
{% for link in related_links %}
{{ link['title'] }}
{% endfor %}

RainLab blog - OctoberCMS - Show posts from specific category

I've found the following code in Posts.php - I think I essentially need to duplicate this and turn it into a public function limiting the category to a sepcific ID. Although that seems overkill? Can I query the current function on the front end?
Here's the posts.php code:
protected function listPosts()
{
$category = $this->category ? $this->category->id : null;
/*
* List all the posts, eager load their categories
*/
$isPublished = !$this->checkEditor();
$posts = BlogPost::with('categories')->listFrontEnd([
'page' => $this->property('pageNumber'),
'sort' => $this->property('sortOrder'),
'perPage' => $this->property('postsPerPage'),
'search' => trim(input('search')),
'category' => $category,
'published' => $isPublished,
'exceptPost' => $this->property('exceptPost'),
]);
/*
* Add a "url" helper attribute for linking to each post and category
*/
$posts->each(function($post) {
$post->setUrl($this->postPage, $this->controller);
$post->categories->each(function($category) {
$category->setUrl($this->categoryPage, $this->controller);
});
});
return $posts;
}
on the front end is this:
{% for post in posts %}
<li>
<h3>{{ post.title }}</h3>
</li>
{% else %}
<li class="no-data">{{ noPostsMessage }}</li>
{% endfor %}
Could someone point me in the right direction?
Cheers,
Not sure what you want to achieve. You just want to show posts from specific category only?
Set the parameter "category filter" of your blogPosts component to the slug of specific category
[blogPosts newsList]
pageNumber = "{{ :page }}"
categoryFilter = "news"
postsPerPage = 100
noPostsMessage = "No posts found"
sortOrder = "published_at desc"
categoryPage = "blog/category"
postPage = "blog/post"
==
{% component 'newsList' %}
this will show posts only from "news" category

PHP - "n" number of children in a list

This question is in relation to: Group by in Laravel 5
Essentially, what I have have is a series of "Groups" and each group can have a as many child groups as they want. So it could look something like this:
Group 1
Group 1 Child
Group 1's child
Group 1 1's Child
Group 2
At the moment, I am only able to display the group, and their children, using:
<ul>
#foreach($contents as $content)
<li>{{$content->title}}</li>
#if($content->children->count() > 0)
<ul>
#foreach($content->children as $childContent)
<li>{{$childContent->title}}</li>
#endforeach
</ul>
#endif
#endforeach
</ul>
If I want to add more layers of children, I have to code this, with another if statement as well as a foreach statement. Obviously this is not practical when a group has n^3,... number of children.
Is there a dynamic, while-loop approach to solving this problem? Any help would be greatly appreciated!!
What you need is a recursive partial - a one that would load itself as long as there are some more group levels to be displayed.
// list_group.blade.php
<li>
{{ $content->title }}
#if($content->children->count() > 0)
<ul>
#foreach($content->children as $childContent)
#include('list_group', array('content' => $childContent))
#endforeach
</ul>
#endif
</li>
//in your template
<ul>
#foreach($contents as $content)
#include('list_group', array('content' => $content))
#endforeach
</ul>

Full text search in laravel 4 across multiple tables

I have a project which I am working on which requires full text searching on multiple tables in a database. I found a useful tutorial here:
http://creative-punch.net/2013/12/implementing-laravel-4-full-text-search
I have got it to work on one table, but now wish to extend to more than one. The issue I am having is that; if duplicate what is there for the remainder of the tables, when I hit submit, how do I get the button to check more than one controller ? or modify existing controller to check multiple tables ?
code
default view form
<div class="search">
{{ Form::model(null, array('route' => array('search'))) }}
{{ Form::text('query', null, array( 'placeholder' => 'Search query...' )) }}
{{ Form::submit('Search') }}
{{ Form::close() }}
</div>
returned view
<div class="search">
{{ Form::model(null, array('route' => array('search'))) }}
{{ Form::text('query', null, array( 'placeholder' => 'Search query...' )) }}
{{ Form::submit('Search') }}
#foreach($posts as $post)
<li>{{ $post->instance_id }}</li>
<li>{{ $post->instance_type }}</li>
<li>{{ $post->availability_zone }}</li>
<li>{{ $post->status_checks }}</li>
<li>{{ $post->alarm_status }}</li>
<li>{{ $post->public_dns }}</li>
<li>{{ $post->key_name }}</li>
#endforeach
{{ Form::close() }}
</div>
controller class
<?php
class PostsController extends BaseController {
public function postSearch(){
$q = Input::get('query');
$posts = ec2_instance::whereRaw("MATCH(instance_id,instance_type,availability_zone, status_checks,alarm_status, public_dns, key_name ) AGAINST(? IN BOOLEAN MODE)",
array($q))->get();
View::share('posts', $posts);
return View::make('ec2_instance', compact('posts'));
}
}
?>
my initial thought is to modify the controller such that you add :
$ip_address = public_ip::whereRaw("MATCH(ip_address) AGAINST(? IN BOOLEAN MODE)",
array($q))->get();'
then in the view add
#foreach($ip_address as $ip)
<li>{{ $ip->ip_address}}</li>
#endforeach
however variable ip_address could not be found
I was returning 2 views which is not possible do as per my initial thoughts ensuring you only return 1 view ie
$posts = ec2_instance::whereRaw("MATCH(instance_id,instance_type,availability_zone, status_checks,alarm_status, public_dns, key_name ) AGAINST(? IN BOOLEAN MODE)", array($q))->get();
$ip_address =
public_ip::whereRaw("MATCH(ip_address ) AGAINST(? IN BOOLEAN MODE)", array($q))->get();
$s3_bucket =
s3_bucket::whereRaw("MATCH(name, storage_class, size ) AGAINST(? IN BOOLEAN MODE)", array($q))->get();
$cloudfront_distribution = cloudfront_distribution::whereRaw("MATCH(delivery_method, cloudfront_id, domain_name,comment, origin, c_name, status, state ) AGAINST(? IN BOOLEAN MODE)", array($q))->get();
return View::make('ec2_instance', compact('ip_address', 'posts','s3_bucket', 'cloudfront_distribution'));

Fat Free Framework: how create dynamic menu with submenu

I have this table
id children voce alias pubblicato
11 NULL Chi Siamo chi-siamo 1
12 11 Chi Siamo - Sub chi-siamo-sub 1
So the id 12 is children (submenu) of 11.
With this block i can print the first level of a menu
<repeat group="{{ #result }}" key="{{ #ikey }}" value="{{ #voce }}">
<li>{{ trim(#voce.voce) }}</li>
</repeat>
(result is result of query SQL).
Of course i need to obtain that in my scheme menu will be (pseudo // bootstrap html code)
<li>ID 11 menu
<ul class="dropdown-menu">
<li>Id 12 menu</li>
</ul>
So, in (very!) pseudo code
if (children is not null) {
don't echo </li>
echo <ul class="dropdown">
echo voce where children == parent
}
Thank you very much.
PS If you think that my table need to be edit, don't worry, tell me your best solution!
i did this the following way:
// load page tree
$pages = $model->find();
$pageTree = array();
$pagesByID = array();
foreach($pages as $index => $page)
$pagesByID[$page->_id] = $page->cast();
// reorder to tree
foreach ($pagesByID as &$value)
if ($parent = $value['pid'])
$pagesByID[$parent]['childs'][] = &$value;
else
$pageTree[] = &$value;
$pageTree is now a multi-dimensional array, with child keys, if that page has some childs.

Categories