April 10, 2009, 3:21am
Hi … I want load a list of profiles within another page… so I am trying to do something like this:
<?php include Yii::app()->request->baseUrl."/protected/views/profile/admin.php"; ?>
That gives me this error: include(/pretty/protected/views/profile/admin.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
So I tried this: <?php include $_SERVER['DOCUMENT_ROOT']."/pretty/protected/views/profile/admin.php"; ?>
That worked … but I don't want to use the PHP env variable like that … and I get the error that $sort is undefined… b/c I never hit the Profile controller.
So… my question is how to include results by hitting the controller, using the model, and returning the results with view.
Thank you so much to anyone who is able to help me out. I really appreciate. I'm just getting started with Yii but I like it a lot so far.
April 10, 2009, 3:42am
Yii::app()->request->baseUrl returns the base URL, which is not what you want.
You can use
<?php $this->renderPartial('/profile/admin'); ?>
April 10, 2009, 4:16am
Thanks so much for replaying! That actually helped me with something else, but when I call $this->renderPartial('/profile/admin'); … none of the variables were ever defined because the actionAdmin() function in the controller was never used.
Right now it's working but I'm using JS to go get the info:
By doing this… I hit the controller and get the HTML I want. Is there a way to do something like: Yii::ProfileController->actionAdmin() and get the HTML back?
April 10, 2009, 11:37am
I don't quite understand your need. If you want to pass in data to the admin view, you can do so with renderPartial() just like you do with render() (that is, pass the data array as the second parameter to the method).
You can also directly include the view file just like you did before.
April 10, 2009, 7:54pm
I'm sorry - I'm probably not being very clear.
Let’s use the blog example. If I go to
http://localhost/?r=post/admin then I get a list of posts. The simple flow of that is:
initiate web app
go to PostController
go to actionAdmin()
get list of posts from Post model
render the contents in /protected/views/post/admin.php wrapped in /protected/views/layouts/main.php
renderPartial and that won't include /protected/views/layouts/main.php
That work flow was accomplished by ?r=post/admin
I'm basically trying to accomplish the same thing, but from within the code. How do I call the actionAdmin() function of the PostController from with another area of the code?
April 10, 2009, 9:20pm
If in the same controller, you can call another action using $this->run($actionID). If in a different controller, you need to use Yii::app()->runController($route).
However, it seems odd to me to use this approach. When don't you simply redirect to this controller action?
April 10, 2009, 9:45pm
The reason I’m doing this is because my page is actually
Within that, I'm using the jQuery UI tabs to show several different tools on different tabs. So, on Tab
#1 … I will call it "profiles" and make a call to Yii:app()->ProfileController(admin) to show a list of profiles.
Maybe it is odd
April 10, 2009, 9:50pm
<?php echo Yii::app()->runController('profile/admin'); ?>
That's what I needed! Thanks so much and sorry for the confusion. I need to read the documentation again