i am using laravel 5.6 with this youtube api
https://github.com/alaouy/Youtube
i am trying to search result with paginate like this
$params = [
'q' => $request,
'type' => 'video',
'part' => 'id, snippet',
'maxResults' => 20
];
// $search = Youtube::searchAdvanced($params, true);
$search = Youtube::paginateResults($params, null);
$info = $search['info'];
$nextpagetoken = $info['nextPageToken'];
return view('search.index', compact('search'));
and my view
#foreach($search as $result)
#foreach($result as $video)
{{ dd($video->snippet->title) }}
#endforeach
#endforeach
my result
but problem is when i use {{ $video->snippet->title }} getting error
You're trying to access title as an object, but it is an array.
I would try with something like:
$video->snippet['title']
(Sorry for not using Markdown syntax, I'm using my smartphone for this answer)
I guess that dd() is smart enough to know the difference between the two and display both of them properly.
When i dd($search);check i am getting 2 array
array:2 [▼
"results" => array:20 [▶]
"info" => array:6 [▶]
]
so i use
$results = $search['results'];// for videos only
$info = $search['info']; // For Other info's
now i can use foreach in view
#foreach($results as $video)
<div class="row boxhead">
<div class="col-md-4">
<a href="{{ url('watch/' . $video->id->videoId)}}">
<img src="{{$video->snippet->thumbnails->medium->url}}" class="img-fluid">
</a>
</div>
<div class="col-md-8">
<a href="#">
<h1 style="font-size: 17px;">{{ $video->snippet->title }}</h1>
<p>{{ $video->snippet->channelTitle }}</p>
<p>{{ $video->snippet->description }}</p>
</a>
</div>
</div>
<hr>
#endforeach
its works fine
Related
I want to display data from 2 different tables which are stored in ViewBag at view side but I'm unable to print the data, I get an error
'object' does not contain a definition for 'Name'
The code at controller side
public ActionResult Packages()
{
int Prov_id = 1;
using (var db = new DataContex())
{
ViewBag.pack = db.Packages.Where(x => x.ProviderId == Prov_id).ToList();
ViewBag.service = db.GroupServices.Join(db.PackageServices,
gs => gs.ServiceId,
ps => ps.ServiceId,
(gs, ps) => new
{
name = gs.ServiceName
})
.ToList();
return View();
}
View markup:
#foreach (var item in ViewBag.pack)
{
<div class="col-md-6 bg-white mt-3">
<div class="card border package-grid p-3">
<div class="row">
<div class="col-md-8">
<input type="hidden" />
<h4 class="font-weight-bold py-2">#item.PackageName</h4>
#foreach (var item1 in ViewBag.service)
{
<h6 class="py-1">#item1.Name</h6>
}
<p class="py-3">#item.PackageDescription</p>
</div>
</div>
<div class="row">
<div class="col-md-12 mt-3 d-flex justify-content-between flex-wrap">
<p><strike> Rs. #item.PackagePrice</strike> <span>Rs. #item.PackageOfferPrice</span> </p>
<span>Remove</span>
</div>
</div>
</div>
</div>
}
That is because when you created ViewBag.service you have created anonymous object with property as name with n as LowerCase and at view side you are trying to use #item.Name as N as UpperCase.
Correct the property name and it will work.
I am buidling a mvc web application with entity framework.
Error:
An exception of type 'System.ObjectDisposedException' occurred in
EntityFramework.dll but was not handled in user code
Additional information: The ObjectContext instance has been disposed
and can no longer be used for operations that require a connection.
This is the entity framework part:
Like you see I already include "Alineas" and do .ToList()
public IList<Kop> Handle(RetrieveKoppenForDocumentQuery query)
{
using (var db = new BmDataContext())
{
var koppen = db.Kop.Where(s => s.Document.Id == query.Id)
.Include(s => s.TegelAfbeelding)
.Include(s => s.CollageAfbeeldingen)
.Include(s => s.FinancieleAfbeeldingen)
.Include(s => s.Alineas)
.ToList();
return _orderKoppenByIndex(koppen);
}
}
This is the view KopListItems.cshtml:
#using PGE.Bestuursmonitor.Contracts.DataTypes
#model IList<Kop>
#* Helper for recursively rendering koppen*#
#helper SortableItem(Kop kop)
{
<div class="sortable-item" data-kopid="#kop.Id">
<div class="row">
<div class="col-md-7 title-column">
<i class="fa fa-arrows"></i> #kop.Titel
</div>
<div class="col-md-5">
<div class="col-md-3">
<span>
#kop.KopType
</span>
</div>
<div class="col-md-3">
<span>
#kop.Status
</span>
</div>
<div class="col-md-6">
<span class="pull-right">
#if (#kop.Alineas != null) // on this line I receive the exception
{
// here I would like to do some logic
}
</span>
</div>
</div>
</div>
<div class="sortable-container">
#foreach (var subKop in kop.Koppen)
{
#SortableItem(subKop);
}
</div>
</div>
}
#* Recursively render all kop items *#
<div id="koppen_sortable" class="sortable-container">
#foreach (Kop kop in Model)
{
#SortableItem(kop);
}
</div>
This is the view KoppenList.cshtml:
#model PGE.Bestuursmonitor.ViewModels.Koppen.IKoppenListViewModel
<h1>#Model.DocumentTitel</h1>
#* Render kop list header *#
<div id="koppen_sortable_header">
<div class="row">
<div class="col-md-7"><strong>Titel</strong></div>
<div class="col-md-5">
<div class="col-md-3">
<strong>Type</strong>
</div>
<div class="col-md-3">
<strong>Status</strong>
</div>
<div class="col-md-6">
<span class="pull-right">
<button type="button" id="btn_add_sub" class="btn btn-success" title="Kop aanmaken" role="button" onclick="BM.Koppen.LoadAddKopView(null);">
<i class="fa fa-plus fa-lg"></i> Kop aanmaken
</button>
</span>
</div>
</div>
</div>
</div>
<div id="koppen_sortable_body">
#{ Html.RenderPartial("~/Views/Koppen/KopListItems.cshtml", #Model.Koppen); }
</div>
#* Store document id in html DOM, so javascript can reach it from multiple places *#
<input type="hidden" id="document_id" value="#Model.DocumentId" />
Action in controller:
[HttpGet]
public ActionResult KoppenList(string id)
{
ViewBag.PageId = id;
Document document = _retrieveStartPcDocumentQueryHandler.Handle(new RetrieveStartPcDocumentQuery());
RetrieveKoppenForDocumentQuery query = new RetrieveKoppenForDocumentQuery
{
Id = document.Id
};
IList<Kop> koppen = _retrieveKoppenForDocumentQueryHandler.Handle(query);
_koppenListViewModel.Koppen = koppen;
_koppenListViewModel.DocumentTitel = document.Titel;
_koppenListViewModel.DocumentId = document.Id;
return View("~/Views/Koppen/KoppenList.cshtml", _koppenListViewModel);
}
Like you see in KopListItems.cshtml there are 2 foreach loops. The outer foreach loop is working fine and can read "Alineas". The inner foreach which shows the sub items gives this strange error. What is going wrong? Im stuck.
This is the solution. You need to get the alineas and content also on sub level:
public IList<Kop> Handle(RetrieveKoppenForDocumentQuery query)
{
using (var db = new BmDataContext())
{
var koppen = db.Kop.Where(s => s.Document.Id == query.Id)
.Include(s => s.TegelAfbeelding)
.Include(s => s.CollageAfbeeldingen)
.Include(s => s.FinancieleAfbeeldingen)
.Include(s => s.Alineas.Select(a => a.Content))
.Include(s => s.Koppen.Select(k => k.Alineas.Select(a => a.Content)))
.Include(s => s.Koppen.Select(k => k.Koppen.Select(x => x.Alineas.Select(a => a.Content))))
.ToList();
return _orderKoppenByIndex(koppen);
}
}
Consider the following nested ng-repeat directives:
<tr ng-repeat="r in SomeExpr1">
<td ng-repeat="c in SomeExpr2">
<p>c index is {{$index}}, r index is {{???}}</p>
</td>
</tr>
How can I access the $index of the outer ng-repeat (i.e., the one in the parent scope that is hidden by the inner ng-repeat scope $index)?
As #Randal Schwartz pointed out in this post $parent does the trick.
<div ng-controller='demo-ctrl'>
<div ng-repeat="row in ctrl.matrix">
<div ng-repeat="column in row">
<span>outer: {{$parent.$index}} inner: {{$index}}</span>
</div>
</div>
</div>
You need ng-init from Angular.js. Sadly, that hasn't been ported yet, but it would look like this if it worked:
<script>
function Ctrl($scope) {
$scope.list = [['a', 'b'], ['c', 'd']];
}
</script>
<div ng-controller="Ctrl">
<div ng-repeat="innerList in list" ng-init="outerIndex = $index">
<div ng-repeat="value in innerList" ng-init="innerIndex = $index">
<span class="example-init">list[ {{outerIndex}} ][ {{innerIndex}} ] = {{value}};</span>
</div>
</div>
</div>
(via http://docs.angularjs.org/api/ng/directive/ngInit)
CONTROLLER:
public ActionResult Index()
{
SonerSevincComEntities context = new SonerSevincComEntities();
var Konular = context.Konu.ToList();
return View(Konular);
}
VİEW:
<div class="primary">
#foreach (var item in Model)
{
<h2>
<a href="Subject?SubjectId=
#Html.DisplayFor(model => item.Id)">
#Html.DisplayFor(model => item.Baslik)</a>
</h2>
<p class="post-info">
<a href="Subject?Tag=
#Html.DisplayFor(model =>item.Etiket)">
#item.Etiket.Split(',').ToString()</a>
</p>
<div class="image-section">
<img src="#Html.DisplayFor(model => item.Resim)"
alt="image post" height="206" width="498" />
</div>
<p>
<a class="more" href="Subject?SubjectId==
#Html.DisplayFor(model => item.Id)">Devamı »</a>
</p>
}
</div>
I want to split under side for (',')
#item.Etiket.Split(',').ToString()
When i run program , i see this code..
System.String[] in stead of Etiket
I tried to solve this with foreach Etiket.Split but id did not work .
How can i solve this problem in View?
<a href="Subject?Tag=
#Html.DisplayFor(model =>item.Etiket)">
#item.Etiket.Split(',').ToString()</a>
it should be like following as you said in your comment
<a href="Subject?Tag=
#Html.DisplayFor(model =>item.Etiket)">
#foreach(var x in item.Etiket.Split(','))
{
#x
}
</a>
String.Split: Returns a string array that contains the substrings in this string that are delimited by elements of a specified string array.
So what you are getting is correct output as per code.
You can try to display first element of substring
#item.Etiket.Split(',')[0]
I want to create a custom template for ListView (I show products eShop in ListView). I wrote this code:
<script type="text/x-kendo-tmpl" id="template">
<div class="item">
<div class="image">
<a href='#Url.Action("GetDetails", "Products", routeValues: new {id =${ProductID}} )' target='_blank' class='pimg'>
<img src="${ProductThumbnailImageUrl}" alt=" ${ProductTitle}"/>
</a>
<div class="price"> ${kendo.toString(ProductPrice, "n0")} </div>
<div class="name">
</div>
<div class="description_featured" style="min-height: 110px;">
${ProductDescription}
</div>
</div>
</div>
</script>
#(Html.Kendo().ListView(Model)
.Name("listView")
.TagName("div")
.ClientTemplateId("template")
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action("Products_Read", "Products"));
dataSource.PageSize(12);
dataSource.ServerOperation(false);
})
.Pageable()
)
I get an error on new {id = ${ProductTitle}}.
This is how you use templates.
This is one on the template i recently used for my web site.
<script type="text/x-kendo-tmpl" id="template">
<div class="product">
<img src='http://cdn.rbgx.net/images/skybazaar/products/medium/${ImageFileName}' alt="${Name} image" />
<div class="productDeatails">
<h3>#:Name#</h3>
# if (EntityType == 2) { #
Click to see products of this category
# } else if(EntityType == 1) { #
# if(parseFloat(SalePrice) > 0 && parseFloat(SalePrice) < parseFloat(Price)) { #
Sale Price #: kendo.toString(SalePrice, "c")#
# } else { #
Price #: kendo.toString(Price, "c")#
# } #
# } #
</div>
</div>
</script>
in your case for ${ProductTitle}
use #: ProductTitle #