Pdf Report

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

  1. model-B has the following fields

-profession

-address

-telephone

  1. 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 …


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 :




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?

Can you provide tables’ scheme or relations then I can help you in that

3816

PdfcreaterController.php
Hi 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

{

&#036;OS='a value pulled from database table. it is not static but dynamic';// this value may be window7, ubuntu, windowxp, opensuse, mac.  





if(&#036;OS=='window7')


{


	public function actionWindow7()


	{


		&#036;this-&gt;render('window7');


	}


}//this one should render a file called window7 in the view folder





if(&#036;OS=='ubuntu')


{


	public function actionUbuntu()


	{


		&#036;this-&gt;render('ubuntu');


	}


}//this one should render a file called ubuntu in the view folder





if(&#036;OS=='windowsxp')


{


	public function actionWindowxp()


	{


		&#036;this-&gt;render('windowsxp');


	}


}//this one should render a file called windowsxp in the view folder





if(&#036;OS=='opensuse')


{


public function actionOpensuse()


	{


		&#036;this-&gt;render('opensuse');


	}


}//this one should render a file called opensuse in the view folder





else


{


	public function actionMac()


	{


		&#036;this-&gt;render('mac');


	}


}//this one should render a file called mac in the view folder

}

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.yiiframework.com/doc/api/1.1/CActiveRecord/#findByAttributes-detail

OR

http://www.yiiframework.com/doc/api/1.1/CActiveRecord#findAllByAttributes-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));



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;

		}

	}

}

?>



Thanks man, let me give it a short

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