Custom Views errors driving me insane

I am modifying the _view page and i keep getting errors… Trying to follow the way the yii mysql tutorial is doing it… http://www.kevinkorb.com/post/25

here is my member controller code for the view:

public function actionView()


{





	$this->render('view',array(


		'model'=>$this->Model()->with(array('team'))->findAll(),


	));





}

and here is the _view code under my member directory for layouts:

<?php foreach($model AS $Members):?>

&lt;?php if (&#036;Members-&gt;teamId === Yii::app()-&gt;user-&gt;id) {?&gt;


&lt;tr&gt;


    &lt;td&gt;&lt;?php echo &#036;Members-&gt;firstName;?&gt;&lt;/td&gt;


    &lt;td&gt;&lt;?php echo &#036;Members-&gt;lastName;?&gt;&lt;/td&gt;


&lt;/tr&gt;


&lt;?php }?&gt;

<?php endforeach;?>

</table>

Based on that tutorial something like that should work but i get errors saying:

"Undefined variable: model"

I dont see the normal _view defining any variables its just pulling back data with a $data variable that I cant seem to find anywhere defined… This is the way the normal code in the _view is pulling data…

<?php echo CHtml::encode($data->firstName); ?>

that works just fine for the normal view… and if I replace the top code with the $data variable it just gives me object references errors…

"Trying to get property of non-object"

Hand-coding PHP is so much easier then using a framework, I cant seem to figure out how to utilize the framework to pull data… trying to use a framework is driving me nuts…

Anyone want to shed some light on proper way to pull data into views or modify controllers etc etc… The official docs get me no where when I read them…

In your actionView, you are calling render() with ‘view’… not ‘_view’.

The ‘_view’ is a partial file, which maybe gets called from ‘view’??

Hmmmm partial view???

Oh found this in the real view file ‘data’=>$model

That must be the definition for the $data variable… Good that I know where that is now things make a bit more sense… and its using a widget, I am going to have to look up widgets in the docs hopefully the docs on widgets doesn’t suck… lol

Anyone have any good resources on creating custom views and extending controllers?? i am surprised there is little documentation on this framework, it seems really nice but I hit a stumbling block every 2 feet because google gets me no where…

kind of on a deadline for this project so its been driving me insane trying to get modules to work… havnt yet… and trying to make custom views and controllers based on logged in users data only…

wooaaaaa hold up… that view file can be completely deleted and the pages function fine… WTF… What is the view.php file for then?

Looks like some url’s and then some widget with all the variables being set to $data in an array

BUt you can delete it and nothing changes… Even the _view file that’s calling $data elements runs fine… This is weird as hell…

ANYONE HAVE ANY CLARIFICATION ON WHATS BEING CALLED FROM WHERE… .These views are driving me nuts…

Calling your view file ‘view.php’ is just going to get confusing - I am going to refer to it as ‘show.php’, and ‘_view.php’ as ‘_show.php’ for this example.

Generally speaking, the view files with no underscore at the start are related to a controller action. E.g your member controller has the method actionShow() which should be using views/member/show.php

View files with an underscore are usually reusable partial view files - i.e. a chunk of view code that can be used by multiple actions. In your case, the _show.php file might be getting used by other views in the member folder - have a quick look. It might be that the view for a particular action like actionShow() does nothing but render that other _show.php file. However some action like actionList() might render _show.php for each item in the list. Can you see how this might be useful?

It might seem redundant when looking at just the one action, but it’s the ability to reuse in other actions that makes it useful. In my projects, I often make a controller specific _search.php view file which is then included in most of the actions related to that particular controller.

Edit: with recent versions of Yii, this _search.php view is created by the default CRUD generator.

Yea i kind of get what your saying about the _view being a partial view file thats called by other actions, but then what does the view file do… I noticed one thing, all of the other files such as _form, _search they all use "$model->field" to call data elements…

_view does not use $model->field, it uses $data and i have no clue where that variable is coming from or how to use it correctly to extend views it complains if you try to use it the same way as $model. If i try to call $model like the other files do it just complains that there is no such thing… And $data does not function the same as $model…

Why would Yii make this different and not utilize the controllers for the view like other frameworks??? I see arrays in the view.php Doesnt that violate MVC?

Also, I looked around and it looks like index.php in the members folder is calling _view with CListView. I am still not sure what the view file actually does… or how to create custom ones…

Main question:

1.How do I utilize the controller actions to create my own views that make sense from the models data?

2.What should I extend and what should I Not extend in the Yii architecture to build custom functionality and views?

  1. Off topic, does anyone know why none of the modules I try to install ever work?