Import Content Php File

Hi

How to pass the content of php file using Yii functions like

$cont = Yii:SomethingImportFunction(‘webroot.themes…myhteme.views.layouts.partoftheme’);

and in another place just using the echo $cont ?

I not like to use ‘require’ or ‘include’ php function :)

If you want to retrieve the contents rather than including the file, I guess you could use this:




$contents = file_get_contents(Yii::getPathOfAlias('your.path.here'));



Check here for the docs.

Thanks Keith for reply :)

Sorry, I didn’t give exactly what I want. I want the output of php file into a variable, not the content.

One way to do it

$contents = require_once (Yii::getPathOfAlias(‘your.path.here’));

But the outputs occurs just in the same line. I want to store the output in a variable and then echo in another place this variable

I could use ob_start() and ob_get_clean() but I would prefer a way with API of Yii… if exists

Thanks

What is the file exactly? It seems like a strange way to process the output.

[s]In any case, I imagine you could turn output buffering on and capture the output.

Can you explain in more detail what you’re trying to do? There may be a better way to handle it.[/s]

EDIT: I see you’ve already thought of that. I’m not sure that there’s a Yii specific way to do it, but you could create a helper method for your own application.

I am developing a theme that has main template, menus submenus etc.

Because each part has large code (with dynamicaly theme and menus content) I want to seperate for maintenance reasons.

I want to keep these part of outputs into local variables and deside later the places that variables output its content

Your last post implies that you are rather looking for partial views. For the record: Yii makes some use of returning data from an included file, so an assignment like $content=include($file); can work. Application configs work that way.

Hi Da:Sourcerer

I know that seems like renderPartial.

Can you suggest me how can I use renderPartial into theme file (because is theme render issue rather than content) ?

The second issue: If I could use renderpartial in theme, how can I get the output into a variable rather than output directly?

Many thanks

You should be able to use renderPartial in themes without problems. render() and renderPartial() take a third argument that controls wether the rendering result should be displayed or rather returned. See CController.renderPartial().

Yes it is :)

So simple…

$submenu = $this->renderPartial(’//layouts/_mypart’,NULL,true);

Many thanks both Keith and Da:Sourcerer