Zend Navigation - setParent Zend_Navigation_Container - zend-framework

Currently working on some modifications inside a Zend Framework website. One of the things I've been trying to change is the navigation structure and caching of the website. Unfortunate I've came accros a small problem which I, for some reason, cant figure out.
The problem is that I've build up a multi dimensional tree structured array from a database, which I want to pass on to the Zend Navigation class. To me, the array seems legit but Zend throws back the setParent error 'Argument 1 passed to Zend_Navigation_Page::setParent() must be an instance of Zend_Navigation_Container, string given'.
After some debugging and research, I've found a test array (pastebin array) and pasted this in as the first argument array. The array looks (as far I can see) almost the same as my generated array (pastebin array).
I hope someone can help me move on with this problem.
Best regards.

Found the problem. Thanks to the 'test array' I've added variables from my generated array one by one. After adding the $row['parent'] variable, the 'test array' also crashed into the setParent error.
foreach($elements as $key => $value) {
$leaf = $value
$value['swag'] = $value['parent'];
unset($value['parent']);
}
Code above is not the exact code used, just the snippet which fixed this bug.

You need to make sure that your array that you are sending to setParent is an instance of Zend_Navigation_Container.
First paste your array through Zend_Navigation() then paste the Instance through the setParent function of Zend_Navigation_Page.

Related

Understanding = operator in dart

What does = do here?
List<Segment> totalSegments = flight.departureFlight.segments;
Do both, totalSegments and flight.departureFlight.segments point to the same memory reference or totalSegments has the same data as flight.departureFlight.segments but points to a different memory location?
My understanding was that the latter should happen since dart is pass by value and not reference. However, a very annoying bug occurred when I added this line below that one:
totalSegments.addAll(flight.returnFlight.segments);
This above line actually modified the flight variable which in turn somehow modified the AsyncSnapshot from the StreamBuilder. Although, I wasn't using the variable anywhere else and not modifying other variables mentioned.
This all happened inside build function of a Stateless Widget. Maybe that has to do something with it.
I tried reading dart documentation for it, but either I couldn't find what I am looking for or the information is simply missing there. Read this too, but according to this, my use case shouldn't happen.
When it comes to objects as in your case, you are assigning a reference to an existing object (memory location) to a new variable. While acting upon that reference, you change the same object.
If this is not what you intend, check out answers related to (deep) copying of the objects
You were mistaken by the fact that Dart passes by value, and not by reference. Actually, it is exactly the opposite: (Almost) everything is always passed by reference (Which is usually a good thing!) Therefore, it is quite logical that because you edited totalSegments your departureflight.segments got edited too. It is a synonym. One of the ways to solve your problem would be:
List<Segment> totalSegments = List();
totalSegments.addAll(flight.departureFlight.segments.toList());
List<Segment> totalSegments = flight.departureFlight.segments;
This expression does the following.
Assigns the value of the expression flight.departureFlight.segments to variable totalSegments.
This and only this and nothing more.
There is no need to know what is really happening, because this is what happens.
P.S.
What value will be obtained as a result of executing the expression flight.departureFlight.segments is another question, because it depends on the implementation of the members of the operands of the expression flight.departureFlight.segments.

Is there a problem, or is it bad accessing and changing values in a List?

I have a List
List myList = [];
It gets populated with values, and then I go and I change these values. It works well.
But then it stopped working and I opened a question here, and a gentleman responded saying that I need to use HashMap, LinkedHash.. etc..
Why? I got it working again. Is it wrong?
Is it wrong to access a list and write to it?
I copied some code that I found on the net, and the developer had copied all elements into a Map and was accessing the elements via a Map object.
Map myMap ;
myMap = myList[0];
--> but frankly speaking, I really didnt see why I needed a Map variable. So I erased all Map variables, and my code works fine.
Am I doing something illegal? Or bad practice?

Calling a python function from MATLAB, generates an object with only some attribute

From MATLAB I am calling a Python function that creates and returns a Python object MyPyObj created by me with some attribute. The object is correctly returned however some attribute is missing and when I try to access them in MATLAB, a No appropriate method, property, or field error is returned. Does someone know why this happens?
Have you already tried this:
commandStr = 'python /Users/myName/pathToScript/sqr.py 2';
[status, commandOut] = system(commandStr);
if status==0
fprintf('squared result is %d\n',str2num(commandOut));
end
I managed to solve the problem following this post. Basically I needed to use
py.getattr(myPyObj, 'name_of_the_hidden_attribute')
However I am still not able to understand why myPyObj.name_of_the_hidden_attribute throws an error. I want to provide also this link in case my solution does not fix the problem for other users.

Using boost's socket.async_send_to()

I've been stuck on this for a while now. I am trying to send the following:
boost::shared_ptr<uint8_t[]> m_data
over the wire using:
_socket.async_send_to(boost::asio::buffer(m_data), m_remote_endpoint,
boost::bind(&UDPServer::handle_send, this, message,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
I get the error "no instance of overloaded function boost::asio::buffer matches the argument list boost::shared_ptr<uint8_t[]>"
m_data is filled in another function.
I suspect this is because I actually have to use the key word new on m_data. But I can't quite figure out how to do it. I've tried a few different variations. Can anybody offer me some insight here? This is probably more a question of how to dereference a shared pointer then anything. Thanks in advance!
boost::asio::buffer has an impressive lists of consttructors, but neither of them takes shared_ptr<[]> (possibly an oversight form lib authors).
In your case, you simply need to derefence shared ptr, for example, by calling get on it.

Why my app crashes when copying an array with certain strings to a dictionary?

I'm working with a tableview that shows an array of dictionaries. Everything was working fine until I wanted to add an array of strings to the new dictionaries.
The strings in the array have the format "CALL 34". When I add the array the app shows the tableview again but after a second it crashes without showing anything at the console.
The very rare thing is that the app works fine if the strings are between "CALL 1" and "CALL 32", or between "CALL 99" and "CALL 100". The console shows the "modifying layer that is being finalized" error when it works tho.
I NSLog'd the array before adding it and the strings are all fine.
Any idea would help as I'm completly lost!
Thanks
I tryed not releasing anything in that class and the problem is solved (I should find what was making it crash...). The class is a heritated class.
Without showing code, it is impossible to say exactly. As well, if there is a crash, there is a backtrace. Show it, too.
Sounds like a memory management issue.