I destroyed yiic!!

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.

Using Yii-1.1.1

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?

What is the error you are getting?

Try to add the path to the config file when you call yiic.

No changes to the Yii core. I’ll have to do some tests to see the minimal of what makes it fail and post here (I’m away from my code at the moment).

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):


<!-- start log messages -->

<table class="yiiLog" width="100%" ... blah blah blah>

...

    <tr style="background:#FFFFFF">

        ...

        <td>trace</td>

        <td>system.web.CModule</td>

        <td><pre>Loading &quot;log&quot; application component</pre></td>

    </tr>

    ...

        <td><pre>Loading &quot;request&quot; application component</pre></td>

    ...

        <td><pre>Loading &quot;urlManager&quot; application component</pre></td>

    ...

        <td><pre>Loading &quot;user&quot; application component</pre></td>

    ...

        <td><pre>Loading &quot;session&quot; application component</pre></td>

...

Again using yiic with the config file does work… I guess why not just use the config file be default?

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()

What does your yiic.php look like?

@jonah:

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.

Yea yiic shell.

Yea I tried that and it worked… just wondering now why the default executes the web application instead of just using the config.

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.

I see that now, thanks! A warning in the yii guide or some other yiic documentation of that would be nice.

Please fill a report at http://code.google.com/p/yii/issues/list

Submitted: http://code.google.com/p/yii/issues/detail?id=1058