David
David

Reputation: 165

Creating a new YII Default page and redirect to it

I am new to YII framework and I am trying to make an application that works like following, when I visit my index it redirects me to this a page called management, I have to create a new page with some list options and I have to redirect to that, but I am not quite sure how to do it with YII.

here is my original action Index:

public function actionIndex()
{
    $this->layout = '//layouts/main';
    // renders the view file 'protected/views/site/index.php'
    // using the default layout 'protected/views/layouts/main.php'
    if (Yii::app()->user->isGuest)
    {
        $this->redirect(Yii::app()->createUrl('site/login'));
    }
    else
    {
        $this->redirect(array('management/list'));
        //$this->redirect(array('site/HomePage'));
        //$this->render('index');
    }
}

it redirects me to management/list, what I have to do is to redirect to a new page instead of management called home page and in the new page there is an option for management which by clicking on that it takes you to the correct page.

this is my management folder:

enter image description here

this is my view:

enter image description here

what I did is: inside site I created a page called homepage.php with the following body:

<div class="static_page">
<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

    <h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>

<p>Congratulations! You have successfully created your Yii application.</p>

<p>You may change the content of this page by modifying the following two files:</p>
<ul>
    <li>View file: <code><?php echo __FILE__; ?></code></li>
    <li>Layout file: <code><?php echo $this->getLayoutFile('main'); ?></code></li>
</ul>

<p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p>

</div>

then I changed my actionIndex(), and added the following to the else part:

$this->redirect(array('site/HomePage'));

but when I run that I saw this errors:

The system is unable to find the requested action "HomePage".

/vagrant/vendor/yiisoft/yii/framework/web/CController.php(483)

471         return $this->createActionFromMap($map,$actionID,$requestActionID,$config);
472     }
473 
474     /**
475      * Handles the request whose action is not recognized.
476      * This method is invoked when the controller cannot find the requested action.
477      * The default implementation simply throws an exception.
478      * @param string $actionID the missing action name
479      * @throws CHttpException whenever this method is invoked
480      */
481     public function missingAction($actionID)
482     {
483         throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{action}".',
484             array('{action}'=>$actionID==''?$this->defaultAction:$actionID)));
485     }
486 
487     /**
488      * @return CAction the action currently being executed, null if no active action.
489      */
490     public function getAction()
491     {
492         return $this->_action;
493     }
494 
495     /**


 // specify how many levels of call stack should be shown in each log message
15 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
16 
17 require_once($yii);
18 
19 Yii::createWebApplication($config)->run();
20 
21 echo 'temporary add records to the rbac tables';
22 
23 //TODO create temporarily the RBAC settings
24 $auth=Yii::app()->authManager;

how can I add the new homepage.php instead of management page??

EDITED NEW VERSION: So this is how I made it: I created a new page called homepage.php withing my views\site. then I open the homepage and added the following:

<div class="static_page">
<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

    <h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>

<p>You may change the page by clicking on the following pages.</p>
<ul>
    <li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
    <li>For Management Information click on: <code> Management Info</code></li>
    <li>For System Management click on: <code> systemBeheer</code></li>
</ul>

<!-- <p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p> -->

</div>

and also changed my actionIndex to $this->render('HomePage');

it works but now my redirection doesnt work:

for example this part is totally incorrect

<li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
        <li>For Management Information click on: <code> Management Info</code></li>

how can I solve this one?

Upvotes: 1

Views: 769

Answers (2)

Tristup
Tristup

Reputation: 3663

Please write this code in place of " $this->redirect(array('management/list'));"

$list=array('David','Tristup');
$selected_value=''; 
$this->render('yourview/index',
               array('list_arr'=>$list,'selected_value'=>$selected_value 
		));

Now you write this code in yourview/index.php. Here make_id is field name change it accordingly.

 <?php       
                                  //echo $selected_value;
                                  echo CHtml::dropDownList('make_id',$selected_value,$list_arr,array('empty' => 'Select a Make','class'=>'drop_class'));            
                            ?>

Now you can see a dropdown with our name. Please let me know if you have any questions.

Upvotes: 0

Tristup
Tristup

Reputation: 3663

Instead of redirecting to anywhere else please load a view

$this->render('yourview/index',array(
			'dataProvider'=>$dataProvider,
                        'list_arr'=>$this->list
		));

Make a folder named yourview inside the view folder. Even if you want to redirect it to management controller, please make sure that you have the controller in name.

Upvotes: 1

Related Questions