Im wondering how to achieve the following:
I have this Session Container created by a factory:
$container = new Container('Fans');
$container->setExpirationSeconds('219867583');
return $container;
then i'm creating an instance in my controller like this:
$this->sessionService = $this->getServiceLocator()->get('SessionService');
Now i want to add something to the Session:
This one works fine:
$this->sessionService->team = 'TEST';
But what i want to achieve is the following
$this->sessionService->team[0] = 'Team Name 0' // This doesn't work;
$this->sessionService->team[1] = 'Team Name 1' // This doesn't work;
\Zend\Debug\Debug::dump($this->sessionService->team);
The Output looks like this:
<pre>string(9) "TEST" </pre>
I don't know if i misunderstood something or do something wrong.
Does anybody know how to do it right ?
This is a problem with the magic __get() functionality in PHP. Because Zend\Session uses __get() to supply access to session variables, you cannot access them like arrays. What does work, is the following:
$team = array();
$team[0] = 'Team Name 0';
$team[1] = 'Team Name 1';
$this->sessionService->team = $team;
How about using an array?
$teams = array();
$session->teams = $teams;
$session->teams[0] = 'blubb';
If you first assign it to be a string, it will remain a string. Make it an array and use it as an array, too ;)
Related
I'm trying to save my IContent called child, but on this line(contentService.SaveAndPublish(child);) I get the following error: Object reference not set to an instance of an object.
if (child.HasProperty("navn"))
{
child.SetValue("navn", worker.Name.ToString(), "da-dk");
}
contentService.SaveAndPublish(child);
This is how I define my contentService:IContentService contentService = Umbraco.Core.Composing.Current.Services.ContentService;
And I'm finding the children like this:
long totalChildren;
IEnumerable<IContent> children = contentService.GetPagedChildren(filialsParent.Id, 0, 100, out totalChildren);
´
Can someone point out what is wrong here?
I found out that if I do this then it works.
var umbf = Umbraco.Web.Composing.Current.Factory.GetInstance<IUmbracoContextFactory>();
using (var contextf = umbf.EnsureUmbracoContext())
{
var umbcontext = contextf.UmbracoContext;
IContentService cs = Umbraco.Core.Composing.Current.Services.ContentService;
cs.SaveAndPublish(child);
}
I believe you're getting your ContentService the wrong way and therefore it may be empty, causing a null reference exception.
If you're in a SurfaceController, you can get ContentService like this:
var cs = Services.ContentService;
If you're in a class where Services is not exposed, you can get it like this:
var cs = ApplicationContext.Current.Services.ContentService;
Read more about it in Umbracos documentation below :)
https://our.umbraco.com/documentation/Reference/Management/Services/ContentService/
Look that link, seems that Umbraco 'Save' works even if something is null but not completely:
Save is working but not completely, it is saving the content to the db
but not to the Umbraco backoffice. And even when I try wrapping the
setValues inside a
if (blogNode.HasProperty("title")) {
I still get a null reference
error.
In the OP case he's taking the wrong contentService in the first step, so i think #Mikkel answer is not completely wrong:
Turns out I had used the wrong parentId in this line:
var newBlog = contentService.CreateContent(post.Title, 1053, "umbNewsItem", 0);
the correct statement was:
var newBlog = contentService.CreateContent(post.Title, 1061, "umbNewsItem", 0);
L-
Given
Dim postviewmodel As IEnumerable(Of be_PostsViewModel)
postviewmodel = _postRepository.SelectAll.Select(Function(S) New
be_PostsViewModel With {.PostIsPublished = S.PostIsPublished, .Id =
S.PostId, .PostSummary = S.PostSummary, .PostDateCreated =
S.PostDateCreated,
.PostCategory = S.PostCategory, .PostTitle =
S.PostTitle}).Where(Function(p)
p.PostIsPublished = True).Where(Function(a) Not
a.PostCategory.FirstOrDefault.CategoryName = "Lead Story")
.Skip((Page - 1) * PageSize).Take(PageSize)
How would I use Automapper so I don't do all thmapping of properties by hand? I am completely new to it and have been doing a lot of reading but don't quite understand how to actually do it. I know I have to create the map and then call Mapper.map. But what goes where in Mapper.map?
I would do this:
Mapper.CreateMap<Post, be_postsViewModel>();
Do that in your application startup (App_Start etc). Then in your code above:
postViewModel = _postRepository.SelectAll.Project.To(Of be_PostsViewModel)
However, I'd put the "Project.To" AFTER all of your Where/Skip/Take pieces. The projection is the last thing you want to do. Project.To creates that exact Select expression, passes it to the query provider to modify the SQL at its base.
Unless SelectAll doesn't return IQueryable, then you have other, larger problems.
I have the following test code:
local luatable = {}
luatable.item1 = 'abc'
luatable.item2 = 'def'
I'd like to know how to change it so that I can dynamically assign the names becuase I don't know how many "items" I have. I'd like to do something like this:
(pseudo code)
n = #someothertable
local luatable = {}
for i = 1, n do
luatable.item..i = some value...
end
Is there a way to do this?
I'd like to do something like this: luatable.item..i = value
That would be
luatable['item'..i] = value
Because table.name is a special case shorthand for the more general indexing syntax table['name'].
However, you should be aware that Lua table indexes can be of any type, including numbers, so in your situation you most likely just want:
luatable[i] = value
Yes, and the correct code is
for i = 1, n do
luatable["item"..i] = some value...
end
Recall that luatable.item1 is just sugar for luatable["item1"].
I can't figure how to create a jira issue and define its component with SOAPpy:
client = so.WSDL.Proxy(cfg_wsld)
auth_token = client.login(cfg_username, cfg_password)
issue_params = dict()
issue_params['project'] = project
issue_params['type'] = issue_type
issue_params['summary'] = summary
issue_params['description'] = summary
newissue = client.createIssue(auth_token, issue_params)
This sample works fine but I try to add components to it Jira will return missmatchTypeException.
I've tried all kinds of variants: passing arrays, strings, ints into it but it won't pick any of them up.
Most attempts (passing string, int, array of both) will cause TypeMissmatch, this causes NullPointerException inside Jira:
issue_params['components'] = {u'Разное': {'id': '11143', 'name': u'Разное'}}
I know the exact id of the issue type I want to use but how do I pass it properly? When I retrieve an issue with this type components returns as SOAPpy.Types.typedArrayType() but this still fails:
issue_params['components'] = so.Types.typedArrayType(data={'id': '11143', 'name': u'Разное'})
newissue = client.createIssue(auth_token, issue_params)
(<class 'SOAPpy.Errors.Error'>, <Error : Data must be a sequence>, None)
issue_params['components'] = so.Types.typedArrayType(data=[{'id': '11143', 'name': u'Разное'},])
This did the trick - data needs to be an array.
I am still relatively new to Backbone. I'm just beginning to get a sense of how it works. I 've been using Rails for a while and it's what is giving me some hint at times of using Backbone. so here goes:
Simple, I have a Company model over in Rails say I do in javascript console
companies = new Backbone.Collection();
companies.url = '/companies';
companies.url; // '/companies'
companies.fetch();
company = companies.at(0);
company.url
The last line, "company.url" doens't return what I expect, what I expect is something like '/companies/12345' so that when I update company and decide to save it, it will know where to "put" to.
So does that mean that everytime I want something saved, I have to save on the whole collection?(!)
I would take a look at what company.url() is returning. Saving the whole collection should not be necessary.
I was trying your problem, and found that the models are not getting an id to it. So the url method on the models is not working. So i think you need to put your collections like below (what i tried)
cltn = Backbone.Collection.extend({
model:modelName,
parse:function(res){
var i = 0;
var itms = _.map(res.items, function(o){
o.id = ++i;
return o
})
return itms;
}
});
cltnInst = new cltn();
cltnInst.url="/combodata.json?";
cltnInst.fetch();
Then in your firebug type the below codes.
cltnInst.url; // this is a string props. output will be "/combodata.json?"
cltnInst.at(0).url() // this is a method props output will be "/combodata.json?/1"
combodata.json will be of this format
{
"identifier": "title",
"items": [
{
"title": "A",
"tag": "htmlcss",
"date": "today"
}, ...
]}
Please correct me if my answer is wrong.
I have actually made a mistake in the step where I make an attempt to create a new companies collection.
So instead of
var Companies = new Backbone.Collection()
I should really do something like this:
var Companies = Backbone.Collection.extend({
model: Company,
url : '/companies'
});
var Company = Backbone.Model.extend();
var companies_collection = new Companies()
companies_collection.fetch()
companies_collection.models[0].url() // '/projects/123'