Yii Framework Forum: Action Controller - Yii Framework Forum

Jump to content

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

Action Controller Rate Topic: -----

#1 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 17 May 2010 - 06:08 AM

My code is this:

public function actionSearch()
	{
		$model=new anagrafe;
		
		if(isset($_POST['anagrafe']))	
		{
			$model->attributes=$_POST['anagrafe'];
			//if($model->save(false))
				$anagra=$_POST['ANAGRA_ID'];
				$this->redirect(array('view','id'=>$model->COGNOME.' '.NOME));
		}

		$this->render('search',array(
			'model'=>$model,
		));
	
	}



Is possible to concatenate two fields in the redirect as I did in my function?
I have a need to view cognome + nome....
Does not work .. someone tell me what should I change?
0

#2 User is offline   Key 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-May 10

Posted 17 May 2010 - 07:21 AM

View Postkitty10, on 17 May 2010 - 06:08 AM, said:

My code is this:

public function actionSearch()
	{
		$model=new anagrafe;
		
		if(isset($_POST['anagrafe']))	
		{
			$model->attributes=$_POST['anagrafe'];
			//if($model->save(false))
				$anagra=$_POST['ANAGRA_ID'];
				$this->redirect(array('view','id'=>$model->COGNOME.' '.NOME));
		}

		$this->render('search',array(
			'model'=>$model,
		));
	
	}



Is possible to concatenate two fields in the redirect as I did in my function?
I have a need to view cognome + nome....
Does not work .. someone tell me what should I change?



Why don't you use the same function we discussed here ( http://www.yiiframew...vedropdownlist/ )?

Then use $model->cognomeNome instead of $model->COGNOME.' '.NOME

Otherwise you can use

$cognomeNome = $model->COGNOME.' '.$model->NOME;
0

#3 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 17 May 2010 - 08:48 AM

View PostKey, on 17 May 2010 - 07:21 AM, said:

Why don't you use the same function we discussed here ( http://www.yiiframew...vedropdownlist/ )?

Then use $model->cognomeNome instead of $model->COGNOME.' '.NOME

Otherwise you can use

$cognomeNome = $model->COGNOME.' '.$model->NOME;


Yes i have just tried...but not work well...
if i pass $ model-> cognomeNome when I load the page in the address bar turns
http://localhost/tir...w&id=6550+34537
where the first corresponds to the COGNOME and the second to NAME but not of the same person
i don't understand...
0

#4 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 17 May 2010 - 09:01 AM

Try to change approach,

create an id on the table Anagrafe and use this for redirect.

If you use Cognome and Nome as id you will have several problems, like the possibility of omonimous, and a special code for manage people like "De Tommasi" "Dell'Acqua" or "Della Morte".

Better to use siple ID, an autoincrement is good, CODICE_FISCALE works too (but there are ALWAYS people that don't remember them own, so can be a problem).

I have always used an ID autoincrement and I never had problem.
0

#5 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 17 May 2010 - 09:09 AM

View Postzaccaria, on 17 May 2010 - 09:01 AM, said:

Try to change approach,

create an id on the table Anagrafe and use this for redirect.

If you use Cognome and Nome as id you will have several problems, like the possibility of omonimous, and a special code for manage people like "De Tommasi" "Dell'Acqua" or "Della Morte".

Better to use siple ID, an autoincrement is good, CODICE_FISCALE works too (but there are ALWAYS people that don't remember them own, so can be a problem).

I have always used an ID autoincrement and I never had problem.

Yes i do just it..
before my code is
public function actionSearch()
	
	{
		$model=new anagrafe;
		
		if(isset($_POST['anagrafe']))	
		{
			$model->attributes=$_POST['anagrafe'];
			//if($model->save(false))
				
				$anagra=$_POST['ANAGRA_ID'];
				$this->redirect(array('view','id'=>$model->ANAGRA_ID));
		}

		$this->render('search',array(
			'model'=>$model,
		));
	
	}

but the redirect don't work...
the url is :
http://localhost/tir...agrafe/view&id=
ERROR 404-The requested page does not exist.
0

#6 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 17 May 2010 - 09:18 AM

Well, is not working because if you do
new anagrafe 

the record is new, and it has't got any id (because the id is set at the save()).

Your code is really strange. If you popolate the anagrafe with post data, how you can do a redirect? How you can be sure that the user inserted data will let you find exactly one anagrafe, not 0 and not 2?

You should use the search for poplate a datagrid (like gridView) and in this datagrid (that can have 0, 1,5 or 500 result inside) you can create a button that does the require.

When you will create the button you will have a record that comes from the db, and so you will have the id you need for redirect.

Your code has a logical mistake, you cannot rely of data inserted from user for redirect. Create a grid or a list, and do the redirect from this list.
0

#7 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 17 May 2010 - 09:33 AM

View Postzaccaria, on 17 May 2010 - 09:18 AM, said:

Well, is not working because if you do
new anagrafe 

the record is new, and it has't got any id (because the id is set at the save()).

Your code is really strange. If you popolate the anagrafe with post data, how you can do a redirect? How you can be sure that the user inserted data will let you find exactly one anagrafe, not 0 and not 2?

You should use the search for poplate a datagrid (like gridView) and in this datagrid (that can have 0, 1,5 or 500 result inside) you can create a button that does the require.

When you will create the button you will have a record that comes from the db, and so you will have the id you need for redirect.

Your code has a logical mistake, you cannot rely of data inserted from user for redirect. Create a grid or a list, and do the redirect from this list.


Then with my function I don't insert any data ...
I just do a search ... I have a form with a textfile name, address and sex
and after do this I post a redirect to the page with the id
The line with save is commented...otherwise it's insert a new line
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