Yii Framework Forum: Controller/View - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Controller/View Rate Topic: -----

#1 User is offline   phpman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 28-October 10

Posted 28 October 2010 - 06:10 AM

Hi,

I'm starting to use Yii.
Following a schema of DB , I have a table and from this table I want to retrive the values of only 2 fields present

1) It is possible create a specific controller without to have a model?
2)In the controllers folder I just created a file named MyController with only 1 function as:
public function actionIndex()
{

$dataProvider=new CActiveDataProvider('index', array( 'criteria'=>array( $criteria->select=name,surname,age), ));

$this->render('index',
array(
'dataProvider'=>$dataProvider,
)
);

}
IT'S correct?

3)Under views I just created a folder reports and I created a index file with:

<?php
$this->breadcrumbs=array(
'Reports',
);

$this->menu=array(
array('label'=>'Create Projects', 'url'=>array('create')),
array('label'=>'Manage Projects', 'url'=>array('admin')),
);
?>

<h1>Vista</h1>

<?php $this->widget('zii.widgets.CListView'/*'zii.widgets.grid.CGridView'*/, array(
'dataProvider'=>$dataProvider,
'itemView'=>name,surname,age

)); ?>

I have error 404
Can I understand the right operation to do?
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,358
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 October 2010 - 06:19 AM

It is possible to create a controller without a model... but if you are working with data from the database... than the models are used just for that...

your code is wrong... because nowhere is specified what table to read data from ?

as you are getting a 404 error than maybe the URL you are trying is wrong...

Anyway as you are just starting with Yii I suggest you take a read at the Definitive Guide to Yii to get a better understanding how all this works...
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   phpman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 28-October 10

Posted 28 October 2010 - 06:49 AM

Hi,
thank you for the answer.
I'm following the useful guide but I'm appronching yii also to write code to understand at well the framework
about the table I changed:

$dataProvider=new CActiveDataProvider('Progetto', array( 'criteria'=>array( $criteria->select=name,surname,age), ));

$this->render('index',
array(
'dataProvider'=>$dataProvider,


but I continue to have error 404 and I don't know what else
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,358
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 October 2010 - 06:56 AM

You really should first read the guide... and work with some examples... before trying to do something like this... it will be easyer and you would not post questions like this...

As per documentation - CActiveDataProvider provides data in terms of ActiveRecord objects which are of class modelClas, but you don't have a model !

As I wrote before the 404 error can be even because you type a wrong URL...
Find more about me.... btw. Do you know your WAN IP?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users