you would probably need a global app controller behavior which
translates everything right away
php doesnt have the attributes itself
but you can acomplish that by using:
$size = count($cars);
$first = array_shift($cars);
$last = array_pop($cars);
and may others
etc
On 5 Jul., 02:38, Zeu5 <kimc...@gmail.com> wrote:
> I am using Twig so that I can make it as easy for designers to design
> themes as possible without knowing php.
>
> Currently, Twig evaluates the strings, arrays, objects like thishttp://www.twig-project.org/doc/templates.html#variables
>
> i want to keep things as simple and as brief as possible.
>
> Hence I want to make it such that designers need only use
> {{ cars.size }} , {{ cars.first }} and {{ cars.last }}
>
> So i guessed that cars cannot be usual php arrays, but objects with
> attributes for size, first and last.
>
> If my understanding is wrong about php arrays, i apologise.
>
> Please educate me on how usual php arrays can possibly have these
> attributes as well.
>
> On Jul 5, 7:17 am, euromark <dereurom...@googlemail.com> wrote:
>
>
>
>
>
>
>
> > why are the normal 1.3 arrays not working for you?
> > they also have all those functions built in (in plain php functions
> > then of course)
>
> > On 5 Jul., 01:06, Zeu5 <kimc...@gmail.com> wrote:
>
> > > I have cars controller, Car model and views for cars.
>
> > > I am using Twig 1.0,http://www.twig-project.org/doc/templates.html#list-of-control-struct...
> > > Cake 1.3
>
> > > I want to do the following in the controller:
>
> > > function index() {
>
> > > ...
>
> > > $carData = $this->Car->find('all');
>
> > > $cars = Car::prepareForView($carData);
>
> > > $this->set('cars', $cars);
>
> > > }
>
> > > the prepareForView will turn the car data into an object that
> > > implements the IteratorAggregatehttp://php.net/manual/en/class.iteratoraggregate.php
>
> > > the reason is because i want to be able to do the following in the
> > > view using Twig.
>
> > > {{ cars.size }} // returns me the size
> > > {{ cars.first }} // returns me the first element of the array
> > > {{ cars.last }} // returns me the last element of the array
>
> > > Am i right in wanting to prepare the array as an IteratorAggregate?
> > > If i do this for Car and other models, how should i do it?
>
> > > Advice, please. Thank you.
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment