Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:26:03+00:00 2026-05-29T06:26:03+00:00

If you look under #3 in this link http://www.yiiframework.com/doc/guide/1.1/en/basics.controller it gives you a way

  • 0

If you look under #3 in this link http://www.yiiframework.com/doc/guide/1.1/en/basics.controller it gives you a way to organize all of your controller functions into individual php files.

To do this you have to have each php file contain a class that extends CAction. Each class must have its running code inside of the function run().

This is my UserController.php file

public function actions()
{
    $FOLDER = '.User';
    $PROJECT_ROOT = 'application.controllers' . $FOLDER;

    return array (
        'list' => $PROJECT_ROOT . 'ListAction',
);

}

In the application that I am writing I need to pass variables to specific Actions.

Yii implemented runWithParams($params) in Yii 1.7 to allow this to happen. However, when I call write in the (for example) DeleteAction.php file runWithParams($params) instead of run() and our front end calls post/delete/?params=45 instead of run() I get an error that says “could not find run() in file DeleteAction.php

class ListAction extends CAction
{
public function runWithParam($id)
{
    SiteController::actionLoggedin();
    $id = addslashes($id);
}

Which means that I need run()…but I can’t pass parameters into run(). I need runWithParams($params).

In the documentation for the function runWithParams($params)
http://www.yiiframework.com/doc/api/1.1/CAction#runWithParams-detail

it says

    Runs the action with the supplied request parameters. This method is internally called by CController::runAction().

I am confused what this means? I don’t understand how I can implement this successfully.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:26:05+00:00Added an answer on May 29, 2026 at 6:26 am

    You just need to implement run() in a CAction class.

    You will automatically have access to the $_GET params, of course, like you would in your action normally:

    class ListAction extends CAction {
      public function run() {
        $id = $_GET['id']; // $_POST works too
        $model = Model::model()->findbyPk($id);
        // render your view next, whatever
      }
    }
    

    If you want to pass in additional constants to the CAction from the Controller, you can do it like this:

    In your action setup in your Controller:

    public function actions() {
      return array(
        'userSearch'=>array(
          'class'=>'application.controllers.User.ListAction', // path alias to your action
          'model'=>'User',
          'otherVariable'=>'something here',
      ));
    }
    

    Then in your CAction:

    class ListAction extends CAction {
      public $modelName;
      public $otherVariable;
      public function run() {
        $this->modelName; //  'User' - passed in from the calling Controller
        $this->otherVariable; //  'something here' - passed in from the calling Controller
      }
    }
    

    I’m not sure what other parameters you might want to pass in to your action, but that should cover it. I hope that helps!

    Update:

    This question has made me look at the code in more depth, and this is actually all to do with a feature of Yii which I did not know about. If you declare a parameter on your action (i.e. function actionTest($param)), then Yii will parse the $_GET parameters of a request and call the Action with that parameter passed in to the function. So you don’t have to get the $_GET parameter yourself. Like so:

    http://example.com/mycontroller/myaction?param1=test
    
    function actionMyaction($param1) { // in a CAction, it would be run($param1)
      echo '$_GET parameter param1 set to '.$param1; // will echo "test"
    }
    

    The way this is implemented is:

    1. In runAction() CController gets the $_GET parameters (if there are any) with getActionParams()
    2. runAction() passes these parameters into runWithParams()
    3. runWithParams() uses PHP Reflection to see if the action method has parameters (e.g. $param1)
      1. If there are parameters, it calls runWithParamsInternal() with the $_GET parameters
        1. runWithParamsInternal() calls the run() method with the $_GET parameters (e.g. run($param1))
      2. Otherwise it just calls run() without any parameters

    It’s totally optional to use this, you can still access the $_GET parameters like normal in your action without. Basically, this just enforces required $_GET parameters. If your action needs a parameter but there are not $_GET parameters in the request URL, Yii returns an “Error 400” from invalidActionParams(). It saves you the burden of checking isset($_GET) in your action, which is kind of cool.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at this example here: http://denise.brixwork.com/showlisting/1/8297-Valley-Drive-Alpine-Meadows-Whistler-denise-brown-real-estate And the red tables under Specifications
look at this fiddle: http://jsfiddle.net/ugxNK/ I want that the first list element is in
Please take a look at this link . Hover cursor on any movie thumbnail.
I'm trying to get this link to look like this: Comment on this show
Please take a look at my fiddle : The .pos_absolute div is under the
look here: http://jsfiddle.net/QTrat/10/ I want to stretch the red box to the floated children
Look at this: $('form).submit(function (event) { $(':input.required').trigger('blur'); var num = $('.warning', this).length; alert(num);//Focus here!
I have this HTML: <div class=info> Some Text Boom A <a onclick=menu('id1');>Link</a> | More
I have a yii website under a sub directory e.g http://localhost/~username/maindirectory/yiiapp/ My htaccess file:
I'm trying to look under the hood about java compilation. So I put my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.