Yii Framework Forum: Pdf Report - Yii Framework Forum

Jump to content

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

Pdf Report Rate Topic: -----

#1 User is offline   demay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 24-August 12

Posted 29 January 2013 - 06:33 AM

hi all,
could u pls help me out am new to yii and i haven't mastered it well.
I have 3 models

1) model-A has the following fields
-name
-phone number
-house number

2) model-B has the following fields
-profession
-address
-telephone

3) model-C has the following fields
-spouse name
-telephone
-profession

So i want to pull these records from a db when doing a report.
In model-A i want all the data to be in the final report.
In model-B i only want address and profession to appear in the final report
In model-C i only want spousename to appear in the final report.

Finally how do i convert the report to pdf
tried something like this
.......
$mPDF1->WriteHTML($this->renderPartial('inde', array('model'=>$model), true));
......
Thanks pls assist me
Its something similar to one below


________________________________________________________________________________

NAMES OF APPLICANT ..............

PHONE NO OF THE APPLICANT ..............

HOUSE NUMBER OF THE APPLICANT ..............

PROFESSION OF THE APPLICANT ..............

ADDRESS OF THE APPLICANT ..............

SPOUSE NAME ..............

________________________________________________________________________________
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 570
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 29 January 2013 - 07:26 AM

You can do it as
Controller
$MA=A::model()->findByPk(1);
$MB=B::model()->findByPk(1);
$MC=C::model()->findByPk(1);
$mPDF1->WriteHTML($this->renderPartial('inde', array(array(
'modela'=>$MA,
'modelb'=>$MB,
'modelc'=>$MC,
)), true));


in the view of inde

NAMES OF APPLICANT :<?php echo $modela->name;?>

PHONE NO OF THE APPLICANT :

HOUSE NUMBER OF THE APPLICANT :

PROFESSION OF THE APPLICANT :

ADDRESS OF THE APPLICANT :

SPOUSE NAME :


Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   demay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 24-August 12

Posted 30 January 2013 - 12:22 PM

Thanks a lot man, i appreciate ur helps so much.
I was able to do it.
At first it couldnt pull data coz of the two arrays

$mPDF1->WriteHTML($this->renderPartial('inde', array(array('modela'=>$MA,'modelb'=>$MB,'modelc'=>$MC,)), true));

but this

$mPDF1->WriteHTML($this->renderPartial('inde',array('modela'=>$MA,'modelb'=>$MB,'modelc'=>$MC), true));

worked

Thanks.

Now i have a table called user and as a column uid and is the Pk.
In the example you gave me, u used a static pK, that is 1 to pull record from the table.
How do i implement a scenario where the logged in user gets his record from modelA, modelB and ModelC and prints the report.
In other words How do i implement this without using a static Pk?
0

#4 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 570
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 30 January 2013 - 03:38 PM

Can you provide tables' scheme or relations then I can help you in that
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#5 User is offline   demay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 24-August 12

Posted 31 January 2013 - 09:05 AM

Attached File  PdfcreaterController.php (994bytes)
Number of downloads: 5Hi PeRoChAk, Am trying to achieve this, but i get errors. wats the best way to do it? I have attached the file for clarity purposes


<?php

class PdfcreaterController extends Controller
{
$OS='a value pulled from database table. it is not static but dynamic';// this value may be window7, ubuntu, windowxp, opensuse, mac.

if($OS=='window7')
{
public function actionWindow7()
{
$this->render('window7');
}
}//this one should render a file called window7 in the view folder

if($OS=='ubuntu')
{
public function actionUbuntu()
{
$this->render('ubuntu');
}
}//this one should render a file called ubuntu in the view folder

if($OS=='windowsxp')
{
public function actionWindowxp()
{
$this->render('windowsxp');
}
}//this one should render a file called windowsxp in the view folder

if($OS=='opensuse')
{
public function actionOpensuse()
{
$this->render('opensuse');
}
}//this one should render a file called opensuse in the view folder

else
{
public function actionMac()
{
$this->render('mac');
}
}//this one should render a file called mac in the view folder

}
0

#6 User is offline   thiagovidal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 17-February 10
  • Location:Brazil, São Paulo

Posted 31 January 2013 - 01:35 PM

View Postdemay, on 30 January 2013 - 12:22 PM, said:

Now i have a table called user and as a column uid and is the Pk.
In the example you gave me, u used a static pK, that is 1 to pull record from the table.
How do i implement a scenario where the logged in user gets his record from modelA, modelB and ModelC and prints the report.
In other words How do i implement this without using a static Pk?


I'm not sure if is what u are looking for but you could create a scenario or just use CActiveRecord::findByAttributes() OR CActiveRecord::findAllByAttributes()

http://www.yiiframew...tributes-detail

OR

http://www.yiiframew...tributes-detail

	$user_id = Yii::app()->user->id;
	$MA=A::model()->findByAttributes(array('user_id'=>$user_id));
	$MB=B::model()->findByAttributes(array('user_id'=>$user_id));
	$MC=C::model()->findByAttributes(array('user_id'=>$user_id));
	$mPDF1->WriteHTML($this->renderPartial('inde', array(array(
		'modela'=>$MA,
		'modelb'=>$MB,
		'modelc'=>$MC,
	)), true));

This post has been edited by thiagovidal: 31 January 2013 - 01:36 PM

0

#7 User is offline   thiagovidal 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 17-February 10
  • Location:Brazil, São Paulo

Posted 31 January 2013 - 05:30 PM

View Postdemay, on 31 January 2013 - 09:05 AM, said:

Attachment PdfcreaterController.phpHi PeRoChAk, Am trying to achieve this, but i get errors. wats the best way to do it? I have attached the file for clarity purposes


<?php

class PdfcreaterController extends Controller
{
$OS='a value pulled from database table. it is not static but dynamic';// this value may be window7, ubuntu, windowxp, opensuse, mac.

if($OS=='window7')
{
public function actionWindow7()
{
$this->render('window7');
}
}//this one should render a file called window7 in the view folder

if($OS=='ubuntu')
{
public function actionUbuntu()
{
$this->render('ubuntu');
}
...



Ok. Lets simplify things.

First off all you can't get things working this way. Why?

On php classes you can't put if outside functions this will throw a error like the following

Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION)

So let's fix this code.

There is a lot of ways to do what you are trying to achieve. On my experience with PHP and Yii Framework I suggest the following:

Why don't you create just one Controller Action that can handle all requests and get the proper view?

<?php
/*
 * Note that you must have Controller under components folders or other place to extend from... Otherwise use CControler (default from Yii)
 */ 
class PdfcreaterController extends Controller
{
	private $_os;

	protected function getOs($userAgent=NULL)
	{
		$osArray = array(
			'iPhone' => '(iPhone)',
			'Windows 3.11' => 'Win16',
			'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
			'Windows 98' => '(Windows 98)|(Win98)',
			'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
			'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
			'Windows 2003' => '(Windows NT 5.2)',
			'Windows Vista' => '(Windows NT 6.0)|(Windows Vista)',
			'Windows 7' => '(Windows NT 6.1)|(Windows 7)',
			'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
			'Windows ME' => 'Windows ME',
			'Open BSD'=>'OpenBSD',
			'Open Suse'=>'OpenSuse',
			'Sun OS'=>'SunOS',
			'Linux'=>'(Linux)|(X11)',
			'Safari' => '(Safari)',
			'Macintosh'=>'(Mac_PowerPC)|(Macintosh)',
			'QNX'=>'QNX',
			'BeOS'=>'BeOS',
			'OS/2'=>'OS/2',
			'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)',
			'Ubuntu'=>'Ubuntu',
		);

		if ($this->_os===NULL) {
			if($userAgent!==NULL) {
				foreach($osArray as $os=>$pattern){
					if(eregi($pattern, $userAgent)) {
						return $this->_os = $os;
					}
				}
				return 'Unknown';
			}
		}
		return $this->_os;
	}

	public functioActionView() {

		switch ($this->os) {
			case 'Windows XP':
				$this->render('_windowsXP');
				break;			
			case 'Windows 7':
				$this->render('_windows7');
				break;
			case 'Ubuntu':
				$this->render('_ubuntu');
				break;
			case 'Open Suse':
				$this->render('_openSuse');
				break;
			case 'Macintosh':
				$this->render('_macintosh');
				break;
			default:
				throw new CHttpException(404, 'Page not found.');
				break;
		}
	}
}
?>

0

#8 User is offline   demay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 24-August 12

Posted 31 January 2013 - 05:58 PM

Thanks man, let me give it a short
0

#9 User is offline   demay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 24-August 12

Posted 10 February 2013 - 09:28 PM

Hi friend,hope you remember our last chat about table relations.The application am doing is to be used register businesses owned by individuals.They are issued with certificates for every business registered.One may have more than one business.This means he/ she will be issued with several certificates of registration.In-terms of database, a person having several businesses have several records in in the database tables involved.we term this a one-to-many relation.help me do the relation here is the systemhttp://thekenyayouthleague.com/icentralsystemzi have attached the database.

Sorry i realized the uploaded cant take sql files
but so far i have 40 tables
so i will use ur email
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