Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)
#81

[eluser]tdktank59[/eluser]
Thought id share it with you guys...

Spanish Translation of the datamapper lang file

DMZ 1.6.1 - Spanish lang File

Enjoy
#82

[eluser]chadbob[/eluser]
I understand looping through the returned objects of a
Code:
$_->get();
query with a foreach.

How would I directly access those objects though if I knew the index?

In my model, I have it set up to auto sort by date, so before I massage all the sets, let's say I need to get the id of the most recent report.

How would I do something along the lines of:

Code:
$_->get();
$_->0->id;

?


Sorry, I know this is probably a basic php question, I'm coming from Java and all this arrow business is a bit odd to me :o
#83

[eluser]OverZealous[/eluser]
@chadbob

When you use foreach($objects as $o), it is simply acting on an Iterator interface that DMZ provides. The Iterator is iterating over the magic all array (which is indexed from 0 in DMZ).

Therefore, you simply use the indexed on the all array, like so:
Code:
$object = new Object();
$object->get();
// get the 3rd item
$object3 = $object->all[2]; // 0-indexed

I come from a Java background too, and I still write some Java code. Switching between the two causes a lot of headache at times.

Some random Java to PHP tips:
Code:
// Java => PHP
object.property => $object->property
object.method() => $object->method()
"string" + "string" => "string" . "string"
super.method() => parent::method()
MyClass.staticMethod() => MyClass::staticMethod()
public String toString() => public function __toString()

Be careful when comparing values. PHP is really loose about values: In PHP, these are == to FALSE: 0, '', NULL. If you need to compare to false explicitly, you need to use ===. Also, always use is_null when checking for NULL values.

Arrays are an all-in-one combination of ArrayList and HashMap. They can be accessed via keys, or iterated over. The order objects are inserted is preserved, or they can be sorted.

Objects can have properties created at runtime. More importantly, there are magic methods that allow the object to dynamically process variables and methods that aren't explicitly defined in the class. DMZ takes advantage of this.

Good Luck, and welcome to the wild-and-crazy world of PHP. It can be really fun, but when you first come across the subtle differences in in_array vs strpos, you may swear a little. :lol:
#84

[eluser]OverZealous[/eluser]
Oh, I should have mentioned, if you only need the 3rd object from a result set, you can do this:
Code:
$o = new Object();
$o->where(...);
$object3 = $o->get(1, 2); //start at item 2, limit to 1
#85

[eluser]chadbob[/eluser]
Thanks Phil, how to access resultant array of objects by index is what I needed! (I still need to return all of the objects for processing.)


Yes...php's typing, arrays, etc drive me nuts! Part of the problem is that I'm cutting my teeth on php+codeigniter+dmz at the same time..so I get confused as to what is general php syntax vs CI syntax vs DMZ syntax...

Since you said you do Java, you know that (if you do a lot of heavy OOP) java's insanely deep hierarchies of classes/interfaces also makes the move to MVC a bit odd as well.

But I'm enjoying this nonetheless! I'm sure my code is horrid, but it's still far more elegant for dynamic pages pulling from a relational DB than I could do with "typical" java.


Thanks again! DMZ is great.
#86

[eluser]OverZealous[/eluser]
@chadbob
Oh, yeah, the function-based tools vs object-based tools is very difficult to get used to.

What's bizarre, though, is that I still enjoy coding in PHP more than in Java. Even with better debugging tools, stricter (and easier to read) code in Java, PHP is just more fun to write. :-P

A good IDE helps. I'm still struggling along with Aptana 1.5 (2.0 effectively dropped PHP support >Sad ), but I'm looking into using NetBeans 6. NB6 is insanely fast, and has incredibly smart PHP suggestions (including the ability to use comments to define the types for magic properties).

However, NB doesn't have a usable synchronizing toolkit, nor the ability to run command-line functions from the toolbar.

I'm 75% of the way solving the first one, as I have written my own, developer-friendly standalone sync tool (in Java) that can be completely run from the command line or pop-up a GUI as needed, and stores sync properties in text files. Currently it syncs between any combination of local filesystem and SFTP (SSH+FTP) connections. I'll eventually release it to the world.

The second problem is a much bigger issue, since I currently have a bunch of little utilities I run in Aptana, like JavaScript compressing. Until I solve that, I can't really switch away from Aptana.
#87

[eluser]tdktank59[/eluser]
Hey got a question.
Has nothing to do with dmz however lol..

http://lgb.421entertainment.com/es/customers

Im running UTF-8 however for some reason it's not printing the proper values. In the database its stored in utf8-general-ci. and looks fine there however it wont print right...
Any idea how I can do that?

EDIT: Never mind just had to set

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

PS. THe page before this one there is a Spanish translation of the language file.
#88

[eluser]OverZealous[/eluser]
Well, first off, your HTML doesn't have the correct encoding. You'll either need to add it as a header, or as a meta tag in your document.

Also, your HTML is all messed up. You've got script and link tags before the DocType. The DocType must be first. (Actually, you've got the the <?xml?> declaration, which should be first, but I believe it is recommended to not use that, even on XHTML, unless you are actually generating an XML document.)
#89

[eluser]OverZealous[/eluser]
W3C Validator results.
#90

[eluser]tdktank59[/eluser]
[quote author="OverZealous" date="1261061182"]Well, first off, your HTML doesn't have the correct encoding. You'll either need to add it as a header, or as a meta tag in your document.

Also, your HTML is all messed up. You've got script and link tags before the DocType. The DocType must be first. (Actually, you've got the the <?xml?> declaration, which should be first, but I believe it is recommended to not use that, even on XHTML, unless you are actually generating an XML document.)[/quote]

damn didnt notice that.

Thanks for seeing that lol...
Yeah ill be removing the xml doc tag thing...
And the script/link tags are supposed to go at array array below all the links and stuff




Theme © iAndrew 2016 - Forum software by © MyBB