Welcome Guest, Not a member yet? Register   Sign In
simple php syntax question
#1

[eluser]Bogdan Tanase[/eluser]
Hi,

Is it possible to write the following sequence shorter?

Code:
$row=$query->row(); //active record row result

$name=$row->name;

could I write something like

Code:
$name=($query->row())->name; //obviously this will not work

I'd like to know if there's a way I could reference the member of the object returned by row() function without assigning it to another variable.

Thank you!
#2

[eluser]xwero[/eluser]
if you use php5 you can write
Code:
$name = $this->select('name')->where('id',$id)->get('table')->row()->name;
#3

[eluser]Bogdan Tanase[/eluser]
right! Thank you xwero. I forgot all about method chaining Big Grin
#4

[eluser]jdfwarrior[/eluser]
Is that in t he documentation/user guide somewhere? Never seen it done quite like that..
#5

[eluser]TheFuzzy0ne[/eluser]
[quote author="jdfwarrior" date="1234293610"]Is that in t he documentation/user guide somewhere? Never seen it done quite like that..[/quote]

Yes it is. http://ellislab.com/codeigniter/user-gui...l#chaining




Theme © iAndrew 2016 - Forum software by © MyBB