layout en modulos...

buenas noches, estoy creando un modulo en mi app (modules/admin) Todo correcto hasta aca. Estoy practicando con el blog.

Bien el problema que tengo es que no puedo hacer que me muestre el layout "column2" que trae los links para hacer el crud.

Estuve leyendo algnos hilos respecto a esto, pero ninguno me soluciona el problema.

Lo que tengo hasta ahora es lo siguiente:

  1. copie los column1, column2, main.php en modules/admin/views/layouts

  2. En mi admin/componets/Controller.php ya logre hacer la llamada al layout main.php


  public function init()

        {

            

            $this->layout = 'main';  

            parent::init();

        }

En mi post controller llamo al column2 de esta manera




<?php


class PostController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

public $layout='column2';

............



y mis comlumn1 y column2 quite el parametro "//layouts/column2" y "//layouts/column1" respectivamente al metodo <?php $this->beginContent(); ?>

Bien pues no me funciona >:( Cualquier sugerencia o guia es bienvenida, por cierto uso la version 1.1.6 (Jan 16, 2011)

Saludines :D

in the init method of your controller you are replacing the PostController layout (column2)


$this->layout = 'main'; 

do the following to fix it:




class Controller extends CController{

   public $layout='main';

   function init(){

 	return parent::init();

   }

}



and in PostController stays the same




class PostController extends Controller

{

public $layout='column2';

//...

}



Hello Gustavo :D

Lo que me recomiendas no funciona. :’(

Ahora lo tengo asi;




<?php

/**

 * Controller is the customized base controller class.

 * All controller classes for this application should extend from this base class.

 */

class Controller extends CController

{

	/**

	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',

	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.

	 */

public $layout= 'column1';

	/**

	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.

	 */

	public $menu=array();

	/**

	 * @var array the breadcrumbs of the current page. The value of this property will

	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}

	 * for more details on how to specify this property.

	 */

	public $breadcrumbs=array();

	  

   function init(){

   $this->layout= 'main';

        return parent::init();

   }

   

}



Carga el main, pero no column1 … y mi PostController tampoco carga el column2 :huh:




<?php


class PostController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='column2';


..................




alguna otra sugerencia?

Regards. ;)

remove in the init function




   function init(){

       //$this->layout= 'main'; ---  remove this line

        return parent::init();

   }




El tema es que cuando vos ejecutas en el init, sobreescribis el método por defautl.

Poné lo siguiente método init en el controlador del módulo:




	public function init(){

		parent::init();

		$this->layout = 'column2';

	}



Saludos,

Al fin pude resolverlo :P

primero tenia un error de conceptos, pero ya logre entender. Al final quedo asi:

column2.php:




<?php $this->beginContent('/layouts/main'); ?>

<div class="container">

	<div class="span-19">

		<div id="content">

			<?php echo $content; ?>

		</div><!-- content -->

	</div>

	<div class="span-5 last">

		<div id="sidebar">

		<?php

			$this->beginWidget('zii.widgets.CPortlet', array(

				'title'=>'Operations',

			));

			$this->widget('zii.widgets.CMenu', array(

				'items'=>$this->menu,

				'htmlOptions'=>array('class'=>'operations'),

			));

			$this->endWidget();

		?>

		</div><!-- sidebar -->

	</div>

</div>

admin/layout/column2

<?php $this->endContent(); ?>



Controller.php (el supercontroller del modulo):


<?php

/**

 * Controller is the customized base controller class.

 * All controller classes for this application should extend from this base class.

 */

class Controller extends CController

{

	/**

	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',

	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.

	 */


	/**

	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.

	 */

	public $menu=array();

	/**

	 * @var array the breadcrumbs of the current page. The value of this property will

	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}

	 * for more details on how to specify this property.

	 */

	public $breadcrumbs=array();

	  

   function init(){

  $this->layout= 'main';

    

  

       

   }

   

}

Y mi controlador:

PostController:




<?php


class PostController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */




function init(){

  

 $this->layout= 'column2';

       

   }

............   



Es raro por que segun la documentación y un ejemplo del libro el metodo <?php $this->beginContent(’/layouts/main’); ?> no debe tener ningun parametro, pero si lo dejo vacio, me llama al main principal y no del modulo. :blink: :huh:

en fin un problema menos.

Saludos y gracias a ambos por su colaboración :D

Gracias por ese aporte también me pasaba lo mismso.

A mi me funcionó de la sgte. manera:

Dentro del controlador (admin/components/Controller.php)

Esto aplica a todos los controladores del módulo que heredan de Controller


class Controller extends CController

{

	public $layout='/layouts/column1';


	public $menu=array();


	public $breadcrumbs=array();

}

Y en column1.php (admin/views/layouts/column1.php)


<?php $this->beginContent('/layouts/main'); ?> 

<!-- contenito html -->

<?php $this->endContent(); ?>

Extra

Y si sólo quieres aplicar el layout a ún solo controlador del módulo pues ya no necesitas copiar Controller.php y dentro del controlador defines esto:


public function init(){

        $this->layout = '/layouts/column1';

    }

P.D: No olvidar de copiar main.php, column1.php, column2.php de la carpeta layout principal a la del módulo.