can we remove default layout of view in yii 1.1 - php

I am new in yii, and trying to import a existing PHP site into this framework, so i want to remove default layout style of yii, just wanna show my view page.
Is there any way to do so?
like, when i load a view
$this->render('myview');
then only myview.php should be render.
I didn't found any help anywhere.

Just put $this->layout = false; in your action or a property public $layout = false; in your controller if you want it disabled controller wide.

Use the renderPartial function.
$this->renderPartial('myview', array('model'=>$model));
You can do other things, like assign the markup to a variable and do things like echo, manipulate and save it.
The renderPartial will not load the page layout.

// for disabled in whole controller actions use following method in controller
Class siteController extend controller {
Public $layout = false;
}
// disable for particular action in controller
Class siteController extend controller {
Public actionIndex (){
$this->layout = false.
}
}

Related

Phalcon PhP - how to change the view dynamically

I'm working in a website where part of it I have the static html, so I created a layout and in it I'm inserting the static content using views. My problem is as this website has many pages I feel wrong creating an action for each url. So I implemented the controller below:
class PageController extends ControllerBase
{
public function initialize(){
$this->init();
$this->view->setLayout( 'website' );
}
public function indexAction ($url=''){
if($url == 'about')
$this->view->pick('page/about');
}
}
When I set the controller view to render $this->view->pick('page/about'); it doesn't insert the view in the template. It renders only the view.
Is there a way to render the view within the layout, and is there a better approach to what I'm doing?
Thanks for any help
To load a template you should use
$this->view->setTemplateAfter('website');
instead of $this->view->setLayout( 'website' );
By using $this->view->pick('page/about'); you are overwriting the layout set by $this->view->setLayout( 'website' );, resulting in only seeing the page/about layout.

In Yii2, how can I exclude layout from rendering in a view file?

I have an admin login page that I want to render without the layout. How can I render a view in Yii2 without rendering the main layout?
This can be done using renderPartial() method.
You can get more from the official documentation. Here's a link!
In your controller you can assing layout for all actions of controller or turn it off:
class AdminController extends Controller
{
// public $layout='//admin';
public $layout=false;
OR you can do it for only one action:
public function actionIndex()
{
$this->layout = false;
You can use renderPartial to exclude header and footer of layout from view file. However if you renderPartial it will not load asset files (css and js files). To load asset files without layout you can use renderAjax.

Autoload function and get variables in codeIgniter

I have this question: how to load function in codeIgniter in every page and get data or variables from it to show in view?
I have many controllers and each one has many function. Each function load master view as a template and load its own view. Master view has dynamic data I push it from database.
So I need in master view to show some data from database automatically. How to do it?
You can use this. change it according to your
function index()
{
$data['list'] = $this->some_model->show_data();
$data1['content'] = $this->load->view('some_view',$data,true);
$this->load->view('template',$data1);
}
content is in your main template where u will pass your data to show in template
I am not sure what exactly you ask but if you want a function to be loaded automatically to any controller
then create a Mycontroller.php in application/core
class Mycontroller extends CI_Controller
{
function __construct()
{
parent::__construct();
// here goes your function
}
}
and then extend every controller you have to Mycontroller instead of CI_Controller
if you want to use your function inside views. use CI Helpers
Codeigniter Helpers
create your helper function
function get_data() {
// and use CI instance
$CI = & get_instance();
// now you can call your models, libraries. etc. in the helper
$data = $CI->your_model->your_model_funcion();
return $data;
}
and you can call your helper function in controllers, views, models. etc...
get_data();

Accessing a controller action through out the application in Zend

I'm little bit new to Zend, I want to use a controller action through out the entire application automatically, I don't have a clear idea to how to use it, thought about init() method, action helpers, etc.
Then instead of simply creating controller action create controllerAction Helper . Here you can find more about it
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
My_Helper_Magic extends Zend_Controller_Action_Helper_Abstract
{
public function preDispach()
{
//code inside here will run for entire application automatically
}
}
In your bootstrap do
Zend_Controller_Action_HelperBroker::addHelper(new My_Helper_Magic());
In Response to comment .
It depends upon your 'code fragment' , If your code fragment does not required to know nothing about module , controller, action , base url then you can use Bootstrap init function
like
public function _initAlways()
{
//see how this function name is prefixed with _init hence it will be called by ZF //everytime. You can put your code fragment here
//If your code fragment depends upon some stuff like baseurl then do action controller
// registration here instead
Zend_Controller_Action_HelperBroker::addHelper(new My_Helper_Magic());
}
In Response To comment
You can save any instance of your object inside Zend_Registy and retrieve it whereever you like
Inside Bootstrap.php
public function _initSetup()
{
$object = new My_Custom_Object();
Zend_Registry::set('my_custom_object',$object);
}
Later in your view or controller do
$myObject = Zend_Registry::get('my_custom_object'); //to access it

Zend Framework loading views without re-loading the layout template

I need to load a profile layout and then have all of the profile views load into that layout without re-loading the layout, so that I can cache a big json object in the clients browser, to allow for data to be available on subsequent views, without having to do a new HTTP request for every view in my profile controller.
Is it possible to load the layout template and then load views into it, by disabling their layout template, so that the layout template never re-loads, only the view within?
Another option would be to have an iframe inside of a layout and then load the views into the iframe, by disabling their layouts, so that just the view is rendered.
Just need to know if this is possible and what the best option would be.
Thanks in advance :)
In the views where you do not want a layout try:
$this->_helper->layout->disableLayout();
This should prevent the layout from being shown.
If, for some reason, you want the same action from the same controller called many times but load the layout once (must be a better way to organise yourself) but you could always try:
public function indexAction()
{
static $firstTime = true;
if($firstTime){
$firstTime = false;
} else {
$this->_helper->layout->disableLayout(); //disable layout
}
}
I'll try to give a better example:
Lets say you have a controller foo with 3 views: index, contact, news.
class Foo_Controller extends Zend_Controller
{
//...
public function indexAction()
{
//normal view layout loads
}
public function contactAction()
{
//normal view layout loads
}
public function newsAction()
{
//no layout for this
$this->_helper->layout->disableLayout(); //disable layout
}
}
So the views that need a layout have one. The ones that do not do not. Unless you are saying layout but really thinking of something else then Zend_View_Helpers_Layout you will have t post some code to help us help you!

Categories