Yii Framework Forum: layout en modulos... - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

layout en modulos... Rate Topic: -----

#1 User is offline   nucklear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 20-September 10
  • Location:Cordoba - Argentina

Posted 30 January 2011 - 06:46 PM

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
0

#2 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 915
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 30 January 2011 - 07:10 PM

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';
//...
}

--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#3 User is offline   nucklear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 20-September 10
  • Location:Cordoba - Argentina

Posted 30 January 2011 - 09:29 PM

View PostGustavo, on 30 January 2011 - 07:10 PM, said:

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. ;)
0

#4 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 915
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 30 January 2011 - 09:52 PM

remove in the init function
   function init(){
       //$this->layout= 'main'; ---  remove this line
        return parent::init();
   }


--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#5 User is offline   sebas 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 492
  • Joined: 28-October 08
  • Location:Buenos Aires, Argentina

Posted 30 January 2011 - 10:05 PM

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,
0

#6 User is offline   nucklear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 20-September 10
  • Location:Cordoba - Argentina

Posted 31 January 2011 - 12:42 PM

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
0

#7 User is offline   Gustalh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-December 11
  • Location:Colombia

Posted 13 April 2012 - 03:37 PM

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

#8 User is offline   butcher202 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 20-June 12

Posted 20 June 2012 - 11:09 PM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users