Hi … I want load a list of profiles within another page… so I am trying to do something like this:
<div id="adminContainer">
<?php include Yii::app()->request->baseUrl."/protected/views/profile/admin.php"; ?>
</div>
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.
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?
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.
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
or
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?
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?
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.