This has happened to me a couple times now (first time took me a little time to figure out). But I’ve changed things in my application that have broken yiic a couple times… maybe yiic should have more private files to run off of (or maybe I shouldn’t mess with certain things)? Well I don’t know if users should just be warned or if yiic should run somewhere else, so here’s my destructions of yiic…
I’ve changed actionIndex in the SiteController to redirect to another controller as we don’t really have a main page (it’s a search site). Trying to use yiic it spit out a bunch of html tags with exception information. So I learned don’t mess with actionIndex.
Just recently we created an internal site which we’ve locked out use by adding a beforeAction in the Controller (the one in components that all controllers derive from). In that beforeAction we only allows a user to go to the login page if they’re not logged in and if they are logged in it checks if they’re in the admin role, if not it redirects them to another site. This also broke yiic so I have to comment out any time I want to do crud operations from the console.
None of this stuff should effect yiic in any way. Yiic is located in the framework core… not the application. Are you making changes to the yii core by any chance?
OK here are my tests. I created a new site and changed actionIndex to:
public function actionIndex()
{
$this->redirect('contact');
//$this->render('index');
}
Running yiic does nothing (in an older version it spit out some html exception stuff. Running yiic and passing the config worked. I changed that code back to the original and did another test in components/Controller.php:
protected function beforeAction($action)
{
if($action->controller->id === "site" && ($action->id === "login" || $action->id === "logout"))
return true;
if(Yii::app()->user->isGuest)
$this->redirect(array('site/login'));
// this is my own custom component which works fine
if(Yii::app()->rbac->isInRole("Root"))
return true;
$this->redirect('http://someothersite');
}
This does the same thing and yiic does not work. Additionally with my custom component there it spits out the exception I was talking about. The output is (part of it at least):
What I don’t understand is the part of the application you are referring to and the yiic console are supposed to be separated. Running yiic should not invoke beforeAction() or actionIndex()
I guess he’s talking about yiic shell which does execute the web application (and thus render index.php but discard it’s output) if no config is provided. It does this to let the application perform its configuration. (Check cli/commands/ShellCommand.php:77).
@Igoss007:
Did you try to add the path to your config file when you call yiic shell? That prevents that your web application is run.
The config file can have any other name than default protected/config/main.php. In order for yiic shell to find out the current configuration in different setups, it simply includes index.php. That configures and runs the application and discards its output. It works pretty well as long as your startpage is accessible and doesn’t do any redirects. If it does, you need to supply the path to your config file, then index.php will not get included.